Btrfs: fail on mismatched subvol and subvolid mount options
There's nothing to stop a user from passing both subvol= and subvolid= to mount, but if they don't refer to the same subvolume, someone is going to be surprised at some point. Error out on this case, but allow users to pass in both if they do match (which they could, for example, get out of /proc/mounts). Reviewed-by: David Sterba <dsterba@suse.cz> Signed-off-by: Omar Sandoval <osandov@osandov.com> Signed-off-by: Chris Mason <clm@fb.com>
This commit is contained in:
parent
fa33065950
commit
bb289b7be6
@ -1167,8 +1167,9 @@ static char *setup_root_args(char *args)
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct dentry *mount_subvol(const char *subvol_name, int flags,
|
static struct dentry *mount_subvol(const char *subvol_name, u64 subvol_objectid,
|
||||||
const char *device_name, char *data)
|
int flags, const char *device_name,
|
||||||
|
char *data)
|
||||||
{
|
{
|
||||||
struct dentry *root;
|
struct dentry *root;
|
||||||
struct vfsmount *mnt = NULL;
|
struct vfsmount *mnt = NULL;
|
||||||
@ -1214,12 +1215,27 @@ static struct dentry *mount_subvol(const char *subvol_name, int flags,
|
|||||||
/* mount_subtree() drops our reference on the vfsmount. */
|
/* mount_subtree() drops our reference on the vfsmount. */
|
||||||
mnt = NULL;
|
mnt = NULL;
|
||||||
|
|
||||||
if (!IS_ERR(root) && !is_subvolume_inode(d_inode(root))) {
|
if (!IS_ERR(root)) {
|
||||||
struct super_block *s = root->d_sb;
|
struct super_block *s = root->d_sb;
|
||||||
dput(root);
|
struct inode *root_inode = d_inode(root);
|
||||||
root = ERR_PTR(-EINVAL);
|
u64 root_objectid = BTRFS_I(root_inode)->root->root_key.objectid;
|
||||||
deactivate_locked_super(s);
|
|
||||||
pr_err("BTRFS: '%s' is not a valid subvolume\n", subvol_name);
|
ret = 0;
|
||||||
|
if (!is_subvolume_inode(root_inode)) {
|
||||||
|
pr_err("BTRFS: '%s' is not a valid subvolume\n",
|
||||||
|
subvol_name);
|
||||||
|
ret = -EINVAL;
|
||||||
|
}
|
||||||
|
if (subvol_objectid && root_objectid != subvol_objectid) {
|
||||||
|
pr_err("BTRFS: subvol '%s' does not match subvolid %llu\n",
|
||||||
|
subvol_name, subvol_objectid);
|
||||||
|
ret = -EINVAL;
|
||||||
|
}
|
||||||
|
if (ret) {
|
||||||
|
dput(root);
|
||||||
|
root = ERR_PTR(ret);
|
||||||
|
deactivate_locked_super(s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
@ -1312,7 +1328,8 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
|
|||||||
|
|
||||||
if (subvol_name) {
|
if (subvol_name) {
|
||||||
/* mount_subvol() will free subvol_name. */
|
/* mount_subvol() will free subvol_name. */
|
||||||
return mount_subvol(subvol_name, flags, device_name, data);
|
return mount_subvol(subvol_name, subvol_objectid, flags,
|
||||||
|
device_name, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
security_init_mnt_opts(&new_sec_opts);
|
security_init_mnt_opts(&new_sec_opts);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user