[英]Kernel module system call overriding
我試圖覆蓋 4.5.1-1-ARCH 上的開放系統調用,但運氣不佳。 我沒有遇到錯誤,但是從來沒有調用 custom_open 函數,所以它實際上並沒有被覆蓋。
代碼:
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/kallsyms.h>
#include <asm/unistd.h>
#include <linux/uaccess.h>
MODULE_LICENSE("GPL");
static void **sys_call_table = NULL;
static asmlinkage long (*old_open) (const char __user *filename, int flags, umode_t mode);
static asmlinkage long custom_open(const char __user *filename, int flags, umode_t mode)
{
printk(KERN_INFO "Custom open invoked");
return old_open(filename, flags, mode);
}
static int init(void)
{
sys_call_table = (void *)kallsyms_lookup_name("sys_call_table");
pr_info("sys_call_table address: %p\n", sys_call_table);
old_open = sys_call_table[__NR_open];
sys_call_table[__NR_open] = custom_open;
pr_info("Original open: %p; New open: %p\n", old_open, custom_open);
return 0;
}
static void exit(void)
{
pr_info("exit");
sys_call_table[__NR_open] = old_open;
}
module_init(init);
module_exit(exit);
加載模塊后,我在 dmesg 中得到以下信息:
[ 8027.331315] sys_call_table address: f97fe204
[ 8027.331320] Original open: (null); New open: f97fc000
您聲明了一個本地符號 sys_call_table。
你不覺得舊的 open 是空的很可疑嗎? 更有趣的是,sys_call_table 符號的發現地址與custom_open 的地址相差不遠。 這是一個強烈的暗示,你發現的是你自己的 sys_call_table 符號的地址。
你想達到什么目的?
作為旁注,我剛剛驗證了支持系統調用表的頁面被映射為只讀,所以如果僅僅寫入沒有使內核崩潰,你就知道你沒有找到它。
編輯:
因此,我檢查了 arch 配置,本地發現可能是未設置 CONFIG_KALLSYMS_ALL 的副作用。 這也意味着 kallsyms 將無法找到您想要的符號,但這應該無關緊要。
http://maitesin.github.io/Module_prank/上的模塊質量太差,不得使用。 我前段時間遇到過,並在這里解釋了主要缺陷: https : //www.reddit.com/r/programming/comments/4b757p/linux_kernel_module_example_rickroll_prank/d16q5v5
因為你只是在玩,這種活動是沒有用的,尤其是在這個階段。 我只能建議你暫時堅持使用用戶空間。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.