[英]How to compile a linux kernel module for different linux kernel
I am sort of new to kernel programming, but i have been struggling a ton with this issue for days now.我对 kernel 编程有点陌生,但几天来我一直在为这个问题苦苦挣扎。 I have a machine with linux kernel '5.10.0-kali7-amd64' and im using it for development of a linux kernel module for Ubutnu 16.04.4 '4.4.0-119-generic', but i can't figure out any way that i can compile it on my machine for that version and for it to actually work on the 4.4.0 kernel machine.
I have a machine with linux kernel '5.10.0-kali7-amd64' and im using it for development of a linux kernel module for Ubutnu 16.04.4 '4.4.0-119-generic', but i can't figure out any这样我就可以在我的机器上为该版本编译它,并让它在 4.4.0 kernel 机器上实际工作。
The closest i've got is this:我得到的最接近的是:
make -C /lib/modules/4.4.0-119-generic/build M=$(PWD) modules
which also worked and compiled my hello world module.make -C /lib/modules/4.4.0-119-generic/build M=$(PWD) modules
中使用来编译我的模块,这些模块也可以工作并编译我的 hello world 模块。 However when uploaded to the 4.4.0 machine the insmod errored saying insmod: ERROR: could not insert module rootkitMy.ko: Invalid module format
.然而,当上传到 4.4.0 机器时,insmod 出错说
insmod: ERROR: could not insert module rootkitMy.ko: Invalid module format
。 The dmesg says: module: rootkit: Unknown rela relocation: 4
I then compiled my source code on the 4.4.0 machine and created a module with literally the exact same modinfo, but that one did work. dmesg 说:
module: rootkit: Unknown rela relocation: 4
然后我在 4.4.0 机器上编译了我的源代码,并创建了一个具有完全相同 modinfo 的模块,但是那个确实有效。 here are the modinfos for both:这是两者的modinfos:
filename: /rootkit.ko
version: 0.01
description: Rootkit hook
author: Bl4ckC4t
license: GPL
srcversion: 46604268C8D1B7FA5115CB4
depends:
vermagic: 4.4.0-119-generic SMP mod_unload modversions retpoline
filename: /rootkitMy.ko
version: 0.01
description: Rootkit hook
author: Bl4ckC4t
license: GPL
srcversion: 46604268C8D1B7FA5115CB4
depends:
vermagic: 4.4.0-119-generic SMP mod_unload modversions retpoline
rootkitMy.ko was compiled on the 5.10 machine and didn't work while the rootkit.ko was compiled on the 4.4.0 machine and did work properly when injected with insmod
What can I do to compile a working module from my 5.10 machine? rootkitMy.ko 是在 5.10 机器上编译的,但在 rootkit.ko 是在 4.4.0 机器上编译并且在注入
insmod
时可以正常工作 我可以做些什么来从我的 5.10 机器编译一个工作模块?
I managed to resolve the issue.我设法解决了这个问题。
Unknown rela relocation: 4
is an insmod error you get due to a change in the way the kernel handles PLT, more specifically the R_X86_64_PC32 and R_X86_64_PLT32. Unknown rela relocation: 4
是由于 kernel 处理 PLT,更具体地说是 R_X86_64_PC32 和 R_X86_64_PLT32 的方式发生变化而导致的 insmod 错误。 With binutils >= 2.31, the linker has decided to use R_X86_64_PLT32 relocations, which aren't supported in the older kernel.在 binutils >= 2.31 的情况下,linker 决定使用 R_X86_64_PLT32 重定位,旧版 kernel 不支持这些重定位。
To fix this:要解决这个问题:
./configure --prefix=/usr/local/binutils-2.6
make
sudo make install
export PATH=/usr/local/binutils-2.6/bin:$PATH
export PATH=/usr/local/binutils-2.6/bin:$PATH
And now it works!现在它起作用了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.