diff --git a/Website/docs/zh/guide/how-to-integrate.md b/Website/docs/zh/guide/how-to-integrate.md index 93d78888..3e52abe1 100644 --- a/Website/docs/zh/guide/how-to-integrate.md +++ b/Website/docs/zh/guide/how-to-integrate.md @@ -63,36 +63,6 @@ curl -LSs "https://raw.githubusercontent.com/SukiSU-Ultra/SukiSU-Ultra/main/kern 请参考此文档 [https://github.com/~ (non-GKI 内核集成)](https://github.com/tiann/KernelSU/blob/main/website/docs/guide/how-to-integrate-for-non-gki.md#manually-modify-the-kernel-source) 和 [https://github.com/~ (GKI 内核构建)](https://kernelsu.org/zh_CN/guide/how-to-build.html) 进行手动集成。虽然第一个链接的标题是“适用于 non-GKI”,但它也适用于 GKI。两者都可以正常工作。 -并且手动修改 kernel/reboot.c, 进行手动 reboot hook - -```diff[reboot.c] -diff --git a/kernel/reboot.c b/kernel/reboot.c -index 8f08af3a7d04..3809b8aa6213 100644 ---- a/kernel/reboot.c -+++ b/kernel/reboot.c -@@ -302,6 +302,9 @@ EXPORT_SYMBOL_GPL(kernel_power_off); - - DEFINE_MUTEX(system_transition_mutex); - -+#ifdef CONFIG_KSU -+extern void ksu_handle_reboot(int magic1, int magic2, void __user * arg); -+#endif - /* - * Reboot system call: for obvious reasons only root may call it, - * and even root needs to set up some magic numbers in the registers -@@ -317,6 +320,10 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd, - char buffer[256]; - int ret = 0; - -+#ifdef CONFIG_KSU -+ ksu_handle_reboot(magic1, magic2, arg); -+#endif -+ - /* We only trust the superuser with rebooting the system. */ - if (!ns_capable(pid_ns->user_ns, CAP_SYS_BOOT)) - return -EPERM; -``` - 还有另一种集成方法,但是仍在开发中。 diff --git a/kernel/core_hook.c b/kernel/core_hook.c index a4d7d260..85126a32 100644 --- a/kernel/core_hook.c +++ b/kernel/core_hook.c @@ -653,7 +653,34 @@ int ksu_handle_setuid(struct cred *new, const struct cred *old) return 0; } -extern void ksu_handle_reboot(int magic1, int magic2, void __user * arg); // supercalls.c +// downstream: make sure to pass arg as reference, this can allow us to extend things. +int ksu_handle_sys_reboot(int magic1, int magic2, unsigned int cmd, void __user **arg) +{ + + if (magic1 != KSU_INSTALL_MAGIC1) + return 0; + +#ifdef CONFIG_KSU_DEBUG + pr_info("sys_reboot: intercepted call! magic: 0x%x id: %d\n", magic1, magic2); +#endif + + // Check if this is a request to install KSU fd + if (magic2 == KSU_INSTALL_MAGIC2) { + int fd = ksu_install_fd(); + pr_info("[%d] install ksu fd: %d\n", current->pid, fd); + + // downstream: dereference all arg usage! + if (copy_to_user((void __user *)*arg, &fd, sizeof(fd))) { + pr_err("install ksu fd reply err\n"); + } + + return 0; + } + + // extensions + + return 0; +} // Init functons - kprobe hooks @@ -663,13 +690,10 @@ static int reboot_handler_pre(struct kprobe *p, struct pt_regs *regs) struct pt_regs *real_regs = PT_REAL_REGS(regs); int magic1 = (int)PT_REGS_PARM1(real_regs); int magic2 = (int)PT_REGS_PARM2(real_regs); - unsigned long arg4; + int cmd = (int)PT_REGS_PARM3(real_regs); + void __user **arg = (void __user **)&PT_REGS_SYSCALL_PARM4(real_regs); - // Check if this is a request to install KSU fd - arg4 = (unsigned long)PT_REGS_SYSCALL_PARM4(real_regs); - ksu_handle_reboot(magic1, magic2, (void __user *) arg4); - - return 0; + return ksu_handle_sys_reboot(magic1, magic2, cmd, arg); } static struct kprobe reboot_kp = { diff --git a/kernel/supercalls.c b/kernel/supercalls.c index 4908336e..5dfacba1 100644 --- a/kernel/supercalls.c +++ b/kernel/supercalls.c @@ -69,17 +69,6 @@ static void init_uid_scanner(void) } } -void ksu_handle_reboot(int magic1, int magic2, void __user * arg) { - if (magic1 == KSU_INSTALL_MAGIC1 && magic2 == KSU_INSTALL_MAGIC2) { - int fd = ksu_install_fd(); - pr_info("[%d] install ksu fd: %d\n", current->pid, fd); - - if (copy_to_user(arg, &fd, sizeof(fd))) { - pr_err("install ksu fd reply err\n"); - } - } -} - static int do_grant_root(void __user *arg) { // Check if current UID is allowed