struct path under = {};
int err = -ENOENT;
+ if (unlikely(beneath) && !path_mounted(path))
+ return -EINVAL;
+
for (;;) {
struct mount *m = real_mount(mnt);
if (beneath) {
path_put(&under);
read_seqlock_excl(&mount_lock);
+ if (unlikely(!mnt_has_parent(m))) {
+ read_sequnlock_excl(&mount_lock);
+ return -EINVAL;
+ }
under.mnt = mntget(&m->mnt_parent->mnt);
under.dentry = dget(m->mnt_mountpoint);
read_sequnlock_excl(&mount_lock);
* @to: mount under which to mount
* @mp: mountpoint of @to
*
- * - Make sure that @to->dentry is actually the root of a mount under
- * which we can mount another mount.
* - Make sure that nothing can be mounted beneath the caller's current
* root or the rootfs of the namespace.
* - Make sure that the caller can unmount the topmost mount ensuring
struct mount *mnt_to = real_mount(to->mnt),
*parent_mnt_to = mnt_to->mnt_parent;
- if (!mnt_has_parent(mnt_to))
- return -EINVAL;
-
- if (!path_mounted(to))
- return -EINVAL;
-
if (IS_MNT_LOCKED(mnt_to))
return -EINVAL;