From f17e1064645be9512dae16faa111375dde55408a Mon Sep 17 00:00:00 2001 From: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com> Date: Tue, 1 Apr 2025 12:38:06 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=20KPM=20=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E4=B8=AD=E5=87=BD=E6=95=B0=E7=9A=84=E5=8F=AF=E8=A7=81=E6=80=A7?= =?UTF-8?q?=E4=BF=AE=E9=A5=B0=E7=AC=A6=EF=BC=8C=E7=AE=80=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/kpm/Makefile | 2 -- kernel/kpm/compact.c | 5 ++- kernel/kpm/kpm.c | 72 ++++++++++---------------------------------- 3 files changed, 18 insertions(+), 61 deletions(-) diff --git a/kernel/kpm/Makefile b/kernel/kpm/Makefile index e0a8ce1a..df093314 100644 --- a/kernel/kpm/Makefile +++ b/kernel/kpm/Makefile @@ -1,4 +1,2 @@ obj-y += kpm.o obj-y += compact.o - -ccflags-y += -flto=thin \ No newline at end of file diff --git a/kernel/kpm/compact.c b/kernel/kpm/compact.c index 3caa17f5..e25a7a53 100644 --- a/kernel/kpm/compact.c +++ b/kernel/kpm/compact.c @@ -36,14 +36,13 @@ struct CompactAddressSymbol { void* addr; }; -__section(".data") static struct CompactAddressSymbol address_symbol [] = { +static struct CompactAddressSymbol address_symbol [] = { { "kallsyms_lookup_name", &kallsyms_lookup_name }, { "compact_find_symbol", &sukisu_compact_find_symbol }, { "is_run_in_sukisu_ultra", (void*)1 } }; - -__section(".text") unsigned long sukisu_compact_find_symbol(const char* name) { +unsigned long sukisu_compact_find_symbol(const char* name) { int i; unsigned long addr; diff --git a/kernel/kpm/kpm.c b/kernel/kpm/kpm.c index 375da32a..39c09ad1 100644 --- a/kernel/kpm/kpm.c +++ b/kernel/kpm/kpm.c @@ -54,113 +54,73 @@ #endif #endif -#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,6,0) - #define USE_DIRECT_PRINT -#endif - // ============================================================================================ noinline NO_OPTIMIZE -__section(".text") void sukisu_kpm_load_module_path(const char* path, const char* args, void* ptr, void __user* result) { +void sukisu_kpm_load_module_path(const char* path, const char* args, void* ptr, void __user* result) { // This is a KPM module stub. int res = -1; printk("KPM: Stub function called (sukisu_kpm_load_module_path). path=%s args=%s ptr=%p\n", path, args, ptr); __asm__ volatile("nop"); // 精确控制循环不被优化 -#ifndef USE_DIRECT_PRINT - if(copy_to_user(result, &res, sizeof(res)) < 1) - printk("KPM: Copy to user failed."); -#else - printk("KPM: Kernel version >= 6.6, unknown return"); -#endif - + if(copy_to_user(result, &res, sizeof(res)) < 1) printk("KPM: Copy to user faild."); } noinline NO_OPTIMIZE -__section(".text") void sukisu_kpm_unload_module(const char* name, void* ptr, void __user* result) { +void sukisu_kpm_unload_module(const char* name, void* ptr, void __user* result) { // This is a KPM module stub. int res = -1; printk("KPM: Stub function called (sukisu_kpm_unload_module). name=%s ptr=%p\n", name, ptr); __asm__ volatile("nop"); // 精确控制循环不被优化 -#ifndef USE_DIRECT_PRINT - if(copy_to_user(result, &res, sizeof(res)) < 1) - printk("KPM: Copy to user failed."); -#else - printk("KPM: Kernel version >= 6.6, unknown return"); -#endif + if(copy_to_user(result, &res, sizeof(res)) < 1) printk("KPM: Copy to user faild."); } noinline NO_OPTIMIZE -__section(".text") void sukisu_kpm_num(void __user* result) { +void sukisu_kpm_num(void __user* result) { // This is a KPM module stub. int res = 0; printk("KPM: Stub function called (sukisu_kpm_num).\n"); __asm__ volatile("nop"); // 精确控制循环不被优化 -#ifndef USE_DIRECT_PRINT - if(copy_to_user(result, &res, sizeof(res)) < 1) - printk("KPM: Copy to user failed."); -#else - printk("KPM: Kernel version >= 6.6, unknown return"); -#endif + if(copy_to_user(result, &res, sizeof(res)) < 1) printk("KPM: Copy to user faild."); } noinline NO_OPTIMIZE -__section(".text") void sukisu_kpm_info(const char* name, void __user* out, void __user* result) { +void sukisu_kpm_info(const char* name, void __user* out, void __user* result) { // This is a KPM module stub. int res = -1; printk("KPM: Stub function called (sukisu_kpm_info). name=%s buffer=%p\n", name, out); __asm__ volatile("nop"); // 精确控制循环不被优化 -#ifndef USE_DIRECT_PRINT - if(copy_to_user(result, &res, sizeof(res)) < 1) - printk("KPM: Copy to user failed."); -#else - printk("KPM: Kernel version >= 6.6, unknown return"); -#endif + if(copy_to_user(result, &res, sizeof(res)) < 1) printk("KPM: Copy to user faild."); } noinline NO_OPTIMIZE -__section(".text") void sukisu_kpm_list(void __user* out, unsigned int bufferSize, void __user* result) { +void sukisu_kpm_list(void __user* out, unsigned int bufferSize, void __user* result) { // This is a KPM module stub. int res = -1; printk("KPM: Stub function called (sukisu_kpm_list). buffer=%p size=%d\n", out, bufferSize); -#ifndef USE_DIRECT_PRINT - if(copy_to_user(result, &res, sizeof(res)) < 1) - printk("KPM: Copy to user failed."); -#else - printk("KPM: Kernel version >= 6.6, unknown return"); -#endif + if(copy_to_user(result, &res, sizeof(res)) < 1) printk("KPM: Copy to user faild."); } noinline NO_OPTIMIZE -__section(".text") void sukisu_kpm_control(void __user* name, void __user* args, void __user* result) { +void sukisu_kpm_control(void __user* name, void __user* args, void __user* result) { // This is a KPM module stub. int res = -1; printk("KPM: Stub function called (sukisu_kpm_control). name=%p args=%p\n", name, args); __asm__ volatile("nop"); // 精确控制循环不被优化 -#ifndef USE_DIRECT_PRINT - if(copy_to_user(result, &res, sizeof(res)) < 1) - printk("KPM: Copy to user failed."); -#else - printk("KPM: Kernel version >= 6.6, unknown return"); -#endif + if(copy_to_user(result, &res, sizeof(res)) < 1) printk("KPM: Copy to user faild."); } noinline NO_OPTIMIZE -__section(".text") void sukisu_kpm_version(void __user* out, unsigned int bufferSize, void __user* result) { +void sukisu_kpm_version(void __user* out, unsigned int bufferSize, void __user* result) { int res = -1; printk("KPM: Stub function called (sukisu_kpm_version). buffer=%p size=%d\n", out, bufferSize); -#ifndef USE_DIRECT_PRINT - if(copy_to_user(result, &res, sizeof(res)) < 1) - printk("KPM: Copy to user failed."); -#else - printk("KPM: Kernel version >= 6.6, unknown return"); -#endif + if(copy_to_user(result, &res, sizeof(res)) < 1) printk("KPM: Copy to user faild."); } EXPORT_SYMBOL(sukisu_kpm_load_module_path); @@ -172,7 +132,7 @@ EXPORT_SYMBOL(sukisu_kpm_version); EXPORT_SYMBOL(sukisu_kpm_control); noinline -__section(".text") int sukisu_handle_kpm(unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5) +int sukisu_handle_kpm(unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5) { if(arg2 == SUKISU_KPM_LOAD) { char kernel_load_path[256] = { 0 }; @@ -217,7 +177,7 @@ __section(".text") int sukisu_handle_kpm(unsigned long arg2, unsigned long arg3, return 0; } -__section(".text") int sukisu_is_kpm_control_code(unsigned long arg2) { +int sukisu_is_kpm_control_code(unsigned long arg2) { return (arg2 >= CMD_KPM_CONTROL && arg2 <= CMD_KPM_CONTROL_MAX) ? 1 : 0; }