3 Signing Kernel Images and Kernel Modules for Use With Secure Boot
This chapter provides instructions on signing kernel modules for Secure Boot.
Attention:
Oracle doesn't support any modules that are built from source directly outside of Oracle's official release mechanisms. For help with these modules, contact the hardware vendor.
A system in Secure Boot mode only loads boot loaders and kernels that have been signed by Oracle. However, you might need to build and install a third-party module to enable specific hardware on a deployed system. If you still require UEFI Secure Boot, the module must be signed with a key that can be validated against a certificate within the UEFI Secure Boot key database or within the MOK database so that the module is recognized at boot.
Note:
If you're running UEK R6, UEK R6U1, or UEK R6U2, the key that's used to sign the module must be compiled into the kernel and then the kernel must be signed again. Note also that the kernel signing key must be added to the either the UEFI or MOK database. As of UEK R6U3, you can load external modules under Secure Boot if the signing key is already enrolled in the UEFI or MOK databases.
Important:
Using the MOK utility on a server depends on server firmware implementation and configuration. Check that the server provides this capability before manually updating signature keys used for UEFI Secure Boot. If you're unsure, don't follow the instructions provided here.
Adding certificates to the MOK database by using the MOK utility requires that you have physical access to the system so that you can complete the enrollment request after the Shim is loaded by UEFI. Don't follow the instructions in this document if you have no physical access to the system.
Because of differences in kernel releases, instructions on how to sign modules differ
depending on the kernel version on the system. In particular, the key signature type within
the module signature has changed from X.509 to PKCS#7. Therefore, although the process to sign
the module by using the kernel-provided sign-file
utility is still used,
you might be required to use a utility more appropriate to the specific kernel for which a
module is being signed.
More importantly, UEK R6 kernels earlier than UEK R6U3 don't offer the same level of trust for the keys that are available for UEFI or the MOK database. Thus, for systems running UEK R6, UEK R6U1, or UEK R6U2, a different set of procedures exists for signing kernel images and modules for use with Secure Boot. See Setting Kernel Module Certificate Trust for UEK R6
Requirements for Signing Kernel Images and Kernel Modules
Before you can sign a module, you must install several required packages, including the kernel source for the kernel where the module is loaded. You also require a signing certificate for a key pair that you have created for this purpose.
Signing kernel images and kernel modules have the following requirements:
Installing Required Packages
You need only a standard minimal installation of the latest Oracle Linux 8 release for this procedure. The steps assume that the system is using UEK as the operating environment.
Generating a Signing Certificate
-
Create a configuration file that OpenSSL can use to obtain default values when generating certificates.
As best practice, create the file in
/etc/ssl/x509.conf
with the rest of the OpenSSL configuration. The following is an example of the configuration file:[ req ] default_bits = 4096 distinguished_name = req_distinguished_name prompt = no string_mask = utf8only x509_extensions = extensions [ req_distinguished_name ] O = Module Signing Example CN = Module Signing Example Key emailAddress = first.last@example.com [ extensions ] basicConstraints=critical,CA:TRUE keyUsage=digitalSignature extendedKeyUsage = codeSigning subjectKeyIdentifier=hash authorityKeyIdentifier=keyid:always
-
Generate a new key pair from the configuration file.
For example, the following command creates a signing certificate that's valid for 10 years (3,650 days).
sudo openssl req -x509 -new -nodes -utf8 -sha512 -days 3650 -batch -config /etc/ssl/x509.conf -outform DER -out /etc/ssl/certs/pubkey.der -keyout /etc/ssl/certs/priv.key
Ensure that the keys are adequately protected.
-
Export the certificate in PEM format.
Enter the following command to export the certificate as a
.pem
file:sudo openssl x509 -inform DER -in /etc/ssl/certs/pubkey.der -out /etc/ssl/certs/pubkey.pem
Signing the Kernel for Secure Boot
UEFI Secure Boot requires that kernels are signed with a trusted certificate to prevent attackers from installing and running unauthorized OSs.
Oracle signs kernel releases that are provided through official software channels to verify
their origin and integrity. For a custom kernel to perform the boot
or
kexec
operations, you must sign the kernel image by using the signing
certificate that you created and confirm that you trust kernel images that are signed with
that certificate.
Signing the kernel for Secure Boot involves the following tasks:
Configuring an NSS Database
The NSS database stores complete sets of keys that the tool for signing kernels accesses to obtain the kernel signing key.
Signing the Kernel Image
In this task, you use the pesign
utility to sign the kernel with a new signature
using the signing key in the NSS database.
Updating the MOK Database
Because the key that you created isn't included in the UEFI Secure Boot Key Database, you must enroll it into the MOK database in the Shim.
Note:
If you only want to let a specific kernel or kernel module load under Secure Boot, and you don't want to enroll a certificate, you can enroll the hash of the binary instead. This limits authorizations to the specific binary, rather than all components signed by a particular certificate. This process is described in Enrolling a Kernel Hash in the MOK Database.
Enrolling a Kernel Hash in the MOK Database
Describes how to enroll a specific kernel's hash into the MOK database.
If you can't or don't want to enroll a signing certificate as described in Updating the MOK Database, you can enroll a specific kernel’s hash into the MOK database. This lets you load that particular kernel under Secure Boot, even without a certificate.
Signing the Kernel Module for Secure Boot
Note:
If you're running UEK R6, UEK R6U1, or UEK R6U2, go instead to Setting Kernel Module Certificate Trust for UEK R6. That section contains extra tasks to complete Secure Boot setup for these UEK R6 kernels.
UEFI Secure Boot requires that kernel modules are signed with a trusted certificate to prevent attackers from installing and running unauthorized OS and malicious drivers.
Oracle signs kernel releases that are provided through official software channels to verify their origin and integrity. However, to install other drivers, you must create signing certificates for them, sign the relevant kernel modules, and confirm that you trust the kernel modules that are signed with that certificate.
The secure boot implementation in UEK R6U3 is updated to trust modules signed using platform certificates that are available in the UEFI and MOK databases. Thus, beginning with UEK R6U3, the key for signing the module itself is enrolled into the database.
For UEK versions except UEK R6, UEK R6U1, and UEK R6U2, signing the kernel module involves the following tasks:
Signing the Kernel Module
The sign-file
utility ensures that the module is signed correctly for the
kernel. This utility is provided within the kernel source.
Updating the MOK Database with the Kernel Module Certificate
Because the key that you created isn't included in the UEFI Secure Boot Key Database, you must enroll it into the MOK database in the Shim.
Note:
If you only want to a specific kernel or kernel module to run under Secure Boot, and you don't want to enroll a certificate, you can enroll the hash of the binary as described in Enrolling a Kernel Hash in the MOK Database. This limits authorizations to the specific binary, rather than all components signed by a certificate.
Setting Kernel Module Certificate Trust for UEK R6
The information in this section applies to kernel modules with any UEK R6 kernels before UEK R6U3, namely:
-
UEK R6
-
UEK R6U1
-
UEK R6U2
With these UEK R6 kernels, after a module is signed, the key that was used to sign it must be inserted into the compiled kernel image. UEK R6 only trusts modules that are signed with keys that are listed in the kernel built-in, trusted keyring. Thus, the updated kernel image must be signed again. Further, the customer owned certificate that's used to sign the kernel must then be added to the UEFI or MOK database. In this manner, the kernel image becomes trusted and can boot in Secure Boot mode.
Setting the kernel module certificate trust for the listed kernels involves the following tasks:
-
Signing the Kernel Module
This task is the same as the first task listed under Signing the Kernel Module for Secure Boot.
-
Updating the MOK database
This task is the same as the second task listed under Signing the Kernel Module for Secure Boot.
Signing the Kernel Module
The sign-file
utility ensures that the module is signed correctly for the
kernel. This utility is provided within the kernel source.
Signing the Kernel Image
In this task, you use the pesign
utility to sign the kernel with a new signature
using the signing key in the NSS database.
Updating the MOK Database
Because the key that you created isn't included in the UEFI Secure Boot Key Database, you must enroll it into the MOK database in the Shim.
Note:
If you only want to let a specific kernel or kernel module load under Secure Boot, and you don't want to enroll a certificate, you can enroll the hash of the binary instead. This limits authorizations to the specific binary, rather than all components signed by a particular certificate. This process is described in Enrolling a Kernel Hash in the MOK Database.
Validating That a Key Is Trusted
After the system is booted, you can validate whether a key is included in the appropriate kernel keyring. Validation depends on the kernel version that you're running. Also, the keyring name that you need to check varies, as the implementation has changed across kernel versions.
If the key that was generated for signing custom modules is listed within the correct keyring, you can load modules that are signed with this key while in Secure Boot mode.
UEK R7
The following describes how to validate a key in UEK R7.
The UEK R7 release provides the
.machine
keyring to enhance security. Keys in the
.machine
keyring are trusted by the Oracle Linux kernel. At system boot,
all MOK keys are loaded into the .machine
keyring.
The .machine
keyring functions similarly to the
.builtin_trusted_keys
keyring and is linked to the
.secondary_trusted_keys
keyring. This linkage ensures that the
.machine
keyring is consulted whenever the kernel checks the
.secondary_trusted_keys
keyring to validate a signed kernel module.
In essence, when validating a signed kernel module, the kernel use the keys in the
.secondary_trusted_keys
keyring, which now also references the trusted
keys in the .machine
keyring, ensuring a comprehensive validation process.
This is shown in the following example:
sudo keyctl show %:.secondary_trusted_keys
Keyring
772746105 ---lswrv 0 0 keyring: .secondary_trusted_keys
252396885 ---lswrv 0 0 \_ keyring: .builtin_trusted_keys
660166481 ---lswrv 0 0 | \_ asymmetric: Oracle CA Server: 702a35b0d12005e5010c0614f7b8abf7c5bd5f73
86702374 ---lswrv 0 0 | \_ asymmetric: Oracle IMA signing CA: a2f28976a05984028f7d1a4904ae14e8e468e551
247354640 ---lswrv 0 0 | \_ asymmetric: Oracle America, Inc.: Ksplice Kernel Module Signing Key: 09010ebef5545fa7c54b626ef518e077b5b1ee4c
264616160 ---lswrv 0 0 | \_ asymmetric: Oracle Linux Kernel Module Signing Key: 2bb352412969a3653f0eb6021763408ebb9bb5ab
772320403 ---lswrv 0 0 \_ keyring: .machine
450491670 ---lswrv 0 0 \_ asymmetric: Oracle America, Inc.: 7c552922286d66bcb33c53d7ee0f1cd716ecdc63
100307441 ---lswrv 0 0 \_ asymmetric: Oracle America, Inc.: 39bff3f0f578f26e527321cafda2a9cdbd71143c
688922247 ---lswrv 0 0 \_ asymmetric: Oracle America, Inc.: 4ff35c3e09ce586fa776d56468d86b022af272f1
UEK R6U3 and Later UEK R6 Updates
The following describes how to validate a key for UEK R6U3 and later UEK R6 updates.
Keys within both the builtin_trusted_keys
keyring and the
platform
keyring are trusted for both module signing and for the
kexec
tools. You can follow the standard procedure to sign a module and add
it to the MOK database for the key to appear in the platform
keyring. The
keyring is then automatically trusted.
Because a key can be loaded into the builtin_trusted_keys
keyring, check
both keyrings for the module signing key, for example:
sudo keyctl show %:.builtin_trusted_keys
Keyring
892034081 ---lswrv 0 0 keyring: .builtin_trusted_keys
367808024 ---lswrv 0 0 \_ asymmetric: Oracle CA Server: fbcd3d4d950c6b2b0e01f0a146c5a4e3855ae704
230958440 ---lswrv 0 0 \_ asymmetric: Module Signing Example Key: a43b4e638874b0656db2bc26216f56c0ac39f72b
408597579 ---lswrv 0 0 \_ asymmetric: Oracle America, Inc.: Ksplice Kernel Module Signing Key: 09010ebef5545fa7c54b626ef518e077b5b1ee4c
839574974 ---lswrv 0 0 \_ asymmetric: Oracle Linux Kernel Module Signing Key: 2bb352412969a3653f0eb6021763408ebb9bb5ab
sudo keyctl show %:.platform
Keyring
705628740 ---lswrv 0 0 keyring: .platform
89698906 ---lswrv 0 0 \_ asymmetric: Microsoft Corporation UEFI CA 2011: 13adbf4309bd82709c8cd54f316ed522988a1bd4
497244381 ---lswrv 0 0 \_ asymmetric: Oracle America, Inc.: d6ee3a06a222bf4244b8986a531046e59c14eeef
710039804 ---lswrv 0 0 \_ asymmetric: Oracle America, Inc.: c65d1d746ae4cb127762e1dbd7ade48215703c5c
730271863 ---lswrv 0 0 \_ asymmetric: Oracle America Inc.: 2e7c1720d1c5df5254cc93d6decaa75e49620cf8
535985802 ---lswrv 0 0 \_ asymmetric: Oracle America, Inc.: 795c5945e7cb2b6773b7797571413e3695062514
607819007 ---lswrv 0 0 \_ asymmetric: Oracle America, Inc.: f9aec43f7480c408d681db3d6f19f54d6e396ff4
99739320 ---lswrv 0 0 \_ asymmetric: Oracle America, Inc.: 430c85cb8b531c3d7b8c44adfafc2e5d49bb89d4
231916335 ---lswrv 0 0 \_ asymmetric: Microsoft Windows Production PCA 2011: a92902398e16c49778cd90f99e4f9ae17c55af53
866576656 ---lswrv 0 0 \_ asymmetric: Oracle Linux Test Certificate: d30dffa37bec20ecfb1d3caee53cd746282e8cad
230958440 ---lswrv 0 0 \_ asymmetric: Module Signing Example Key: a43b4e638874b0656db2bc26216f56c0ac39f72b
UEK R6U3 and Earlier UEK R6 Updates
The following describes how to validate a key for UEK R6 releases before UEK R6U3.
For UEK R6 releases before UEK R6U3, only those keys that are listed in the kernel
builtin_trusted_keys
keyring are trusted for module signing. For this
reason, module signing keys are added to the kernel image as part of the process for signing
modules.
To check whether the module signing key that you created is contained within the keyring, enter the following command to list the keyring contents:
sudo keyctl show %:.builtin_trusted_keys
Keyring
892034081 ---lswrv 0 0 keyring: .builtin_trusted_keys
367808024 ---lswrv 0 0 \_ asymmetric: Oracle CA Server: fbcd3d4d950c6b2b0e01f0a146c5a4e3855ae704
230958440 ---lswrv 0 0 \_ asymmetric: Module Signing Example Key: a43b4e638874b0656db2bc26216f56c0ac39f72b
408597579 ---lswrv 0 0 \_ asymmetric: Oracle America, Inc.: Ksplice Kernel Module Signing Key: 09010ebef5545fa7c54b626ef518e077b5b1ee4c
839574974 ---lswrv 0 0 \_ asymmetric: Oracle Linux Kernel Module Signing Key: 2bb352412969a3653f0eb6021763408ebb9bb5ab
RHCK
The following describes how to validate a key for Red Hat Compatible Kernels (RHCK).
Keys within both the builtin_trusted_keys
keyring and the
platform
keyring are trusted for both module signing and for the
kexec
tools. You can follow the standard procedure to sign a module and add
it to the MOK database for the key to appear in the platform
keyring. The
keyring is then automatically trusted.
Because a key can be loaded into the builtin_trusted_keys
keyring, check
both keyrings for the module signing key, for example:
sudo keyctl show %:.builtin_trusted_keys
Keyring
441234704 ---lswrv 0 0 keyring: .builtin_trusted_keys
798307349 ---lswrv 0 0 \_ asymmetric: Oracle CA Server: 32a7ceb6c56614c69b4729b455254bfaf09569a4
277992501 ---lswrv 0 0 \_ asymmetric: Oracle Linux RHCK Module Signing Key: dd995b155c19b3a7c3ef7707b969e25f9639666e
1000618915 ---lswrv 0 0 \_ asymmetric: Red Hat Enterprise Linux kpatch signing key: 4d38fd864ebe18c5f0b72e3852e2014c3a676fc8
199403819 ---lswrv 0 0 \_ asymmetric: Red Hat Enterprise Linux Driver Update Program (key 3): bf57f3e87362bc7229d9f465321773dfd1f77a80
sudo keyctl show %:.platform
Keyring
705628740 ---lswrv 0 0 keyring: .platform
89698906 ---lswrv 0 0 \_ asymmetric: Microsoft Corporation UEFI CA 2011: 13adbf4309bd82709c8cd54f316ed522988a1bd4
497244381 ---lswrv 0 0 \_ asymmetric: Oracle America, Inc.: d6ee3a06a222bf4244b8986a531046e59c14eeef
710039804 ---lswrv 0 0 \_ asymmetric: Oracle America, Inc.: c65d1d746ae4cb127762e1dbd7ade48215703c5c
730271863 ---lswrv 0 0 \_ asymmetric: Oracle America Inc.: 2e7c1720d1c5df5254cc93d6decaa75e49620cf8
535985802 ---lswrv 0 0 \_ asymmetric: Oracle America, Inc.: 795c5945e7cb2b6773b7797571413e3695062514
607819007 ---lswrv 0 0 \_ asymmetric: Oracle America, Inc.: f9aec43f7480c408d681db3d6f19f54d6e396ff4
99739320 ---lswrv 0 0 \_ asymmetric: Oracle America, Inc.: 430c85cb8b531c3d7b8c44adfafc2e5d49bb89d4
231916335 ---lswrv 0 0 \_ asymmetric: Microsoft Windows Production PCA 2011: a92902398e16c49778cd90f99e4f9ae17c55af53
866576656 ---lswrv 0 0 \_ asymmetric: Oracle Linux Test Certificate: d30dffa37bec20ecfb1d3caee53cd746282e8cad
230958440 ---lswrv 0 0 \_ asymmetric: Module Signing Example Key: a43b4e638874b0656db2bc26216f56c0ac39f72b