Commit 0040e606 authored by Christoph Jaeger's avatar Christoph Jaeger Committed by Chris Mason

btrfs: fix use-after-free in mount_subvol()

Pointer 'newargs' is used after the memory that it points to has already
been freed.

Picked up by Coverity - CID 1201425.

Fixes: 0723a047 ("btrfs: allow mounting btrfs subvolumes with
different ro/rw options")
Signed-off-by: default avatarChristoph Jaeger <christophjaeger@linux.com>
Signed-off-by: default avatarChris Mason <clm@fb.com>
parent e4fbaee2
...@@ -1186,7 +1186,6 @@ static struct dentry *mount_subvol(const char *subvol_name, int flags, ...@@ -1186,7 +1186,6 @@ static struct dentry *mount_subvol(const char *subvol_name, int flags,
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
mnt = vfs_kern_mount(&btrfs_fs_type, flags, device_name, mnt = vfs_kern_mount(&btrfs_fs_type, flags, device_name,
newargs); newargs);
kfree(newargs);
if (PTR_RET(mnt) == -EBUSY) { if (PTR_RET(mnt) == -EBUSY) {
if (flags & MS_RDONLY) { if (flags & MS_RDONLY) {
...@@ -1196,17 +1195,22 @@ static struct dentry *mount_subvol(const char *subvol_name, int flags, ...@@ -1196,17 +1195,22 @@ static struct dentry *mount_subvol(const char *subvol_name, int flags,
int r; int r;
mnt = vfs_kern_mount(&btrfs_fs_type, flags | MS_RDONLY, device_name, mnt = vfs_kern_mount(&btrfs_fs_type, flags | MS_RDONLY, device_name,
newargs); newargs);
if (IS_ERR(mnt)) if (IS_ERR(mnt)) {
kfree(newargs);
return ERR_CAST(mnt); return ERR_CAST(mnt);
}
r = btrfs_remount(mnt->mnt_sb, &flags, NULL); r = btrfs_remount(mnt->mnt_sb, &flags, NULL);
if (r < 0) { if (r < 0) {
/* FIXME: release vfsmount mnt ??*/ /* FIXME: release vfsmount mnt ??*/
kfree(newargs);
return ERR_PTR(r); return ERR_PTR(r);
} }
} }
} }
kfree(newargs);
if (IS_ERR(mnt)) if (IS_ERR(mnt))
return ERR_CAST(mnt); return ERR_CAST(mnt);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment