RHEL 10 编译内核模块:vermagic、签名与 taint
RHEL 10 默认只信任 Red Hat 签名的内核模块。自己编译的 out-of-tree 模块能加载(Secure Boot 关闭时),但会 taint 内核;modinfo 里没有 sig_id/signer 就是最直接的信号。
在 PVE 390 rhel10-lab(RHEL 10.2)执行:
sudo dnf -y install gcc make kernel-devel-$(uname -r)uname -r# 6.12.0-211.73.1.el10_2.x86_64E3 记录:plans/content-expansion/evidence/rhel/rhel-kmod-build/run.json(4 步,含 build/modinfo/insmod/rmmod 输出 sha256)。
先给结论:out-of-tree 没有 Red Hat 签名
Section titled “先给结论:out-of-tree 没有 Red Hat 签名”kernel-devel提供/lib/modules/$(uname -r)/build;- 自己编译的
.ko没有sig_id/signer; - Secure Boot 关闭时
insmod仍可加载,内核会 taint; - Secure Boot 打开时,未签名模块会被直接拒绝。
hello 模块
Section titled “hello 模块”hello.c:
#include <linux/module.h>#include <linux/kernel.h>
static int __init hello_init(void){ pr_info("hello: init\n"); return 0;}
static void __exit hello_exit(void){ pr_info("hello: exit\n");}
module_init(hello_init);module_exit(hello_exit);
MODULE_LICENSE("GPL");MODULE_DESCRIPTION("RunEntLinux lab hello module");MODULE_VERSION("0.1");Makefile:
obj-m := hello.ocd /tmp/hello-modmake -C /lib/modules/$(uname -r)/build M=$PWD modules产物 hello.ko;vermagic 必须与当前内核一致,否则 insmod 报 “invalid module format”。
modinfo:看 vermagic 与签名
Section titled “modinfo:看 vermagic 与签名”$ modinfo /tmp/hello-mod/hello.kofilename: /tmp/hello-mod/hello.koversion: 0.1license: GPLrhelversion: 10.2srcversion: 3FD3E81CE9B4B0E7CF0BB8Avermagic: 6.12.0-211.73.1.el10_2.x86_64 SMP preempt mod_unload modversions注意没有 sig_id / signer 行。系统自带模块(如 xfs)会有 sig_id: PKCS#7、signer: Red Hat...。
insmod:能加载但 taint
Section titled “insmod:能加载但 taint”sudo insmod /tmp/hello-mod/hello.kolsmod | grep hello# hello 12288 0sudo dmesg | grep -i hello[58174.752009] hello: loading out-of-tree module taints kernel.[58174.758327] hello: module verification failed: signature and/or required key missing - tainting kernel两行 taint:out-of-tree + 无签名。lsmod 的引用计数为 0 表示没被使用。
sudo rmmod hellolsmod | grep hello || echo no-hello普通用户直接 dmesg 会报 Operation not permitted(RHEL 10 限制 CAP_SYSLOG);看内核日志用 sudo dmesg/journalctl -k。
Secure Boot 边界
Section titled “Secure Boot 边界”本次 VM 是 SeaBIOS、未启用 Secure Boot,所以未签名模块能加载。如果 mokutil --sb-state 显示 SecureBoot enabled:
- 未签名模块会被内核拒绝(
insmod: ERROR: could not insert module: Key was rejected by service); - 需要给模块签名并
mokutil --import注册公钥(MOK),或关闭 Secure Boot; - 生产不建议关闭 Secure Boot 来迁就模块。
-
kernel-devel与uname -r完全一致; -
vermagic与当前内核一致; -
modinfo是否有sig_id/signer; - Secure Boot 状态(
mokutil --sb-state); - 加载后用
lsmod/dmesg确认 taint; - 卸载用
rmmod,生产用modprobe -r。
未实测与边界
Section titled “未实测与边界”- 未测试 Secure Boot 下拒绝未签名模块(VM 未开 Secure Boot);
- 未测试 MOK 签名/注册流程;
- 未测试
dkms自动重编; - 未测试模块参数与
modprobe.d配置。
- RHEL 内核与模块管理 — 模块基础
- RHEL 10 采用评估 — 内核版本
- 官方:Managing, monitoring, and updating the kernel