sst-linux/fs/cachefiles
Zizhi Wo d6bba3ece9 cachefiles: Fix NULL pointer dereference in object->file
commit 31ad74b20227ce6b40910ff78b1c604e42975cf1 upstream.

At present, the object->file has the NULL pointer dereference problem in
ondemand-mode. The root cause is that the allocated fd and object->file
lifetime are inconsistent, and the user-space invocation to anon_fd uses
object->file. Following is the process that triggers the issue:

	  [write fd]				[umount]
cachefiles_ondemand_fd_write_iter
				       fscache_cookie_state_machine
					 cachefiles_withdraw_cookie
  if (!file) return -ENOBUFS
					   cachefiles_clean_up_object
					     cachefiles_unmark_inode_in_use
					     fput(object->file)
					     object->file = NULL
  // file NULL pointer dereference!
  __cachefiles_write(..., file, ...)

Fix this issue by add an additional reference count to the object->file
before write/llseek, and decrement after it finished.

Fixes: c838305450 ("cachefiles: notify the user daemon when looking up cookie")
Signed-off-by: Zizhi Wo <wozizhi@huawei.com>
Link: https://lore.kernel.org/r/20241107110649.3980193-5-wozizhi@huawei.com
Reviewed-by: David Howells <dhowells@redhat.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Bin Lan <lanbincn@qq.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-02-21 13:49:54 +01:00
..
cache.c cachefiles: fix slab-use-after-free in cachefiles_withdraw_cookie() 2024-07-25 09:49:21 +02:00
daemon.c cachefiles: Parse the "secctx" immediately 2025-01-23 17:17:12 +01:00
error_inject.c
interface.c cachefiles: Fix NULL pointer dereference in object->file 2025-02-21 13:49:54 +01:00
internal.h cachefiles: Parse the "secctx" immediately 2025-01-23 17:17:12 +01:00
io.c
Kconfig
key.c
main.c
Makefile
namei.c cachefiles: fix dentry leak in cachefiles_open_file() 2024-10-17 15:22:01 +02:00
ondemand.c cachefiles: Fix NULL pointer dereference in object->file 2025-02-21 13:49:54 +01:00
security.c cachefiles: Parse the "secctx" immediately 2025-01-23 17:17:12 +01:00
volume.c cachefiles: fix slab-use-after-free in cachefiles_withdraw_cookie() 2024-07-25 09:49:21 +02:00
xattr.c cachefiles: propagate errors from vfs_getxattr() to avoid infinite loop 2024-07-18 13:18:31 +02:00