aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/module.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-09-28 11:14:15 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-09-28 11:14:15 -0400
commitaefcf2f4b58155d27340ba5f9ddbe9513da8286d (patch)
treea8ae994ca71b2e43e3075c796165e5ed62e28e42 /kernel/module.c
parentf1f2f614d535564992f32e720739cb53cf03489f (diff)
parent45893a0abee6b5fd52994a3a1095735aeaec472b (diff)
Merge branch 'next-lockdown' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security
Pull kernel lockdown mode from James Morris: "This is the latest iteration of the kernel lockdown patchset, from Matthew Garrett, David Howells and others. From the original description: This patchset introduces an optional kernel lockdown feature, intended to strengthen the boundary between UID 0 and the kernel. When enabled, various pieces of kernel functionality are restricted. Applications that rely on low-level access to either hardware or the kernel may cease working as a result - therefore this should not be enabled without appropriate evaluation beforehand. The majority of mainstream distributions have been carrying variants of this patchset for many years now, so there's value in providing a doesn't meet every distribution requirement, but gets us much closer to not requiring external patches. There are two major changes since this was last proposed for mainline: - Separating lockdown from EFI secure boot. Background discussion is covered here: https://lwn.net/Articles/751061/ - Implementation as an LSM, with a default stackable lockdown LSM module. This allows the lockdown feature to be policy-driven, rather than encoding an implicit policy within the mechanism. The new locked_down LSM hook is provided to allow LSMs to make a policy decision around whether kernel functionality that would allow tampering with or examining the runtime state of the kernel should be permitted. The included lockdown LSM provides an implementation with a simple policy intended for general purpose use. This policy provides a coarse level of granularity, controllable via the kernel command line: lockdown={integrity|confidentiality} Enable the kernel lockdown feature. If set to integrity, kernel features that allow userland to modify the running kernel are disabled. If set to confidentiality, kernel features that allow userland to extract confidential information from the kernel are also disabled. This may also be controlled via /sys/kernel/security/lockdown and overriden by kernel configuration. New or existing LSMs may implement finer-grained controls of the lockdown features. Refer to the lockdown_reason documentation in include/linux/security.h for details. The lockdown feature has had signficant design feedback and review across many subsystems. This code has been in linux-next for some weeks, with a few fixes applied along the way. Stephen Rothwell noted that commit 9d1f8be5cf42 ("bpf: Restrict bpf when kernel lockdown is in confidentiality mode") is missing a Signed-off-by from its author. Matthew responded that he is providing this under category (c) of the DCO" * 'next-lockdown' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (31 commits) kexec: Fix file verification on S390 security: constify some arrays in lockdown LSM lockdown: Print current->comm in restriction messages efi: Restrict efivar_ssdt_load when the kernel is locked down tracefs: Restrict tracefs when the kernel is locked down debugfs: Restrict debugfs when the kernel is locked down kexec: Allow kexec_file() with appropriate IMA policy when locked down lockdown: Lock down perf when in confidentiality mode bpf: Restrict bpf when kernel lockdown is in confidentiality mode lockdown: Lock down tracing and perf kprobes when in confidentiality mode lockdown: Lock down /proc/kcore x86/mmiotrace: Lock down the testmmiotrace module lockdown: Lock down module params that specify hardware parameters (eg. ioport) lockdown: Lock down TIOCSSERIAL lockdown: Prohibit PCMCIA CIS storage when the kernel is locked down acpi: Disable ACPI table override if the kernel is locked down acpi: Ignore acpi_rsdp kernel param when the kernel has been locked down ACPI: Limit access to custom_method when the kernel is locked down x86/msr: Restrict MSR access when the kernel is locked down x86: Lock down IO port access when the kernel is locked down ...
Diffstat (limited to 'kernel/module.c')
-rw-r--r--kernel/module.c37
1 files changed, 30 insertions, 7 deletions
diff --git a/kernel/module.c b/kernel/module.c
index edbe42755a27..ff2d7359a418 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2839,8 +2839,9 @@ static inline void kmemleak_load_module(const struct module *mod,
2839#ifdef CONFIG_MODULE_SIG 2839#ifdef CONFIG_MODULE_SIG
2840static int module_sig_check(struct load_info *info, int flags) 2840static int module_sig_check(struct load_info *info, int flags)
2841{ 2841{
2842 int err = -ENOKEY; 2842 int err = -ENODATA;
2843 const unsigned long markerlen = sizeof(MODULE_SIG_STRING) - 1; 2843 const unsigned long markerlen = sizeof(MODULE_SIG_STRING) - 1;
2844 const char *reason;
2844 const void *mod = info->hdr; 2845 const void *mod = info->hdr;
2845 2846
2846 /* 2847 /*
@@ -2855,16 +2856,38 @@ static int module_sig_check(struct load_info *info, int flags)
2855 err = mod_verify_sig(mod, info); 2856 err = mod_verify_sig(mod, info);
2856 } 2857 }
2857 2858
2858 if (!err) { 2859 switch (err) {
2860 case 0:
2859 info->sig_ok = true; 2861 info->sig_ok = true;
2860 return 0; 2862 return 0;
2861 }
2862 2863
2863 /* Not having a signature is only an error if we're strict. */ 2864 /* We don't permit modules to be loaded into trusted kernels
2864 if (err == -ENOKEY && !is_module_sig_enforced()) 2865 * without a valid signature on them, but if we're not
2865 err = 0; 2866 * enforcing, certain errors are non-fatal.
2867 */
2868 case -ENODATA:
2869 reason = "Loading of unsigned module";
2870 goto decide;
2871 case -ENOPKG:
2872 reason = "Loading of module with unsupported crypto";
2873 goto decide;
2874 case -ENOKEY:
2875 reason = "Loading of module with unavailable key";
2876 decide:
2877 if (is_module_sig_enforced()) {
2878 pr_notice("%s is rejected\n", reason);
2879 return -EKEYREJECTED;
2880 }
2866 2881
2867 return err; 2882 return security_locked_down(LOCKDOWN_MODULE_SIGNATURE);
2883
2884 /* All other errors are fatal, including nomem, unparseable
2885 * signatures and signature check failures - even if signatures
2886 * aren't required.
2887 */
2888 default:
2889 return err;
2890 }
2868} 2891}
2869#else /* !CONFIG_MODULE_SIG */ 2892#else /* !CONFIG_MODULE_SIG */
2870static int module_sig_check(struct load_info *info, int flags) 2893static int module_sig_check(struct load_info *info, int flags)