diff options
author | Kees Cook <keescook@chromium.org> | 2014-01-23 18:55:59 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-01-23 19:37:03 -0500 |
commit | 7984754b99b6c89054edc405e9d9d35810a91d36 (patch) | |
tree | 9828ff56e995007158fecee07666f6a5c08f403a | |
parent | 3b96d7db3b6dc99d207bca50037274d22e48dea5 (diff) |
kexec: add sysctl to disable kexec_load
For general-purpose (i.e. distro) kernel builds it makes sense to build
with CONFIG_KEXEC to allow end users to choose what kind of things they
want to do with kexec. However, in the face of trying to lock down a
system with such a kernel, there needs to be a way to disable kexec_load
(much like module loading can be disabled). Without this, it is too easy
for the root user to modify kernel memory even when CONFIG_STRICT_DEVMEM
and modules_disabled are set. With this change, it is still possible to
load an image for use later, then disable kexec_load so the image (or lack
of image) can't be altered.
The intention is for using this in environments where "perfect"
enforcement is hard. Without a verified boot, along with verified
modules, and along with verified kexec, this is trying to give a system a
better chance to defend itself (or at least grow the window of
discoverability) against attack in the face of a privilege escalation.
In my mind, I consider several boot scenarios:
1) Verified boot of read-only verified root fs loading fd-based
verification of kexec images.
2) Secure boot of writable root fs loading signed kexec images.
3) Regular boot loading kexec (e.g. kcrash) image early and locking it.
4) Regular boot with no control of kexec image at all.
1 and 2 don't exist yet, but will soon once the verified kexec series has
landed. 4 is the state of things now. The gap between 2 and 4 is too
large, so this change creates scenario 3, a middle-ground above 4 when 2
and 1 are not possible for a system.
Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Rik van Riel <riel@redhat.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Eric Biederman <ebiederm@xmission.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | Documentation/sysctl/kernel.txt | 15 | ||||
-rw-r--r-- | include/linux/kexec.h | 1 | ||||
-rw-r--r-- | kernel/kexec.c | 3 | ||||
-rw-r--r-- | kernel/sysctl.c | 13 |
4 files changed, 30 insertions, 2 deletions
diff --git a/Documentation/sysctl/kernel.txt b/Documentation/sysctl/kernel.txt index 6d486404200e..ee9a2f983b99 100644 --- a/Documentation/sysctl/kernel.txt +++ b/Documentation/sysctl/kernel.txt | |||
@@ -33,6 +33,7 @@ show up in /proc/sys/kernel: | |||
33 | - domainname | 33 | - domainname |
34 | - hostname | 34 | - hostname |
35 | - hotplug | 35 | - hotplug |
36 | - kexec_load_disabled | ||
36 | - kptr_restrict | 37 | - kptr_restrict |
37 | - kstack_depth_to_print [ X86 only ] | 38 | - kstack_depth_to_print [ X86 only ] |
38 | - l2cr [ PPC only ] | 39 | - l2cr [ PPC only ] |
@@ -287,6 +288,18 @@ Default value is "/sbin/hotplug". | |||
287 | 288 | ||
288 | ============================================================== | 289 | ============================================================== |
289 | 290 | ||
291 | kexec_load_disabled: | ||
292 | |||
293 | A toggle indicating if the kexec_load syscall has been disabled. This | ||
294 | value defaults to 0 (false: kexec_load enabled), but can be set to 1 | ||
295 | (true: kexec_load disabled). Once true, kexec can no longer be used, and | ||
296 | the toggle cannot be set back to false. This allows a kexec image to be | ||
297 | loaded before disabling the syscall, allowing a system to set up (and | ||
298 | later use) an image without it being altered. Generally used together | ||
299 | with the "modules_disabled" sysctl. | ||
300 | |||
301 | ============================================================== | ||
302 | |||
290 | kptr_restrict: | 303 | kptr_restrict: |
291 | 304 | ||
292 | This toggle indicates whether restrictions are placed on | 305 | This toggle indicates whether restrictions are placed on |
@@ -331,7 +344,7 @@ A toggle value indicating if modules are allowed to be loaded | |||
331 | in an otherwise modular kernel. This toggle defaults to off | 344 | in an otherwise modular kernel. This toggle defaults to off |
332 | (0), but can be set true (1). Once true, modules can be | 345 | (0), but can be set true (1). Once true, modules can be |
333 | neither loaded nor unloaded, and the toggle cannot be set back | 346 | neither loaded nor unloaded, and the toggle cannot be set back |
334 | to false. | 347 | to false. Generally used with the "kexec_load_disabled" toggle. |
335 | 348 | ||
336 | ============================================================== | 349 | ============================================================== |
337 | 350 | ||
diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 5fd33dc1fe3a..6d4066cdb5b5 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h | |||
@@ -170,6 +170,7 @@ unsigned long paddr_vmcoreinfo_note(void); | |||
170 | 170 | ||
171 | extern struct kimage *kexec_image; | 171 | extern struct kimage *kexec_image; |
172 | extern struct kimage *kexec_crash_image; | 172 | extern struct kimage *kexec_crash_image; |
173 | extern int kexec_load_disabled; | ||
173 | 174 | ||
174 | #ifndef kexec_flush_icache_page | 175 | #ifndef kexec_flush_icache_page |
175 | #define kexec_flush_icache_page(page) | 176 | #define kexec_flush_icache_page(page) |
diff --git a/kernel/kexec.c b/kernel/kexec.c index 9c970167e402..ac738781d356 100644 --- a/kernel/kexec.c +++ b/kernel/kexec.c | |||
@@ -932,6 +932,7 @@ static int kimage_load_segment(struct kimage *image, | |||
932 | */ | 932 | */ |
933 | struct kimage *kexec_image; | 933 | struct kimage *kexec_image; |
934 | struct kimage *kexec_crash_image; | 934 | struct kimage *kexec_crash_image; |
935 | int kexec_load_disabled; | ||
935 | 936 | ||
936 | static DEFINE_MUTEX(kexec_mutex); | 937 | static DEFINE_MUTEX(kexec_mutex); |
937 | 938 | ||
@@ -942,7 +943,7 @@ SYSCALL_DEFINE4(kexec_load, unsigned long, entry, unsigned long, nr_segments, | |||
942 | int result; | 943 | int result; |
943 | 944 | ||
944 | /* We only trust the superuser with rebooting the system. */ | 945 | /* We only trust the superuser with rebooting the system. */ |
945 | if (!capable(CAP_SYS_BOOT)) | 946 | if (!capable(CAP_SYS_BOOT) || kexec_load_disabled) |
946 | return -EPERM; | 947 | return -EPERM; |
947 | 948 | ||
948 | /* | 949 | /* |
diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 693eac39c202..096db7452cbd 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c | |||
@@ -62,6 +62,7 @@ | |||
62 | #include <linux/capability.h> | 62 | #include <linux/capability.h> |
63 | #include <linux/binfmts.h> | 63 | #include <linux/binfmts.h> |
64 | #include <linux/sched/sysctl.h> | 64 | #include <linux/sched/sysctl.h> |
65 | #include <linux/kexec.h> | ||
65 | 66 | ||
66 | #include <asm/uaccess.h> | 67 | #include <asm/uaccess.h> |
67 | #include <asm/processor.h> | 68 | #include <asm/processor.h> |
@@ -614,6 +615,18 @@ static struct ctl_table kern_table[] = { | |||
614 | .proc_handler = proc_dointvec, | 615 | .proc_handler = proc_dointvec, |
615 | }, | 616 | }, |
616 | #endif | 617 | #endif |
618 | #ifdef CONFIG_KEXEC | ||
619 | { | ||
620 | .procname = "kexec_load_disabled", | ||
621 | .data = &kexec_load_disabled, | ||
622 | .maxlen = sizeof(int), | ||
623 | .mode = 0644, | ||
624 | /* only handle a transition from default "0" to "1" */ | ||
625 | .proc_handler = proc_dointvec_minmax, | ||
626 | .extra1 = &one, | ||
627 | .extra2 = &one, | ||
628 | }, | ||
629 | #endif | ||
617 | #ifdef CONFIG_MODULES | 630 | #ifdef CONFIG_MODULES |
618 | { | 631 | { |
619 | .procname = "modprobe", | 632 | .procname = "modprobe", |