Skip to content

Commit ccd48bc

Browse files
Al ViroLinus Torvalds
authored andcommitted
[PATCH] cleanups and bug fix in do_loopback()
- check_mnt() on the source of binding should've been unconditional from the very beginning. My fault - as far I could've trace it, that's an old thinko made back in 2001. Kudos to Miklos for spotting it... Fixed. - code cleaned up. Signed-off-by: Al Viro <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 7b7b1ac commit ccd48bc

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

fs/namespace.c

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -661,29 +661,32 @@ static int do_loopback(struct nameidata *nd, char *old_name, int recurse)
661661

662662
down_write(&current->namespace->sem);
663663
err = -EINVAL;
664-
if (check_mnt(nd->mnt) && (!recurse || check_mnt(old_nd.mnt))) {
665-
err = -ENOMEM;
666-
if (recurse)
667-
mnt = copy_tree(old_nd.mnt, old_nd.dentry);
668-
else
669-
mnt = clone_mnt(old_nd.mnt, old_nd.dentry);
670-
}
664+
if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))
665+
goto out;
671666

672-
if (mnt) {
673-
/* stop bind mounts from expiring */
667+
err = -ENOMEM;
668+
if (recurse)
669+
mnt = copy_tree(old_nd.mnt, old_nd.dentry);
670+
else
671+
mnt = clone_mnt(old_nd.mnt, old_nd.dentry);
672+
673+
if (!mnt)
674+
goto out;
675+
676+
/* stop bind mounts from expiring */
677+
spin_lock(&vfsmount_lock);
678+
list_del_init(&mnt->mnt_expire);
679+
spin_unlock(&vfsmount_lock);
680+
681+
err = graft_tree(mnt, nd);
682+
if (err) {
674683
spin_lock(&vfsmount_lock);
675-
list_del_init(&mnt->mnt_expire);
684+
umount_tree(mnt);
676685
spin_unlock(&vfsmount_lock);
686+
} else
687+
mntput(mnt);
677688

678-
err = graft_tree(mnt, nd);
679-
if (err) {
680-
spin_lock(&vfsmount_lock);
681-
umount_tree(mnt);
682-
spin_unlock(&vfsmount_lock);
683-
} else
684-
mntput(mnt);
685-
}
686-
689+
out:
687690
up_write(&current->namespace->sem);
688691
path_release(&old_nd);
689692
return err;

0 commit comments

Comments
 (0)