Skip to content
Search RHEL

This page uses Chinese content. Search opens the Chinese documentation.

    Browse this documentation

    RHEL 10 编译内核模块:vermagic、签名与 taint

    This content is not available in your language yet.

    RHEL 10 默认只信任 Red Hat 签名的内核模块。自己编译的 out-of-tree 模块能加载(Secure Boot 关闭时),但会 taint 内核;modinfo 里没有 sig_id/signer 就是最直接的信号。

    在 PVE 390 rhel10-lab(RHEL 10.2)执行:

    Terminal window
    sudo dnf -y install gcc make kernel-devel-$(uname -r)
    uname -r
    # 6.12.0-211.73.1.el10_2.x86_64

    E3 记录: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.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.o
    Terminal window
    cd /tmp/hello-mod
    make -C /lib/modules/$(uname -r)/build M=$PWD modules

    产物 hello.ko;vermagic 必须与当前内核一致,否则 insmod 报 “invalid module format”。

    $ modinfo /tmp/hello-mod/hello.ko
    filename: /tmp/hello-mod/hello.ko
    version: 0.1
    license: GPL
    rhelversion: 10.2
    srcversion: 3FD3E81CE9B4B0E7CF0BB8A
    vermagic: 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...。

    Terminal window
    sudo insmod /tmp/hello-mod/hello.ko
    lsmod | grep hello
    # hello 12288 0
    sudo 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 表示没被使用。

    Terminal window
    sudo rmmod hello
    lsmod | grep hello || echo no-hello

    普通用户直接 dmesg 会报 Operation not permitted(RHEL 10 限制 CAP_SYSLOG);看内核日志用 sudo dmesg/journalctl -k。

    本次 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。
    • 未测试 Secure Boot 下拒绝未签名模块(VM 未开 Secure Boot);
    • 未测试 MOK 签名/注册流程;
    • 未测试 dkms 自动重编;
    • 未测试模块参数与 modprobe.d 配置。