Skip to content

Commit 07836bc

Browse files
Sasha Levingregkh
authored andcommitted
btrfs: fix use-after-free on inode when scanning root during em shrinking
[ Upstream commit 59f3703 ] 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: stable@vger.kernel.org # 6.13+ Tested-by: Ivan Shapovalov <intelfx@intelfx.name> Link: https://lore.kernel.org/linux-btrfs/0414d690ac5680d0d77dfc930606cdc36e42e12f.camel@intelfx.name/ Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 5f4863c commit 07836bc

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

fs/btrfs/extent_map.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,7 @@ static struct btrfs_inode *find_first_inode_to_shrink(struct btrfs_root *root,
12501250

12511251
static long btrfs_scan_root(struct btrfs_root *root, struct btrfs_em_shrink_ctx *ctx)
12521252
{
1253+
struct btrfs_fs_info *fs_info = root->fs_info;
12531254
struct btrfs_inode *inode;
12541255
long nr_dropped = 0;
12551256
u64 min_ino = ctx->last_ino + 1;
@@ -1264,7 +1265,7 @@ static long btrfs_scan_root(struct btrfs_root *root, struct btrfs_em_shrink_ctx
12641265
iput(&inode->vfs_inode);
12651266

12661267
if (ctx->scanned >= ctx->nr_to_scan ||
1267-
btrfs_fs_closing(inode->root->fs_info))
1268+
btrfs_fs_closing(fs_info))
12681269
break;
12691270

12701271
cond_resched();

0 commit comments

Comments
 (0)