]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
cachefiles: Fix NULL pointer dereference in object->file
authorZizhi Wo <wozizhi@huawei.com>
Thu, 7 Nov 2024 11:06:48 +0000 (19:06 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 21 Feb 2025 12:49:54 +0000 (13:49 +0100)
commitd6bba3ece960129a553d4b16f1b00c884dc0993a
treefb34cfbdc496aa56d8e43e76c4d810501ea424c3
parent918cf2616af595d028b4ac0dfa3d55fb7c107436
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: c8383054506c ("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>
fs/cachefiles/interface.c
fs/cachefiles/ondemand.c