From 78b662c3604de15cbd05829ce143bf7196c4c9ef Mon Sep 17 00:00:00 2001 From: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com> Date: Tue, 1 Apr 2025 12:24:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20KPM=20=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=20copy=5Fto=5Fuser=20=E8=B0=83=E7=94=A8?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=AF=B9=E5=86=85=E6=A0=B8=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E7=9A=84=E6=9D=A1=E4=BB=B6=E7=BC=96=E8=AF=91=E6=94=AF?= =?UTF-8?q?=E6=8C=81=EF=BC=8C=E4=BC=98=E5=8C=96=E9=94=99=E8=AF=AF=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/kpm/kpm.c | 54 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/kernel/kpm/kpm.c b/kernel/kpm/kpm.c index efda485e..375da32a 100644 --- a/kernel/kpm/kpm.c +++ b/kernel/kpm/kpm.c @@ -54,6 +54,10 @@ #endif #endif +#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,6,0) + #define USE_DIRECT_PRINT +#endif + // ============================================================================================ noinline @@ -63,7 +67,13 @@ __section(".text") void sukisu_kpm_load_module_path(const char* path, const char 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"); // 精确控制循环不被优化 - if(copy_to_user(result, &res, sizeof(res)) < 1) printk("KPM: Copy to user faild."); +#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 + } noinline @@ -73,7 +83,12 @@ __section(".text") void sukisu_kpm_unload_module(const char* name, void* ptr, vo int res = -1; printk("KPM: Stub function called (sukisu_kpm_unload_module). name=%s ptr=%p\n", name, ptr); __asm__ volatile("nop"); // 精确控制循环不被优化 - if(copy_to_user(result, &res, sizeof(res)) < 1) printk("KPM: Copy to user faild."); +#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 } noinline @@ -83,7 +98,12 @@ __section(".text") void sukisu_kpm_num(void __user* result) { int res = 0; printk("KPM: Stub function called (sukisu_kpm_num).\n"); __asm__ volatile("nop"); // 精确控制循环不被优化 - if(copy_to_user(result, &res, sizeof(res)) < 1) printk("KPM: Copy to user faild."); +#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 } noinline @@ -93,7 +113,12 @@ __section(".text") void sukisu_kpm_info(const char* name, void __user* out, void int res = -1; printk("KPM: Stub function called (sukisu_kpm_info). name=%s buffer=%p\n", name, out); __asm__ volatile("nop"); // 精确控制循环不被优化 - if(copy_to_user(result, &res, sizeof(res)) < 1) printk("KPM: Copy to user faild."); +#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 } noinline @@ -102,7 +127,12 @@ __section(".text") void sukisu_kpm_list(void __user* out, unsigned int bufferSiz // This is a KPM module stub. int res = -1; printk("KPM: Stub function called (sukisu_kpm_list). buffer=%p size=%d\n", out, bufferSize); - if(copy_to_user(result, &res, sizeof(res)) < 1) printk("KPM: Copy to user faild."); +#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 } noinline @@ -112,7 +142,12 @@ __section(".text") void sukisu_kpm_control(void __user* name, void __user* args, int res = -1; printk("KPM: Stub function called (sukisu_kpm_control). name=%p args=%p\n", name, args); __asm__ volatile("nop"); // 精确控制循环不被优化 - if(copy_to_user(result, &res, sizeof(res)) < 1) printk("KPM: Copy to user faild."); +#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 } noinline @@ -120,7 +155,12 @@ NO_OPTIMIZE __section(".text") 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); - if(copy_to_user(result, &res, sizeof(res)) < 1) printk("KPM: Copy to user faild."); +#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 } EXPORT_SYMBOL(sukisu_kpm_load_module_path);