Skip to content
Snippets Groups Projects
Commit e3eee87c authored by Miklos Szeredi's avatar Miklos Szeredi Committed by Greg Kroah-Hartman
Browse files

ovl: prevent private clone if bind mount is not allowed


commit 427215d8 upstream.

Add the following checks from __do_loopback() to clone_private_mount() as
well:

 - verify that the mount is in the current namespace

 - verify that there are no locked children

Reported-by: default avatarAlois Wohlschlager <alois1@gmx-topmail.de>
Fixes: c771d683 ("vfs: introduce clone_private_mount()")
Cc: <stable@vger.kernel.org> # v3.18
Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent ffdc1e31
No related branches found
No related tags found
No related merge requests found
...@@ -1853,6 +1853,20 @@ void drop_collected_mounts(struct vfsmount *mnt) ...@@ -1853,6 +1853,20 @@ void drop_collected_mounts(struct vfsmount *mnt)
namespace_unlock(); namespace_unlock();
} }
static bool has_locked_children(struct mount *mnt, struct dentry *dentry)
{
struct mount *child;
list_for_each_entry(child, &mnt->mnt_mounts, mnt_child) {
if (!is_subdir(child->mnt_mountpoint, dentry))
continue;
if (child->mnt.mnt_flags & MNT_LOCKED)
return true;
}
return false;
}
/** /**
* clone_private_mount - create a private clone of a path * clone_private_mount - create a private clone of a path
* *
...@@ -1867,16 +1881,27 @@ struct vfsmount *clone_private_mount(struct path *path) ...@@ -1867,16 +1881,27 @@ struct vfsmount *clone_private_mount(struct path *path)
struct mount *old_mnt = real_mount(path->mnt); struct mount *old_mnt = real_mount(path->mnt);
struct mount *new_mnt; struct mount *new_mnt;
down_read(&namespace_sem);
if (IS_MNT_UNBINDABLE(old_mnt)) if (IS_MNT_UNBINDABLE(old_mnt))
return ERR_PTR(-EINVAL); goto invalid;
if (!check_mnt(old_mnt))
goto invalid;
if (has_locked_children(old_mnt, path->dentry))
goto invalid;
down_read(&namespace_sem);
new_mnt = clone_mnt(old_mnt, path->dentry, CL_PRIVATE); new_mnt = clone_mnt(old_mnt, path->dentry, CL_PRIVATE);
up_read(&namespace_sem); up_read(&namespace_sem);
if (IS_ERR(new_mnt)) if (IS_ERR(new_mnt))
return ERR_CAST(new_mnt); return ERR_CAST(new_mnt);
return &new_mnt->mnt; return &new_mnt->mnt;
invalid:
up_read(&namespace_sem);
return ERR_PTR(-EINVAL);
} }
EXPORT_SYMBOL_GPL(clone_private_mount); EXPORT_SYMBOL_GPL(clone_private_mount);
...@@ -2192,19 +2217,6 @@ static int do_change_type(struct path *path, int flag) ...@@ -2192,19 +2217,6 @@ static int do_change_type(struct path *path, int flag)
return err; return err;
} }
static bool has_locked_children(struct mount *mnt, struct dentry *dentry)
{
struct mount *child;
list_for_each_entry(child, &mnt->mnt_mounts, mnt_child) {
if (!is_subdir(child->mnt_mountpoint, dentry))
continue;
if (child->mnt.mnt_flags & MNT_LOCKED)
return true;
}
return false;
}
/* /*
* do loopback mount. * do loopback mount.
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment