Skip to content

Commit

Permalink
BACKPORT: fs/namespace.c path_umount [5.10.9 + inline]
Browse files Browse the repository at this point in the history
and inline can_umount. shit is likely very hot when on KernelSU

this is the better backport as the comment says:
"caller is responsible for flags being sane"
so that removes the check, and KernelSU already does its check.

tiann/KernelSU#1464
  • Loading branch information
backslashxx authored and alternoegraha committed Oct 23, 2024
1 parent d5639f2 commit 0b9356d
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions fs/namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1645,6 +1645,39 @@ static inline bool may_mandlock(void)
}
#endif

static inline int can_umount(const struct path *path, int flags)
{
struct mount *mnt = real_mount(path->mnt);

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;
}

// caller is responsible for flags being sane
int path_umount(struct path *path, int flags)
{
struct mount *mnt = real_mount(path->mnt);
int ret;

ret = can_umount(path, flags);
if (!ret)
ret = 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 ret;
}

/*
* Now umount can handle mount points as well as block devices.
* This is important for filesystems which use unnamed block devices.
Expand Down

0 comments on commit 0b9356d

Please sign in to comment.