Re: [LTP-FAIL][02/21] fs: refactor ksys_umount

From: Al Viro
Date: Thu Aug 06 2020 - 13:26:14 EST


On Thu, Aug 06, 2020 at 04:17:32PM +0200, Christoph Hellwig wrote:
> Fix for umount03 below. The other one works fine here, but from
> your logs this might be a follow on if you run it after umount without
> the fix.

Ugh...

How about
static int may_umount(const struct path *path, int flags)
{
struct mount *mnt = real_mount(path->mnt);

if (flags & ~(MNT_FORCE | MNT_DETACH | MNT_EXPIRE | UMOUNT_NOFOLLOW))
return -EINVAL;
if (!may_mount())
return -EPERM;
if (path->dentry != path->mnt->mnt_root)
return -EINVAL;
if (!check_mnt(mnt))
return -EINVAL;
if (mnt->mnt.mnt_flags & MNT_LOCKED) /* Check optimistically */
return -EINVAL;
if (flags & MNT_FORCE && !capable(CAP_SYS_ADMIN))
return -EPERM;
return 0;
}

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

err = may_umount(path, flags);
if (!err)
err = do_umount(mnt, flags);

/* we mustn't call path_put() as that would clear mnt_expiry_mark */
dput(path->dentry);
mntput_no_expire(mnt);
return err;
}

instead?