From 36cca65af3809fb9fec120ced1a52e46b1804ba8 Mon Sep 17 00:00:00 2001 From: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com> Date: Fri, 13 Jun 2025 15:42:11 +0800 Subject: [PATCH] kernel: Add CMD_HOOK_TYPE handling to core_hook.c to support state lookups for manual hooks Co-authored-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com> Co-authored-by: rifsxd Signed-off-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com> --- kernel/core_hook.c | 23 +++++++++++++++++++++++ kernel/ksu.h | 1 + 2 files changed, 24 insertions(+) diff --git a/kernel/core_hook.c b/kernel/core_hook.c index e10fc149..fa4aadae 100644 --- a/kernel/core_hook.c +++ b/kernel/core_hook.c @@ -529,6 +529,29 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3, return 0; } + if (arg2 == CMD_HOOK_TYPE) { + const char *hook_type; + +#ifdef CONFIG_KSU_MANUAL_HOOK + hook_type = "Manual"; +#elif defined(CONFIG_KSU_KPROBES_HOOK) + hook_type = "Kprobes"; +#else + hook_type = "Unknown"; +#endif + + size_t len = strlen(hook_type) + 1; + if (copy_to_user((void __user *)arg3, hook_type, len)) { + pr_err("hook_type: copy_to_user failed\n"); + return 0; + } + + if (copy_to_user(result, &reply_ok, sizeof(reply_ok))) { + pr_err("hook_type: prctl reply error\n"); + } + return 0; + } + #ifdef CONFIG_KSU_SUSFS if (current_uid_val == 0) { #ifdef CONFIG_KSU_SUSFS_SUS_PATH diff --git a/kernel/ksu.h b/kernel/ksu.h index 8643c921..0dd2cec9 100644 --- a/kernel/ksu.h +++ b/kernel/ksu.h @@ -24,6 +24,7 @@ #define CMD_IS_SU_ENABLED 14 #define CMD_ENABLE_SU 15 #define CMD_ENABLE_KPM 100 +#define CMD_HOOK_TYPE 101 #define EVENT_POST_FS_DATA 1 #define EVENT_BOOT_COMPLETED 2