Skip to content

Commit 59f3703

Browse files
fdmananakdave
authored andcommitted
btrfs: fix use-after-free on inode when scanning root during em shrinking
At btrfs_scan_root() we are accessing the inode's root (and fs_info) in a call to btrfs_fs_closing() after we have scheduled the inode for a delayed iput, and that can result in a use-after-free on the inode in case the cleaner kthread does the iput before we dereference the inode in the call to btrfs_fs_closing(). Fix this by using the fs_info stored already in a local variable instead of doing inode->root->fs_info. Fixes: 1020443 ("btrfs: make the extent map shrinker run asynchronously as a work queue job") CC: [email protected] # 6.13+ Tested-by: Ivan Shapovalov <[email protected]> Link: https://lore.kernel.org/linux-btrfs/[email protected]/ Reviewed-by: Johannes Thumshirn <[email protected]> Reviewed-by: Qu Wenruo <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 290237f commit 59f3703

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

fs/btrfs/extent_map.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,8 +1222,7 @@ static long btrfs_scan_root(struct btrfs_root *root, struct btrfs_em_shrink_ctx
12221222
fs_info->em_shrinker_last_ino = btrfs_ino(inode);
12231223
btrfs_add_delayed_iput(inode);
12241224

1225-
if (ctx->scanned >= ctx->nr_to_scan ||
1226-
btrfs_fs_closing(inode->root->fs_info))
1225+
if (ctx->scanned >= ctx->nr_to_scan || btrfs_fs_closing(fs_info))
12271226
break;
12281227

12291228
cond_resched();

0 commit comments

Comments
 (0)