]> git.hungrycats.org Git - linux/commit
btrfs: zoned: fix possible UAF in wait_eb_writebacks
authorJohannes Thumshirn <johannes.thumshirn@wdc.com>
Wed, 9 Sep 2026 09:45:34 +0000 (11:45 +0200)
committerJohannes Thumshirn <johannes.thumshirn@wdc.com>
Wed, 21 Oct 2026 08:03:34 +0000 (10:03 +0200)
commitbe3b6cfc3b511d3717d4f691915003829092e54f
treeea3920d5d9ae40df88cd5f2e65707de3315e4d4e
parent0be761ecf1a9cb32ce3bfd9e0469a331b9920483
btrfs: zoned: fix possible UAF in wait_eb_writebacks

wait_eb_writebacks() iterates the fs_info->buffer_tree xarray and waits
for the writeback of these extent-buffers. Waiting for writeback needs
to be done without the rcu_read_lock() held (because it can sleep) and
thus the loop drops the rcu_read_lock() before calling into
wait_on_extent_buffer_writeback(). But extent_buffers are freed through
RCU, so if btrfs_release_extent_buffer_rcu() is scheduled while we're
still waiting on the writeback, the extent_buffer will be freed causing
a use-after-free.

Similar to what is done in find_extent_buffer_nolock(), get a reference
to the extent_buffer before calling into
wait_on_extent_buffer_writeback() so a sucessfull writeback does not
free the extent_buffer while we still have a reference to it.

Reviewed-by: Daniel Vacek <neelx@suse.com>
Fixes: 2dd7e7bc0282 ("btrfs: zoned: wait for extent buffer IOs before finishing a zone")
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
fs/btrfs/zoned.c