mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-05 19:31:57 -04:00
UPSTREAM: fuse: fix readdir cache race
[ Upstream commit 9fa248c65bdbf5af0a2f74dd38575acfc8dfd2bf ]
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: 5d7bc7e868 ("fuse: allow using readdir cache")
Cc: <stable@vger.kernel.org> # v4.20
Change-Id: I1dea0531dd4d2cb0b89b8e1ee6796339fc2dc624
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
9769804365
commit
ac8fa186fc
1 changed files with 9 additions and 1 deletions
|
|
@ -79,8 +79,10 @@ static void fuse_add_dirent_to_cache(struct file *file,
|
|||
goto unlock;
|
||||
|
||||
addr = kmap_atomic(page);
|
||||
if (!offset)
|
||||
if (!offset) {
|
||||
clear_page(addr);
|
||||
SetPageUptodate(page);
|
||||
}
|
||||
memcpy(addr + offset, dirent, reclen);
|
||||
kunmap_atomic(addr);
|
||||
fi->rdc.size = (index << PAGE_SHIFT) + offset + reclen;
|
||||
|
|
@ -526,6 +528,12 @@ retry_locked:
|
|||
|
||||
page = find_get_page_flags(file->f_mapping, index,
|
||||
FGP_ACCESSED | FGP_LOCK);
|
||||
/* Page gone missing, then re-added to cache, but not initialized? */
|
||||
if (page && !PageUptodate(page)) {
|
||||
unlock_page(page);
|
||||
put_page(page);
|
||||
page = NULL;
|
||||
}
|
||||
spin_lock(&fi->rdc.lock);
|
||||
if (!page) {
|
||||
/*
|
||||
|
|
|
|||
Loading…
Reference in a new issue