更新 KPM 模块中的 copy_to_user 调用,增加对内核版本的条件编译支持,优化错误处理逻辑
This commit is contained in:
@@ -54,6 +54,10 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,6,0)
|
||||||
|
#define USE_DIRECT_PRINT
|
||||||
|
#endif
|
||||||
|
|
||||||
// ============================================================================================
|
// ============================================================================================
|
||||||
|
|
||||||
noinline
|
noinline
|
||||||
@@ -63,7 +67,13 @@ __section(".text") void sukisu_kpm_load_module_path(const char* path, const char
|
|||||||
int res = -1;
|
int res = -1;
|
||||||
printk("KPM: Stub function called (sukisu_kpm_load_module_path). path=%s args=%s ptr=%p\n", path, args, ptr);
|
printk("KPM: Stub function called (sukisu_kpm_load_module_path). path=%s args=%s ptr=%p\n", path, args, ptr);
|
||||||
__asm__ volatile("nop"); // 精确控制循环不被优化
|
__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
|
noinline
|
||||||
@@ -73,7 +83,12 @@ __section(".text") void sukisu_kpm_unload_module(const char* name, void* ptr, vo
|
|||||||
int res = -1;
|
int res = -1;
|
||||||
printk("KPM: Stub function called (sukisu_kpm_unload_module). name=%s ptr=%p\n", name, ptr);
|
printk("KPM: Stub function called (sukisu_kpm_unload_module). name=%s ptr=%p\n", name, ptr);
|
||||||
__asm__ volatile("nop"); // 精确控制循环不被优化
|
__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
|
noinline
|
||||||
@@ -83,7 +98,12 @@ __section(".text") void sukisu_kpm_num(void __user* result) {
|
|||||||
int res = 0;
|
int res = 0;
|
||||||
printk("KPM: Stub function called (sukisu_kpm_num).\n");
|
printk("KPM: Stub function called (sukisu_kpm_num).\n");
|
||||||
__asm__ volatile("nop"); // 精确控制循环不被优化
|
__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
|
noinline
|
||||||
@@ -93,7 +113,12 @@ __section(".text") void sukisu_kpm_info(const char* name, void __user* out, void
|
|||||||
int res = -1;
|
int res = -1;
|
||||||
printk("KPM: Stub function called (sukisu_kpm_info). name=%s buffer=%p\n", name, out);
|
printk("KPM: Stub function called (sukisu_kpm_info). name=%s buffer=%p\n", name, out);
|
||||||
__asm__ volatile("nop"); // 精确控制循环不被优化
|
__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
|
noinline
|
||||||
@@ -102,7 +127,12 @@ __section(".text") void sukisu_kpm_list(void __user* out, unsigned int bufferSiz
|
|||||||
// This is a KPM module stub.
|
// This is a KPM module stub.
|
||||||
int res = -1;
|
int res = -1;
|
||||||
printk("KPM: Stub function called (sukisu_kpm_list). buffer=%p size=%d\n", out, bufferSize);
|
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
|
noinline
|
||||||
@@ -112,7 +142,12 @@ __section(".text") void sukisu_kpm_control(void __user* name, void __user* args,
|
|||||||
int res = -1;
|
int res = -1;
|
||||||
printk("KPM: Stub function called (sukisu_kpm_control). name=%p args=%p\n", name, args);
|
printk("KPM: Stub function called (sukisu_kpm_control). name=%p args=%p\n", name, args);
|
||||||
__asm__ volatile("nop"); // 精确控制循环不被优化
|
__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
|
noinline
|
||||||
@@ -120,7 +155,12 @@ NO_OPTIMIZE
|
|||||||
__section(".text") void sukisu_kpm_version(void __user* out, unsigned int bufferSize, void __user* result) {
|
__section(".text") void sukisu_kpm_version(void __user* out, unsigned int bufferSize, void __user* result) {
|
||||||
int res = -1;
|
int res = -1;
|
||||||
printk("KPM: Stub function called (sukisu_kpm_version). buffer=%p size=%d\n", out, bufferSize);
|
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);
|
EXPORT_SYMBOL(sukisu_kpm_load_module_path);
|
||||||
|
|||||||
Reference in New Issue
Block a user