From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757389AbbCMVkH (ORCPT ); Fri, 13 Mar 2015 17:40:07 -0400 Received: from cavan.codon.org.uk ([93.93.128.6]:32774 "EHLO cavan.codon.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754227AbbCMVj6 (ORCPT ); Fri, 13 Mar 2015 17:39:58 -0400 From: Matthew Garrett To: linux-security-module@vger.kernel.org Cc: james.l.morris@oracle.com, serge@hallyn.com, linux-kernel@vger.kernel.org, keescook@chromium.org, hpa@zytor.com, gnomes@lxorguk.ukuu.org.uk, Matthew Garrett Date: Fri, 13 Mar 2015 11:38:24 -1000 Message-Id: <1426282708-21485-9-git-send-email-matthew.garrett@nebula.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1426282708-21485-1-git-send-email-matthew.garrett@nebula.com> References: <1426282708-21485-1-git-send-email-matthew.garrett@nebula.com> X-SA-Do-Not-Run: Yes X-SA-Exim-Connect-IP: 72.253.89.114 X-SA-Exim-Mail-From: matthew.garrett@nebula.com X-Spam-ASN: Subject: [PATCH 08/12] kexec: Disable loading of unverified images X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:54:46 +0000) X-SA-Exim-Scanned: Yes (on cavan.codon.org.uk) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 #include #include +#include #include #include @@ -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