acrn-kernel/fs/afs
David Howells 9b4c95a63e afs: Fix use-after-free due to get/remove race in volume tree
[ Upstream commit 9a6b294ab496650e9f270123730df37030911b55 ]

When an afs_volume struct is put, its refcount is reduced to 0 before
the cell->volume_lock is taken and the volume removed from the
cell->volumes tree.

Unfortunately, this means that the lookup code can race and see a volume
with a zero ref in the tree, resulting in a use-after-free:

    refcount_t: addition on 0; use-after-free.
    WARNING: CPU: 3 PID: 130782 at lib/refcount.c:25 refcount_warn_saturate+0x7a/0xda
    ...
    RIP: 0010:refcount_warn_saturate+0x7a/0xda
    ...
    Call Trace:
     afs_get_volume+0x3d/0x55
     afs_create_volume+0x126/0x1de
     afs_validate_fc+0xfe/0x130
     afs_get_tree+0x20/0x2e5
     vfs_get_tree+0x1d/0xc9
     do_new_mount+0x13b/0x22e
     do_mount+0x5d/0x8a
     __do_sys_mount+0x100/0x12a
     do_syscall_64+0x3a/0x94
     entry_SYSCALL_64_after_hwframe+0x62/0x6a

Fix this by:

 (1) When putting, use a flag to indicate if the volume has been removed
     from the tree and skip the rb_erase if it has.

 (2) When looking up, use a conditional ref increment and if it fails
     because the refcount is 0, replace the node in the tree and set the
     removal flag.

Fixes: 20325960f8 ("afs: Reorganise volume and server trees to be rooted on the cell")
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Jeffrey Altman <jaltman@auristor.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: linux-afs@lists.infradead.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-01-01 12:38:58 +00:00
..
Kconfig
Makefile
addr_list.c
afs.h
afs_cm.h
afs_fs.h
afs_vl.h
callback.c
cell.c afs: Fix overwriting of result of DNS query 2024-01-01 12:38:58 +00:00
cmservice.c
dir.c
dir_edit.c
dir_silly.c
dynroot.c afs: Fix dynamic root lookup DNS check 2024-01-01 12:38:57 +00:00
file.c
flock.c
fs_operation.c
fs_probe.c
fsclient.c
inode.c
internal.h afs: Fix use-after-free due to get/remove race in volume tree 2024-01-01 12:38:58 +00:00
main.c
misc.c
mntpt.c
proc.c
protocol_afs.h
protocol_uae.h
protocol_yfs.h
rotate.c
rxrpc.c afs: Fix refcount underflow from error handling race 2023-12-20 17:00:15 +01:00
security.c
server.c
server_list.c
super.c afs: Fix file locking on R/O volumes to operate in local mode 2023-12-03 07:32:08 +01:00
vl_alias.c
vl_list.c
vl_probe.c
vl_rotate.c afs: Return ENOENT if no cell DNS record can be found 2023-12-03 07:32:08 +01:00
vlclient.c
volume.c afs: Fix use-after-free due to get/remove race in volume tree 2024-01-01 12:38:58 +00:00
write.c
xattr.c
xdr_fs.h
yfsclient.c