[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221121072947.836672-1-coxu@redhat.com>
Date: Mon, 21 Nov 2022 15:29:47 +0800
From: Coiby Xu <coxu@...hat.com>
To: kexec@...ts.infradead.org
Cc: Matthew Garrett <mjg59@...f.ucam.org>, Jiri Bohac <jbohac@...e.cz>,
David Howells <dhowells@...hat.com>,
linux-integrity@...r.kernel.org,
Eric Biederman <ebiederm@...ssion.com>,
James Morris <jmorris@...ei.org>,
Matthew Garrett <mjg59@...gle.com>,
linux-kernel@...r.kernel.org (open list)
Subject: [PATCH] lockdown: kexec_file: prevent unsigned kernel image when KEXEC_SIG not enabled
A kernel builder may not enable KEXEC_SIG and some architectures like
ppc64 simply don't have KEXEC_SIG. In these cases, unless both
IMA_ARCH_POLICY and secure boot also enabled, lockdown doesn't prevent
unsigned kernel image from being kexec'ed via the kexec_file_load
syscall whereas it could prevent one via the kexec_load syscall. Mandate
signature verification for those cases.
Fixes: 155bdd30af17 ("kexec_file: Restrict at runtime if the kernel is locked down")
Cc: Matthew Garrett <mjg59@...f.ucam.org>
Cc: Jiri Bohac <jbohac@...e.cz>
Cc: David Howells <dhowells@...hat.com>
Cc: kexec@...ts.infradead.org
Cc: linux-integrity@...r.kernel.org
Signed-off-by: Coiby Xu <coxu@...hat.com>
---
kernel/kexec_file.c | 31 +++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
index 45637511e0de..04d56b6e6459 100644
--- a/kernel/kexec_file.c
+++ b/kernel/kexec_file.c
@@ -125,6 +125,20 @@ void kimage_file_post_load_cleanup(struct kimage *image)
image->image_loader_data = NULL;
}
+static int mandate_signatute_verification(void)
+{
+ /*
+ * If IMA is guaranteed to appraise a signature on the kexec
+ * image, permit it even if the kernel is otherwise locked
+ * down.
+ */
+ if (!ima_appraise_signature(READING_KEXEC_IMAGE) &&
+ security_locked_down(LOCKDOWN_KEXEC))
+ return -EPERM;
+
+ return 0;
+}
+
#ifdef CONFIG_KEXEC_SIG
#ifdef CONFIG_SIGNED_PE_FILE_VERIFICATION
int kexec_kernel_verify_pe_sig(const char *kernel, unsigned long kernel_len)
@@ -168,14 +182,9 @@ kimage_validate_signature(struct kimage *image)
return ret;
}
- /*
- * If IMA is guaranteed to appraise a signature on the kexec
- * image, permit it even if the kernel is otherwise locked
- * down.
- */
- if (!ima_appraise_signature(READING_KEXEC_IMAGE) &&
- security_locked_down(LOCKDOWN_KEXEC))
- return -EPERM;
+ ret = mandate_signatute_verification();
+ if (ret)
+ return ret;
pr_debug("kernel signature verification failed (%d).\n", ret);
}
@@ -211,10 +220,12 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd,
#ifdef CONFIG_KEXEC_SIG
ret = kimage_validate_signature(image);
-
+#else
+ ret = mandate_signatute_verification();
+#endif
if (ret)
goto out;
-#endif
+
/* It is possible that there no initramfs is being loaded */
if (!(flags & KEXEC_FILE_NO_INITRAMFS)) {
ret = kernel_read_file_from_fd(initrd_fd, 0, &image->initrd_buf,
--
2.38.1
Powered by blists - more mailing lists