From fc85270a35fb8a9ada1c47960ee3bb8199a15fd8 Mon Sep 17 00:00:00 2001 From: rsuntk Date: Tue, 22 Jul 2025 21:55:49 +0700 Subject: [PATCH] kernel: code clean up and some inlining Signed-off-by: rsuntk --- kernel/ksud.c | 36 ++---------------------------------- kernel/sucompat.c | 24 +++++++----------------- 2 files changed, 9 insertions(+), 51 deletions(-) diff --git a/kernel/ksud.c b/kernel/ksud.c index 972191ea..950609f4 100644 --- a/kernel/ksud.c +++ b/kernel/ksud.c @@ -75,11 +75,11 @@ void on_post_fs_data(void) { static bool done = false; if (done) { - pr_info("on_post_fs_data already done\n"); + pr_info("%s already done\n", __func__); return; } done = true; - pr_info("on_post_fs_data!\n"); + pr_info("%s!\n", __func__); ksu_load_allow_list(); // sanity check, this may influence the performance stop_input_hook(); @@ -523,18 +523,6 @@ static int sys_execve_handler_pre(struct kprobe *p, struct pt_regs *regs) NULL); } -// remove this later! -__maybe_unused static int vfs_read_handler_pre(struct kprobe *p, - struct pt_regs *regs) -{ - struct file **file_ptr = (struct file **)&PT_REGS_PARM1(regs); - char __user **buf_ptr = (char **)&PT_REGS_PARM2(regs); - size_t *count_ptr = (size_t *)&PT_REGS_PARM3(regs); - loff_t **pos_ptr = (loff_t **)&PT_REGS_CCALL_PARM4(regs); - - return ksu_handle_vfs_read(file_ptr, buf_ptr, count_ptr, pos_ptr); -} - static int sys_read_handler_pre(struct kprobe *p, struct pt_regs *regs) { struct pt_regs *real_regs = PT_REAL_REGS(regs); @@ -554,35 +542,15 @@ static int input_handle_event_handler_pre(struct kprobe *p, return ksu_handle_input_handle_event(type, code, value); } -#if 1 static struct kprobe execve_kp = { .symbol_name = SYS_EXECVE_SYMBOL, .pre_handler = sys_execve_handler_pre, }; -#else -static struct kprobe execve_kp = { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 9, 0) - .symbol_name = "do_execveat_common", -#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0) - .symbol_name = "__do_execve_file", -#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) - .symbol_name = "do_execveat_common", -#endif - .pre_handler = execve_handler_pre, -}; -#endif -#if 1 static struct kprobe vfs_read_kp = { .symbol_name = SYS_READ_SYMBOL, .pre_handler = sys_read_handler_pre, }; -#else -static struct kprobe vfs_read_kp = { - .symbol_name = "vfs_read", - .pre_handler = vfs_read_handler_pre, -}; -#endif static struct kprobe input_event_kp = { .symbol_name = "input_event", diff --git a/kernel/sucompat.c b/kernel/sucompat.c index 407c39a6..fe8a38d0 100644 --- a/kernel/sucompat.c +++ b/kernel/sucompat.c @@ -25,11 +25,15 @@ #define SU_PATH "/system/bin/su" #define SH_PATH "/system/bin/sh" +static const char sh_path = SH_PATH; +static const char su_path = SU_PATH; +static const char ksud_path[] = KSUD_PATH; + extern void escape_to_root(); bool ksu_sucompat_hook_state __read_mostly = true; -static void __user *userspace_stack_buffer(const void *d, size_t len) +static inline void __user *userspace_stack_buffer(const void *d, size_t len) { /* To avoid having to mmap a page in userspace, just write below the stack * pointer. */ @@ -38,26 +42,19 @@ static void __user *userspace_stack_buffer(const void *d, size_t len) return copy_to_user(p, d, len) ? NULL : p; } -static char __user *sh_user_path(void) +static inline char __user *sh_user_path(void) { - static const char sh_path[] = "/system/bin/sh"; - return userspace_stack_buffer(sh_path, sizeof(sh_path)); } -static char __user *ksud_user_path(void) +static inline char __user *ksud_user_path(void) { - static const char ksud_path[] = KSUD_PATH; - return userspace_stack_buffer(ksud_path, sizeof(ksud_path)); } int ksu_handle_faccessat(int *dfd, const char __user **filename_user, int *mode, int *__unused_flags) { - - const char su[] = SU_PATH; - #ifndef CONFIG_KSU_KPROBES_HOOK if (!ksu_sucompat_hook_state) { return 0; @@ -82,9 +79,6 @@ int ksu_handle_faccessat(int *dfd, const char __user **filename_user, int *mode, int ksu_handle_stat(int *dfd, const char __user **filename_user, int *flags) { - // const char sh[] = SH_PATH; - const char su[] = SU_PATH; - #ifndef CONFIG_KSU_KPROBES_HOOK if (!ksu_sucompat_hook_state) { return 0; @@ -118,9 +112,6 @@ int ksu_handle_execveat_sucompat(int *fd, struct filename **filename_ptr, int *__never_use_flags) { struct filename *filename; - const char sh[] = KSUD_PATH; - const char su[] = SU_PATH; - #ifndef CONFIG_KSU_KPROBES_HOOK if (!ksu_sucompat_hook_state) { return 0; @@ -153,7 +144,6 @@ int ksu_handle_execve_sucompat(int *fd, const char __user **filename_user, void *__never_use_argv, void *__never_use_envp, int *__never_use_flags) { - const char su[] = SU_PATH; char path[sizeof(su) + 1]; if (unlikely(!filename_user))