fs/btrfs: On error always free subvol_name in btrfs_mount
Subsystems (2)
PATCH 1/1 fs/btrfs: On error always free subvol_name in btrfs_mount
The subvol_name is allocated in btrfs_parse_subvol_options and is consumed and freed in mount_subvol. Add a free to the error paths that don't call mount_subvol so that it is guaranteed that subvol_name is freed when an error happens.
--- fs/btrfs/super.c | 3 +++ 1 file changed, 3 insertions(+)
fs/btrfs/super.c +3 -0
@@ -1621,6 +1621,7 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, flags | SB_RDONLY, device_name, data);if (IS_ERR (mnt_root)) { root =ERR_CAST (mnt_root); +kfree (subvol_name); goto out; }
@@ -1630,12 +1631,14 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,if (error <0 ) { root =ERR_PTR (error);mntput (mnt_root); +kfree (subvol_name); goto out; } } }if (IS_ERR (mnt_root)) { root =ERR_CAST (mnt_root); +kfree (subvol_name); goto out; }
Signature · 1 line
2.17.1
Quoted 5 lines · Eric W. Biederman
The
subvol_nameis allocated inbtrfs_parse_subvol_optionsand is consumed and freed inmount_subvol. Add a free to the error paths that don't callmount_subvolso that it is guaranteed thatsubvol_nameis freed when an error happens.
Good catch,
Quoted 40 lines
Fixes 312c89fbca06 ("btrfs: cleanup btrfs_mount() using btrfs_mount_root()")Cc Chris Mason <[email protected]>Cc Josef Bacik <[email protected]>Cc David Sterba <[email protected]>Signed-off-by "Eric W. Biederman" <[email protected]>--- fs/btrfs/super.c | 3 +++ 1 file changed, 3 insertions(+)fs/btrfs/super.c +3
-0@@ -1621,6 +1621,7 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, flags | SB_RDONLY, device_name, data);if (IS_ERR (mnt_root)) { root =ERR_CAST (mnt_root); +kfree (subvol_name); goto out; }@@ -1630,12 +1631,14 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,if (error <0 ) { root =ERR_PTR (error);mntput (mnt_root); +kfree (subvol_name); goto out; } } }if (IS_ERR (mnt_root)) { root =ERR_CAST (mnt_root); +kfree (subvol_name); goto out; }
Quoted 6 lines · Eric W. Biederman
The
subvol_nameis allocated inbtrfs_parse_subvol_optionsand is consumed and freed inmount_subvol. Add a free to the error paths that don't callmount_subvolso that it is guaranteed thatsubvol_nameis freed when an error happens.
Quoted 7 lines
Fixes 312c89fbca06 ("btrfs: cleanup btrfs_mount() using btrfs_mount_root()")Cc Chris Mason <[email protected]>Cc Josef Bacik <[email protected]>Cc David Sterba <[email protected]>Signed-off-by "Eric W. Biederman" <[email protected]>
Added to 5.0-rc queue, thanks.