]> www.infradead.org Git - users/jedix/linux-maple.git/commit
cachefiles: defer exposing anon_fd until after copy_to_user() succeeds
authorBaokun Li <libaokun1@huawei.com>
Wed, 22 May 2024 11:43:05 +0000 (19:43 +0800)
committerChristian Brauner <brauner@kernel.org>
Wed, 29 May 2024 11:03:30 +0000 (13:03 +0200)
commit4b4391e77a6bf24cba2ef1590e113d9b73b11039
tree775e7253b866862a1bc0efbc69c8add6106414e3
parent4988e35e95fc938bdde0e15880fe72042fc86acf
cachefiles: defer exposing anon_fd until after copy_to_user() succeeds

After installing the anonymous fd, we can now see it in userland and close
it. However, at this point we may not have gotten the reference count of
the cache, but we will put it during colse fd, so this may cause a cache
UAF.

So grab the cache reference count before fd_install(). In addition, by
kernel convention, fd is taken over by the user land after fd_install(),
and the kernel should not call close_fd() after that, i.e., it should call
fd_install() after everything is ready, thus fd_install() is called after
copy_to_user() succeeds.

Fixes: c8383054506c ("cachefiles: notify the user daemon when looking up cookie")
Suggested-by: Hou Tao <houtao1@huawei.com>
Signed-off-by: Baokun Li <libaokun1@huawei.com>
Link: https://lore.kernel.org/r/20240522114308.2402121-10-libaokun@huaweicloud.com
Acked-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/cachefiles/ondemand.c