fs: fix a struct path leak in path_umount

From: Christoph Hellwig
Date: Thu Aug 06 2020 - 10:07:10 EST


Make sure we also put the dentry and vfsmnt in the illegal flags
and !may_mount cases.

Fixes: 41525f56e256 ("fs: refactor ksys_umount")
Reported-by: Vikas Kumar <vikas.kumar2@xxxxxxx>
Signed-off-by: Christoph Hellwig <hch@xxxxxx>
---
fs/namespace.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/namespace.c b/fs/namespace.c
index a7301790abb211..1180437dfab909 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -1708,15 +1708,16 @@ static inline bool may_mandlock(void)

int path_umount(struct path *path, int flags)
{
- struct mount *mnt;
+ struct mount *mnt = real_mount(path->mnt);
int retval;

+ retval = -EINVAL;
if (flags & ~(MNT_FORCE | MNT_DETACH | MNT_EXPIRE | UMOUNT_NOFOLLOW))
- return -EINVAL;
+ goto dput_and_out;
+ retval = -EPERM;
if (!may_mount())
- return -EPERM;
+ goto dput_and_out;

- mnt = real_mount(path->mnt);
retval = -EINVAL;
if (path->dentry != path->mnt->mnt_root)
goto dput_and_out;
--
2.27.0