From 4a37422af52417386c5619e70a910fdd7c8f0acc Mon Sep 17 00:00:00 2001 From: backslashxx <118538522+backslashxx@users.noreply.github.com> Date: Thu, 15 May 2025 16:45:37 +0800 Subject: [PATCH] kernel/sucompat: sync to KSU pr #2506 kernel: sucompat: sucompat toggle support for non-kp This is done like how vfs_read_hook, input_hook and execve_hook is disabled. While this is not exactly the same thing, this CAN achieve the same results. The complete disabling of all KernelSU hooks. While this is likely unneeded, It keeps feature parity to non-kprobe builds. adapted from upstream: kernel: Allow to re-enable sucompat - https://github.com/tiann/KernelSU/commit/4593ae81c78998dffbc81291eac15726a273a538 Rejected: https://github.com/tiann/KernelSU/pull/2506 Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com> kernel: sucompat: fix compile issue on kprobe builds, unused variable --- kernel/sucompat.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/kernel/sucompat.c b/kernel/sucompat.c index 9f5d7ca9..c2c4291e 100644 --- a/kernel/sucompat.c +++ b/kernel/sucompat.c @@ -24,11 +24,9 @@ #define SU_PATH "/system/bin/su" #define SH_PATH "/system/bin/sh" -bool ksu_faccessat_hook __read_mostly = true; -bool ksu_stat_hook __read_mostly = true; -bool ksu_execve_sucompat_hook __read_mostly = true; -bool ksu_execveat_sucompat_hook __read_mostly = true; -bool ksu_devpts_hook __read_mostly = true; +#ifndef CONFIG_KSU_WITH_KPROBES +static bool ksu_sucompat_non_kp __read_mostly = true; +#endif extern void escape_to_root(); @@ -61,7 +59,7 @@ int ksu_handle_faccessat(int *dfd, const char __user **filename_user, int *mode, const char su[] = SU_PATH; #ifndef CONFIG_KSU_WITH_KPROBES - if (!ksu_faccessat_hook) { + if (!ksu_sucompat_non_kp) { return 0; } #endif @@ -88,7 +86,7 @@ int ksu_handle_stat(int *dfd, const char __user **filename_user, int *flags) const char su[] = SU_PATH; #ifndef CONFIG_KSU_WITH_KPROBES - if (!ksu_stat_hook){ + if (!ksu_sucompat_non_kp){ return 0; } #endif @@ -138,7 +136,7 @@ int ksu_handle_execveat_sucompat(int *fd, struct filename **filename_ptr, const char su[] = SU_PATH; #ifndef CONFIG_KSU_WITH_KPROBES - if (!ksu_execveat_sucompat_hook) { + if (!ksu_sucompat_non_kp) { return 0; } #endif @@ -173,7 +171,7 @@ int ksu_handle_execve_sucompat(int *fd, const char __user **filename_user, char path[sizeof(su) + 1]; #ifndef CONFIG_KSU_WITH_KPROBES - if (!ksu_execve_sucompat_hook) { + if (!ksu_sucompat_non_kp) { return 0; } #endif @@ -201,7 +199,7 @@ int ksu_handle_execve_sucompat(int *fd, const char __user **filename_user, int ksu_handle_devpts(struct inode *inode) { #ifndef CONFIG_KSU_WITH_KPROBES - if (!ksu_devpts_hook) { + if (!ksu_sucompat_non_kp) { return 0; } #endif @@ -323,11 +321,7 @@ void ksu_sucompat_init() su_kps[2] = init_kprobe(SYS_NEWFSTATAT_SYMBOL, newfstatat_handler_pre); su_kps[3] = init_kprobe("pts_unix98_lookup", pts_unix98_lookup_pre); #else - ksu_faccessat_hook = true; - ksu_stat_hook = true; - ksu_execve_sucompat_hook = true; - ksu_execveat_sucompat_hook = true; - ksu_devpts_hook = true; + ksu_sucompat_non_kp = true; pr_info("ksu_sucompat_init: hooks enabled: execve/execveat_su, faccessat, stat, devpts\n"); #endif } @@ -339,11 +333,7 @@ void ksu_sucompat_exit() destroy_kprobe(&su_kps[i]); } #else - ksu_faccessat_hook = false; - ksu_stat_hook = false; - ksu_execve_sucompat_hook = false; - ksu_execveat_sucompat_hook = false; - ksu_devpts_hook = false; + ksu_sucompat_non_kp = false; pr_info("ksu_sucompat_exit: hooks disabled: execve/execveat_su, faccessat, stat, devpts\n"); #endif }