From patchwork Thu Nov 15 05:52:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10683563 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4CA891747 for ; Thu, 15 Nov 2018 05:58:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 34F592C260 for ; Thu, 15 Nov 2018 05:58:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 251082C263; Thu, 15 Nov 2018 05:58:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9D7542C260 for ; Thu, 15 Nov 2018 05:58:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=emG2Odxd6H+VNPrPzPhioKFKXIlz/SVPz/jz6TTlOZ4=; b=QwEtkxmIta34xG 8vubX5PaETJa3J5etxtpU3Ks8Xzuy52wVgpAJM93tBdzP8yF5wPLv3vZTjB6RoH77LrHaMt+46dZQ Jy0/6YfFBYMsL4XOTJrURPLzo+AvUYdcMcE16cQ7rV5HfKYQ6wSPfBcMJT53MiLp3dW6Vvu/w2u8t m3kMmI1O1R6gUExSSNLJ5eD/QGHiKZX5Z4bzWcY2hMlfv9JYCMHy4xN6yyCKQoLgIc1V7VbuNKRVB 5eHwZacf+9KJX35VY1kY8tfd/GoEsrWUlvNFfXzPfEAWp9sbeYSIW/l2RxP2hAq8cixwqEDRkg1BU aO5sIVBdHEYkcX2K8pdQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNAfH-0003Mq-JF; Thu, 15 Nov 2018 05:58:07 +0000 Received: from mail-yb1-xb41.google.com ([2607:f8b0:4864:20::b41]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNAbC-0006da-GZ for linux-arm-kernel@lists.infradead.org; Thu, 15 Nov 2018 05:53:57 +0000 Received: by mail-yb1-xb41.google.com with SMTP id h187-v6so7903533ybg.10 for ; Wed, 14 Nov 2018 21:53:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9P53Yj/xMXiy2VwbQPz0MnQUBccWU//quNYW0Ks+uWQ=; b=RuBj4P2KtbYJ5z9USSRs+7o18nA+07+01QwFh3UtWxMpEjf1sRCmIJdKeu9F7Dxe0b U4yhq1t6E5RWWBnY3EVAbaOpN+RsBs9HGRli3CY50P6r+V5BdeUIq1m6yrvOhnrJ4Snz kVhrmv1hMMApkndiuBYd7IAa8gpBE9Wml7WoY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9P53Yj/xMXiy2VwbQPz0MnQUBccWU//quNYW0Ks+uWQ=; b=cJuUnWESUco1mjB87yySFOrbioZ6Ic0e5RKy6jiyy1nM0g2xnrbv0oI+ddciDIYbAc XfJ/nOdiJHYWPKJAf0bXR9ejdLVwcaCnbmz8UkZB8nVQhgiBShgnnbduDsmQno3kzluR 19KbXdVLUlimwyRya3LUGMTR6AmE64n+a1GO93Dh3+ScAnwYOv+cxWLw+cDkZbygdtIa V8/CQHjDz6lub0obYH+JOQi17GQNtWW05aKc8PCCHX+dPyRIZJtE4iYOH8W7RPYtMwVk sbL5SQkk23XMt/8DJTqRDks+focaOiLBfr7/6T17Ux3Xl+/TpTEGs6kyPitlWpWStel+ u/Gw== X-Gm-Message-State: AGRZ1gK23TR8n8b2BYc5Y3kj1QeUkMOe0v+T1yXUjT9ItLnl4CVksFCR gdK7etCItOPfP5xBY7PTYW45Cw== X-Google-Smtp-Source: AJdET5fFdK8szs+B+qUJ3wdgWiLE4l4gaPySkRnftc2+aZxbkCEKtN3WDr30shmkoLh8Q0v+ims7Og== X-Received: by 2002:a5b:40a:: with SMTP id m10-v6mr4520102ybp.21.1542261223143; Wed, 14 Nov 2018 21:53:43 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id l35sm1837306ywh.48.2018.11.14.21.53.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:53:42 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v16 15/16] arm64: kexec_file: add kernel signature verification support Date: Thu, 15 Nov 2018 14:52:54 +0900 Message-Id: <20181115055254.2812-16-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181114_215354_592167_148EA466 X-CRM114-Status: GOOD ( 15.67 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP With this patch, kernel verification can be done without IMA security subsystem enabled. Turn on CONFIG_KEXEC_VERIFY_SIG instead. On x86, a signature is embedded into a PE file (Microsoft's format) header of binary. Since arm64's "Image" can also be seen as a PE file as far as CONFIG_EFI is enabled, we adopt this format for kernel signing. You can create a signed kernel image with: $ sbsign --key ${KEY} --cert ${CERT} Image Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: James Morse --- arch/arm64/Kconfig | 24 ++++++++++++++++++++++++ arch/arm64/kernel/kexec_image.c | 17 +++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 93dc4d36d6db..11f3e1a00588 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -867,6 +867,30 @@ config KEXEC_FILE for kernel and initramfs as opposed to list of segments as accepted by previous system call. +config KEXEC_VERIFY_SIG + bool "Verify kernel signature during kexec_file_load() syscall" + depends on KEXEC_FILE + help + Select this option to verify a signature with loaded kernel + image. If configured, any attempt of loading a image without + valid signature will fail. + + In addition to that option, you need to enable signature + verification for the corresponding kernel image type being + loaded in order for this to work. + +config KEXEC_IMAGE_VERIFY_SIG + bool "Enable Image signature verification support" + default y + depends on KEXEC_VERIFY_SIG + depends on EFI && SIGNED_PE_FILE_VERIFICATION + help + Enable Image signature verification support. + +comment "Support for PE file signature verification disabled" + depends on KEXEC_VERIFY_SIG + depends on !EFI || !SIGNED_PE_FILE_VERIFICATION + config CRASH_DUMP bool "Build kdump crash kernel" help diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c index 9f0d8b5d62d3..d1c6c54c22e3 100644 --- a/arch/arm64/kernel/kexec_image.c +++ b/arch/arm64/kernel/kexec_image.c @@ -12,7 +12,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -29,6 +31,10 @@ static int image_probe(const char *kernel_buf, unsigned long kernel_len) sizeof(h->magic))) return -EINVAL; + pr_debug("PE format: %s\n", + memcmp(&((struct mz_hdr *)h)->magic, "MZ", 2) ? + "no" : "yes"); + return 0; } @@ -107,7 +113,18 @@ static void *image_load(struct kimage *image, return ERR_PTR(ret); } +#ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG +static int image_verify_sig(const char *kernel, unsigned long kernel_len) +{ + return verify_pefile_signature(kernel, kernel_len, NULL, + VERIFYING_KEXEC_PE_SIGNATURE); +} +#endif + const struct kexec_file_ops kexec_image_ops = { .probe = image_probe, .load = image_load, +#ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG + .verify_sig = image_verify_sig, +#endif };