From 6281b85ef10bea27f0cece46f41c44743f1c3bc1 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Sun, 17 Mar 2024 15:38:11 +0800 Subject: [PATCH] website/docs: document path_umount backport Cherry picked from the following changes to the Linux Kernel https://github.com/torvalds/linux/commit/a1e6aaa3743a3daa98d0f9275df8243eef8bb666 https://github.com/torvalds/linux/commit/41525f56e2564c2feff4fb2824823900efb3a39f https://github.com/torvalds/linux/commit/c60166f04283ffba7b88b45d824bbfb2bfccee24 https://github.com/torvalds/linux/commit/09267defa36aaff6ff829bd2fc8b043ec151cc3e Selective backport of path_umount from 5.9 in the included diff. Document it properly. Co-Authored-By: Fede2782 <78815152+Fede2782@users.noreply.github.com> Co-Authored-By: backslashxx <118538522+backslashxx@users.noreply.github.com> --- .../guide/how-to-integrate-for-non-gki.md | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/website/docs/guide/how-to-integrate-for-non-gki.md b/website/docs/guide/how-to-integrate-for-non-gki.md index 131bd5819ed7..00abe5268dc9 100644 --- a/website/docs/guide/how-to-integrate-for-non-gki.md +++ b/website/docs/guide/how-to-integrate-for-non-gki.md @@ -40,6 +40,11 @@ But if you encounter a boot loop when integrated KernelSU, it is maybe *kprobe i comment out `ksu_enable_sucompat()` and `ksu_enable_ksud()` in `KernelSU/kernel/ksu.c`, if the device boots normally, then kprobe may be broken. ::: +:::info How to get module umount feature working on pre-GKI? + +If your kernel is older than 5.9, you should backport ```path_umount``` to ```fs/namespace.c```. This is required to get module umount feature working. If you don't backport ```path_umount```, module umount feature won't work. You can get more info on how to achieve this at the end of this page. +::: + ## Manually modify the kernel source If kprobe does not work in your kernel (may be an upstream or kernel bug below 4.8), then you can try this way: @@ -292,6 +297,55 @@ index 45306f9ef247..815091ebfca4 100755 add_input_randomness(type, code, value); ``` +## path_umount + +You can get module umount feature working on pre-GKI kernels by manually backporting ```path_umount``` from 5.9. You can use this patch as reference: + +```diff +--- a/fs/namespace.c ++++ b/fs/namespace.c +@@ -1739,6 +1739,39 @@ static inline bool may_mandlock(void) + } + #endif + ++static int can_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(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. +``` + Finally, build your kernel again, KernelSU should work well. :::info Entering safe mode accidiently?