Skip to content

Commit 418ffb9

Browse files
asjkdave
authored andcommitted
btrfs: free btrfs_path before copying inodes to userspace
btrfs_ioctl_logical_to_ino() frees the search path after the userspace copy from the temp buffer @inodes. Which potentially can lead to a lock splat. Fix this by freeing the path before we copy @inodes to userspace. CC: stable@vger.kernel.org # 4.19+ Signed-off-by: Anand Jain <anand.jain@oracle.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent b740d80 commit 418ffb9

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

fs/btrfs/ioctl.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4282,21 +4282,20 @@ static long btrfs_ioctl_logical_to_ino(struct btrfs_fs_info *fs_info,
42824282
size = min_t(u32, loi->size, SZ_16M);
42834283
}
42844284

4285-
path = btrfs_alloc_path();
4286-
if (!path) {
4287-
ret = -ENOMEM;
4288-
goto out;
4289-
}
4290-
42914285
inodes = init_data_container(size);
42924286
if (IS_ERR(inodes)) {
42934287
ret = PTR_ERR(inodes);
4294-
inodes = NULL;
4295-
goto out;
4288+
goto out_loi;
42964289
}
42974290

4291+
path = btrfs_alloc_path();
4292+
if (!path) {
4293+
ret = -ENOMEM;
4294+
goto out;
4295+
}
42984296
ret = iterate_inodes_from_logical(loi->logical, fs_info, path,
42994297
inodes, ignore_offset);
4298+
btrfs_free_path(path);
43004299
if (ret == -EINVAL)
43014300
ret = -ENOENT;
43024301
if (ret < 0)
@@ -4308,7 +4307,6 @@ static long btrfs_ioctl_logical_to_ino(struct btrfs_fs_info *fs_info,
43084307
ret = -EFAULT;
43094308

43104309
out:
4311-
btrfs_free_path(path);
43124310
kvfree(inodes);
43134311
out_loi:
43144312
kfree(loi);

0 commit comments

Comments
 (0)