由于 linux 內(nèi)核升級了 lockdown 功能,導致簽名驗證不過的內(nèi)核模塊在安裝時會報:
insmod: ERROR: could not insert module xxxxxxxx.ko: Operation not permitted
查看內(nèi)核 lockdown 狀態(tài)
dmesg | grep secureboot
dmesg | grep lockdown
會打印相應的 lockdown 開啟顯示信息
解決方法用兩種:
一 進入 BIOS,關(guān)閉 UEFI 的 Secure Boot
BIOS -> Security -> Secure Boot -> Secure Boot 設為 Disabled
BIOS -> Startup -> UEFI/Legacy Boot 設為 Both
BIOS -> Startup -> UEFI/Legacy Boot Priority 設為 Legacy First
二 向內(nèi)核添加一個自簽名證書,然后使用證書對驅(qū)動模塊進行簽名
生成簽名證書
- 編輯證書請求配置文件
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
- 生成密鑰和證書
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 重啟系統(tǒng)后,使用如下命令查看已生效的簽名證書:
dmesg | grep MODSIGN
會顯示類似如下信息:
[ 2.450021] MODSIGN: Loaded cert 'GenFic: Kernel Signing Key: b923a5f44eae25bbad52c8bf2742e7b7e6fb0c0e'
單獨對模塊簽名
可以將模塊與內(nèi)核一同編譯,也可以以后單獨編譯,單獨編譯完的模塊要用下面的命令對模塊進行簽名:
/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
參考
- Linux 模塊(ko)簽名 https://blog.csdn.net/seek_0380/article/details/60872738
- 給Linux模塊簽名 http://www.itdecent.cn/p/215eee5dbb05