美文网首页
内核 lockdown 导致驱动无法加载的解决方法

内核 lockdown 导致驱动无法加载的解决方法

作者: jerryyyq | 来源:发表于2020-05-15 14:46 被阅读0次

由于 linux 内核升级了 lockdown 功能,导致签名验证不过的内核模块在安装时会报:
insmod: ERROR: could not insert module xxxxxxxx.ko: Operation not permitted

查看内核 lockdown 状态

dmesg | grep secureboot
dmesg | grep lockdown

会打印相应的 lockdown 开启显示信息

解决方法用两种:

一 进入 BIOS,关闭 UEFI 的 Secure Boot

BIOS -> Security -> Secure Boot -> Secure Boot 设为 Disabled
BIOS -> Startup -> UEFI/Legacy Boot 设为 Both
BIOS -> Startup -> UEFI/Legacy Boot Priority 设为 Legacy First

二 向内核添加一个自签名证书,然后使用证书对驱动模块进行签名

生成签名证书

  1. 编辑证书请求配置文件
    vim configuration_file.config
[ req ]
default_bits = 4096
distinguished_name = req_distinguished_name
prompt = no
string_mask = utf8only
x509_extensions = myexts

[ req_distinguished_name ]
O = Organization
CN = Organization signing key
emailAddress = yangyuqi@sina.com

[ myexts ]
basicConstraints=critical,CA:FALSE
keyUsage=digitalSignature
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid
  1. 生成密钥和证书
    openssl req -x509 -new -nodes -utf8 -sha256 -days 36500
    -batch -config configuration_file.config -outform DER
    -out public_key.der -keyout private_key.priv

将生成的密钥和证书改名为: signing_key.x509 和 signing_key.priv 放到 Linux kernel 源码根目录。

重新生成 Linux Kernel

使用新编译的 kernel 重启系统后,使用如下命令查看已生效的签名证书:
dmesg | grep MODSIGN
会显示类似如下信息:
[ 2.450021] MODSIGN: Loaded cert 'GenFic: Kernel Signing Key: b923a5f44eae25bbad52c8bf2742e7b7e6fb0c0e'

单独对模块签名

可以将模块与内核一同编译,也可以以后单独编译,单独编译完的模块要用下面的命令对模块进行签名:
/usr/src/linux-headers-5.3.0-51-generic/scripts/sign-file sha512 /home/yangyuqi/ko_sign_key/private_key.priv /home/yangyuqi/ko_sign_key/public_key.der xxxxxxxx.ko

可以使用如下命令查看是否签名已添加到模块:
hexdump -C hello.ko | tail

可以使用如下命令移除签名:
strip --strip-debug hello.ko

参考

相关文章

网友评论

      本文标题:内核 lockdown 导致驱动无法加载的解决方法

      本文链接:https://www.haomeiwen.com/subject/gzecohtx.html