Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lockdown: Enforce module signatures if the kernel is locked down

If the kernel is locked down, require that all modules have valid
signatures that we can verify.

I have adjusted the errors generated:

(1) If there's no signature (ENODATA) or we can't check it (ENOPKG,
ENOKEY), then:

(a) If signatures are enforced then EKEYREJECTED is returned.

(b) If there's no signature or we can't check it, but the kernel is
locked down then EPERM is returned (this is then consistent with
other lockdown cases).

(2) If the signature is unparseable (EBADMSG, EINVAL), the signature fails
the check (EKEYREJECTED) or a system error occurs (eg. ENOMEM), we
return the error we got.

Note that the X.509 code doesn't check for key expiry as the RTC might not
be valid or might not have been transferred to the kernel's clock yet.

[Modified by Matthew Garrett to remove the IMA integration. This will
be replaced with integration with the IMA architecture policy
patchset.]

Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Matthew Garrett <matthewgarrett@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Cc: Jessica Yu <jeyu@kernel.org>
Signed-off-by: James Morris <jmorris@namei.org>

authored by

David Howells and committed by
James Morris
49fcf732 000d388e

+39 -8
+1
include/linux/security.h
··· 103 103 */ 104 104 enum lockdown_reason { 105 105 LOCKDOWN_NONE, 106 + LOCKDOWN_MODULE_SIGNATURE, 106 107 LOCKDOWN_INTEGRITY_MAX, 107 108 LOCKDOWN_CONFIDENTIALITY_MAX, 108 109 };
+5
init/Kconfig
··· 1939 1939 kernel build dependency so that the signing tool can use its crypto 1940 1940 library. 1941 1941 1942 + You should enable this option if you wish to use either 1943 + CONFIG_SECURITY_LOCKDOWN_LSM or lockdown functionality imposed via 1944 + another LSM - otherwise unsigned modules will be loadable regardless 1945 + of the lockdown policy. 1946 + 1942 1947 !!!WARNING!!! If you enable this option, you MUST make sure that the 1943 1948 module DOES NOT get stripped after being signed. This includes the 1944 1949 debuginfo strip done by some packagers (such as rpmbuild) and
+31 -8
kernel/module.c
··· 2753 2753 #ifdef CONFIG_MODULE_SIG 2754 2754 static int module_sig_check(struct load_info *info, int flags) 2755 2755 { 2756 - int err = -ENOKEY; 2756 + int err = -ENODATA; 2757 2757 const unsigned long markerlen = sizeof(MODULE_SIG_STRING) - 1; 2758 + const char *reason; 2758 2759 const void *mod = info->hdr; 2759 2760 2760 2761 /* ··· 2770 2769 err = mod_verify_sig(mod, info); 2771 2770 } 2772 2771 2773 - if (!err) { 2772 + switch (err) { 2773 + case 0: 2774 2774 info->sig_ok = true; 2775 2775 return 0; 2776 + 2777 + /* We don't permit modules to be loaded into trusted kernels 2778 + * without a valid signature on them, but if we're not 2779 + * enforcing, certain errors are non-fatal. 2780 + */ 2781 + case -ENODATA: 2782 + reason = "Loading of unsigned module"; 2783 + goto decide; 2784 + case -ENOPKG: 2785 + reason = "Loading of module with unsupported crypto"; 2786 + goto decide; 2787 + case -ENOKEY: 2788 + reason = "Loading of module with unavailable key"; 2789 + decide: 2790 + if (is_module_sig_enforced()) { 2791 + pr_notice("%s is rejected\n", reason); 2792 + return -EKEYREJECTED; 2793 + } 2794 + 2795 + return security_locked_down(LOCKDOWN_MODULE_SIGNATURE); 2796 + 2797 + /* All other errors are fatal, including nomem, unparseable 2798 + * signatures and signature check failures - even if signatures 2799 + * aren't required. 2800 + */ 2801 + default: 2802 + return err; 2776 2803 } 2777 - 2778 - /* Not having a signature is only an error if we're strict. */ 2779 - if (err == -ENOKEY && !is_module_sig_enforced()) 2780 - err = 0; 2781 - 2782 - return err; 2783 2804 } 2784 2805 #else /* !CONFIG_MODULE_SIG */ 2785 2806 static int module_sig_check(struct load_info *info, int flags)
+1
security/lockdown/Kconfig
··· 1 1 config SECURITY_LOCKDOWN_LSM 2 2 bool "Basic module for enforcing kernel lockdown" 3 3 depends on SECURITY 4 + select MODULE_SIG if MODULES 4 5 help 5 6 Build support for an LSM that enforces a coarse kernel lockdown 6 7 behaviour.
+1
security/lockdown/lockdown.c
··· 18 18 19 19 static char *lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = { 20 20 [LOCKDOWN_NONE] = "none", 21 + [LOCKDOWN_MODULE_SIGNATURE] = "unsigned module loading", 21 22 [LOCKDOWN_INTEGRITY_MAX] = "integrity", 22 23 [LOCKDOWN_CONFIDENTIALITY_MAX] = "confidentiality", 23 24 };