Skip to content

Commit 25ccd24

Browse files
Christoph HellwigAl Viro
authored andcommitted
fs: fix a struct path leak in path_umount
Make sure we also put the dentry and vfsmnt in the illegal flags and !may_umount cases. Fixes: 41525f5 ("fs: refactor ksys_umount") Reported-by: Vikas Kumar <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent f073531 commit 25ccd24

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

fs/namespace.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,34 +1706,38 @@ static inline bool may_mandlock(void)
17061706
}
17071707
#endif
17081708

1709-
int path_umount(struct path *path, int flags)
1709+
static int can_umount(const struct path *path, int flags)
17101710
{
1711-
struct mount *mnt;
1712-
int retval;
1711+
struct mount *mnt = real_mount(path->mnt);
17131712

17141713
if (flags & ~(MNT_FORCE | MNT_DETACH | MNT_EXPIRE | UMOUNT_NOFOLLOW))
17151714
return -EINVAL;
17161715
if (!may_mount())
17171716
return -EPERM;
1718-
1719-
mnt = real_mount(path->mnt);
1720-
retval = -EINVAL;
17211717
if (path->dentry != path->mnt->mnt_root)
1722-
goto dput_and_out;
1718+
return -EINVAL;
17231719
if (!check_mnt(mnt))
1724-
goto dput_and_out;
1720+
return -EINVAL;
17251721
if (mnt->mnt.mnt_flags & MNT_LOCKED) /* Check optimistically */
1726-
goto dput_and_out;
1727-
retval = -EPERM;
1722+
return -EINVAL;
17281723
if (flags & MNT_FORCE && !capable(CAP_SYS_ADMIN))
1729-
goto dput_and_out;
1724+
return -EPERM;
1725+
return 0;
1726+
}
1727+
1728+
int path_umount(struct path *path, int flags)
1729+
{
1730+
struct mount *mnt = real_mount(path->mnt);
1731+
int ret;
1732+
1733+
ret = can_umount(path, flags);
1734+
if (!ret)
1735+
ret = do_umount(mnt, flags);
17301736

1731-
retval = do_umount(mnt, flags);
1732-
dput_and_out:
17331737
/* we mustn't call path_put() as that would clear mnt_expiry_mark */
17341738
dput(path->dentry);
17351739
mntput_no_expire(mnt);
1736-
return retval;
1740+
return ret;
17371741
}
17381742

17391743
static int ksys_umount(char __user *name, int flags)

0 commit comments

Comments
 (0)