如何在 Ubuntu 16.04 中安装没有内核签名或内核重建的 module.ko 模块?

kar*_*hik 10 drivers 16.04

如何在不签名或不编辑任何内核配置的情况下在 Ubuntu 16.04 中安装任何模块。是否可以?任何帮助将不胜感激。

Pan*_*her 5

您可以禁用安全启动或对内核模块进行签名。

就个人而言,我在 bios 中禁用了安全启动。

请参阅https://wiki.ubuntu.com/SecurityTeam/SecureBoot

或者手动签署内核模块,请参阅

https://www.kernel.org/doc/Documentation/module-signing.txt

      ==============================          KERNEL MODULE SIGNING FACILITY
      ==============================
Run Code Online (Sandbox Code Playgroud)

内容

  • 概述。
  • 配置模块签名。
  • 生成签名密钥。
  • 内核中的公钥。
  • 手动签名模块。
  • 签名模块和剥离。
  • 加载签名模块。
  • 无效签名和未签名模块。
  • 管理/保护私钥。

======== 概述

内核模块签名工具在安装期间对模块进行加密签名,然后在加载模块时检查签名。这允许通过禁止加载未签名的模块或使用无效密钥签名的模块来提高内核安全性。模块签名通过使将恶意模块加载到内核中变得更加困难来提高安全性。模块签名检查由内核完成,因此不需要具有受信任的用户空间位。

该工具使用 X.509 ITU-T 标准证书对所涉及的公钥进行编码。签名本身不以任何工业标准类型编码。该工具目前仅支持 RSA 公钥加密标准(尽管它是可插入的并允许使用其他标准)。可以使用的可能的哈希算法有 SHA-1、SHA-224、SHA-256、SHA-384 和 SHA-512(算法由签名中的数据选择)。

========================== 配置模块签名

通过转到内核配置的“启用可加载模块支持”部分并打开来启用模块签名工具

CONFIG_MODULE_SIG "模块签名验证"

这有许多可用选项:

(1) “要求模块被有效签名” (CONFIG_MODULE_SIG_FORCE)

 This specifies how the kernel should deal with a module that has a
 signature for which the key is not known or a module that is unsigned.

 If this is off (ie. "permissive"), then modules for which the key is not
 available and modules that are unsigned are permitted, but the kernel will
 be marked as being tainted, and the concerned modules will be marked as
 tainted, shown with the character 'E'.

 If this is on (ie. "restrictive"), only modules that have a valid
 signature that can be verified by a public key in the kernel's possession
 will be loaded.  All other modules will generate an error.

 Irrespective of the setting here, if the module has a signature block that
 cannot be parsed, it will be rejected out of hand.
Run Code Online (Sandbox Code Playgroud)

(2)“自动签署所有模块”(CONFIG_MODULE_SIG_ALL)

 If this is on then modules will be automatically signed during the
 modules_install phase of a build.  If this is off, then the modules must
 be signed manually using:
Run Code Online (Sandbox Code Playgroud)

脚本/签名文件

(3) “模块应该用哪种哈希算法签名?”

 This presents a choice of which hash algorithm the installation phase will
 sign the modules with:
Run Code Online (Sandbox Code Playgroud)

CONFIG_MODULE_SIG_SHA1 "使用 SHA-1 签署模块" CONFIG_MODULE_SIG_SHA224 "使用 SHA-224 签署模块" CONFIG_MODULE_SIG_SHA256 "使用 SHA-256 签署模块" CONFIG_MODULE_SIG_SHA384 "使用 SHA-256 签署模块"

 The algorithm selected here will also be built into the kernel (rather
 than being a module) so that modules signed with that algorithm can have
 their signatures checked without causing a dependency loop.
Run Code Online (Sandbox Code Playgroud)

(4) “模块签名密钥的文件名或 PKCS#11 URI” (CONFIG_MODULE_SIG_KEY)

 Setting this option to something other than its default of
 "certs/signing_key.pem" will disable the autogeneration of signing keys
 and allow the kernel modules to be signed with a key of your choosing.
 The string provided should identify a file containing both a private key
 and its corresponding X.509 certificate in PEM form, or — on systems where
 the OpenSSL ENGINE_pkcs11 is functional — a PKCS#11 URI as defined by
 RFC7512. In the latter case, the PKCS#11 URI should reference both a
 certificate and a private key.

 If the PEM file containing the private key is encrypted, or if the
 PKCS#11 token requries a PIN, this can be provided at build time by
 means of the KBUILD_SIGN_PIN variable.
Run Code Online (Sandbox Code Playgroud)

(5) “默认系统密钥环的附加 X.509 密钥” (CONFIG_SYSTEM_TRUSTED_KEYS)

 This option can be set to the filename of a PEM-encoded file containing
 additional certificates which will be included in the system keyring by
 default.
Run Code Online (Sandbox Code Playgroud)

请注意,启用模块签名会将 OpenSSL 开发包的依赖关系添加到执行签名的工具的内核构建过程中。

