OSDN Git Service

fuse: fix readdir cache race
authorMiklos Szeredi <mszeredi@redhat.com>
Thu, 20 Oct 2022 15:18:58 +0000 (17:18 +0200)
committerMiklos Szeredi <mszeredi@redhat.com>
Thu, 20 Oct 2022 15:18:58 +0000 (17:18 +0200)
commit9fa248c65bdbf5af0a2f74dd38575acfc8dfd2bf
tree4fc373a67c8d59509c4db530a86da7c0252f1267
parent9abf2313adc1ca1b6180c508c25f22f9395cc780
fuse: fix readdir cache race

There's a race in fuse's readdir cache that can result in an uninitilized
page being read.  The page lock is supposed to prevent this from happening
but in the following case it doesn't:

Two fuse_add_dirent_to_cache() start out and get the same parameters
(size=0,offset=0).  One of them wins the race to create and lock the page,
after which it fills in data, sets rdc.size and unlocks the page.

In the meantime the page gets evicted from the cache before the other
instance gets to run.  That one also creates the page, but finds the
size to be mismatched, bails out and leaves the uninitialized page in the
cache.

Fix by marking a filled page uptodate and ignoring non-uptodate pages.

Reported-by: Frank Sorenson <fsorenso@redhat.com>
Fixes: 5d7bc7e8680c ("fuse: allow using readdir cache")
Cc: <stable@vger.kernel.org> # v4.20
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/fuse/readdir.c