[PATCH 08/12] kexec: Disable loading of unverified images
From: Matthew Garrett
Date: Fri Mar 13 2015 - 17:40:10 EST
kexec permits the loading and execution of arbitrary code in ring 0, which
permits the modification of the running kernel. Restrict it such that only
images which have been verified may be loaded when trusted_kernel is true.
Signed-off-by: Matthew Garrett <matthew.garrett@xxxxxxxxxx>
---
kernel/kexec.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/kernel/kexec.c b/kernel/kexec.c
index 38c25b1..463b369 100644
--- a/kernel/kexec.c
+++ b/kernel/kexec.c
@@ -36,6 +36,7 @@
#include <linux/syscore_ops.h>
#include <linux/compiler.h>
#include <linux/hugetlb.h>
+#include <linux/security.h>
#include <asm/page.h>
#include <asm/uaccess.h>
@@ -1247,6 +1248,14 @@ SYSCALL_DEFINE4(kexec_load, unsigned long, entry, unsigned long, nr_segments,
return -EPERM;
/*
+ * This codepath has no mechanism for verifying that the loaded image
+ * is trustworthy, so forbid using kexec_load() if the kernel is
+ * trusted
+ */
+ if (get_trusted_kernel())
+ return -EPERM;
+
+ /*
* Verify we have a legal set of flags
* This leaves us room for future extensions.
*/
@@ -1388,6 +1397,15 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd,
int ret = 0, i;
struct kimage **dest_image, *image;
+#ifndef CONFIG_KEXEC_VERIFY_SIG
+ /*
+ * Don't permit images to be loaded into trusted kernels if we're not
+ * going to verify the signature on them
+ */
+ if (get_trusted_kernel())
+ return -EPERM;
+#endif
+
/* We only trust the superuser with rebooting the system. */
if (!capable(CAP_SYS_BOOT) || kexec_load_disabled)
return -EPERM;
--
2.1.0
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/