======================== 生成签名密钥

生成和检查签名需要加密密钥对。私钥用于生成签名,并使用相应的公钥进行检查。私钥只在构建过程中需要,之后可以安全地删除或存储。公钥内置于内核中,以便在加载模块时可以使用它来检查签名。

在正常情况下,当 CONFIG_MODULE_SIG_KEY 与其默认值保持不变时,如果文件中不存在,内核构建将使用 openssl 自动生成一个新的密钥对:

证书/signing_key.pem

在构建 vmlinux 期间(密钥的公共部分需要构建到 vmlinux 中)使用以下参数:

证书/x509.genkey

文件(如果它不存在,也会生成)。

强烈建议您提供自己的 x509.genkey 文件。

最值得注意的是,在 x509.genkey 文件中, req_distinguished_name 部分应该从默认值进行更改:

[ req_distinguished_name ] #O = 未指定的公司 CN = 构建时自动生成的内核密钥 #emailAddress = unspecified.user@unspecified.company

生成的 RSA 密钥大小也可以设置为:

[请求] default_bits = 4096

也可以使用 Linux 内核源代码树根节点中的 x509.genkey 密钥生成配置文件和 openssl 命令手动生成密钥私有/公共文件。以下是生成公钥​​/私钥文件的示例:

openssl req -new -nodes -utf8 -sha256 -days 36500 -batch -x509 \ -config x509.genkey -outform PEM -out kernel_key.pem \ -keyout kernel_key.pem

然后可以在 CONFIG_MODULE_SIG_KEY 选项中指定生成的 kernel_key.pem 文件的完整路径名,并且将使用其中的证书和密钥而不是自动生成的密钥对。

========================== 内核中的公钥

内核包含一个可以被 root 用户查看的公钥环。它们位于名为“.system_keyring”的密钥环中,可以通过以下方式看到:

[root@deneb ~]# cat /proc/keys ... 223c7853 I------ 1 perm 1f030000 0 0 keyring .system_keyring: 1 302d2d52 I------
1 perm 1f010000 0 0 asymmetri Fedora 内核签名密钥:d69a84e6bce3d216b979e9505b3e3ef9a7118079:X509.RSA a7118079 [] ...

除了专门为模块签名生成的公钥之外,还可以在 CONFIG_SYSTEM_TRUSTED_KEYS 配置选项引用的 PEM 编码文件中提供其他可信证书。

此外,体系结构代码可以从硬件存储中获取公钥并将它们添加到其中(例如,来自 UEFI 密钥数据库)。

最后,可以通过执行以下操作添加其他公钥:

keyctl padd 非对称 "" [.system_keyring-ID] <[key-file]

例如:

keyctl 填充不对称“”0x223c7853

但是请注意,如果新密钥的 X.509 包装器由在添加密钥时已驻留在 .system_keyring 中的密钥有效签名,则内核将仅允许将密钥添加到 .system_keyring 。

========================== 手动签名模块

要手动对模块进行签名,请使用 Linux 内核源代码树中提供的脚本/签名文件工具。该脚本需要 4 个参数:

  1. 哈希算法(例如,sha256)
  2. 私钥文件名或 PKCS#11 URI
  3. 公钥文件名
  4. 要签名的内核模块

以下是对内核模块进行签名的示例:

脚本/签名文件 sha512 kernel-signkey.priv \ kernel-signkey.x509 module.ko

使用的散列算法不必与配置的匹配,但如果不匹配,您应该确保散列算法要么内置于内核中,要么可以在不需要自身的情况下加载。

如果私钥需要密码或 PIN,则可以在 $KBUILD_SIGN_PIN 环境变量中提供。

============================ 签名模块和剥离

签名模块具有简单地附加在末尾的数字签名。字符串“~模块签名附加~”。在模块文件的末尾确认签名存在,但不确认签名有效!

签名模块是脆弱的,因为签名在定义的 ELF 容器之外。因此,一旦计算并附加了签名,它们就不会被剥离。请注意,整个模块是已签名的有效负载,包括签名时存在的任何和所有调试信息。

====================== 加载签名模块

模块使用 insmod、modprobe、init_module() 或 finit_module() 加载,与未签名模块完全相同,因为在用户空间中不进行任何处理。签名检查全部在内核中完成。

========================================== 无效签名和未签名模块

如果启用了 CONFIG_MODULE_SIG_FORCE 或在内核命令行上提供了 module.sig_enforce=1,则内核将仅加载具有公钥的有效签名模块。否则,它也会加载未签名的模块。内核有密钥但证明签名不匹配的任何模块都不允许加载。

任何具有不可解析签名的模块都将被拒绝。

======================================== 管理/保护私钥

由于私钥用于对模块进行签名,病毒和恶意软件可以使用私钥对模块进行签名并危及操作系统。私钥必须被销毁或移动到安全位置,而不是保存在内核源代码树的根节点中。