From patchwork Thu Feb 22 11:17:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10235253 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 819A6602DC for ; Thu, 22 Feb 2018 11:42:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 835E428901 for ; Thu, 22 Feb 2018 11:42:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 77ECC28A93; Thu, 22 Feb 2018 11:42:32 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable 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 E412728901 for ; Thu, 22 Feb 2018 11:42:31 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=l5tA5GnwpM34Vck2odB+StiFIHLP+r35+NChcHYT084=; b=vBySvde27Eo5s7FdxH7TPNVUte G9pl0rnecocEoLZk8ybh1SbSdM2G4uuBc83H2ynqn5MFRRqBYiJvI9f9GLPte3bWQBQ1gIm/FmwmD TmBlSgb0s/q9e/3B2B5nSsdkMmNK1FdFibHuFzax0T8EB6BEcprFyKjmxpE81uCmSVbzleSRQeige 0BsjhyNyuTx7/VnF3H/ducRZFKR+8IK3ubsDNzteyO7bqgdq9uZnf6Ju25HyWSq4AhKeUDrGmF+Ww gcwabiGv47FI9ub8LiD2OV/FkUvlRm6L3n+2RlWvFSWMd48qXl6gj7IFdYIJZL73t1rNNBHx9E4La amWuu5Ng==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eopGa-00018j-IM; Thu, 22 Feb 2018 11:42:24 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eopFs-0000md-B6 for linux-arm-kernel@bombadil.infradead.org; Thu, 22 Feb 2018 11:41:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=jsSE1wBGdj+4kK9YoZHE5wwBzlPAEkUMsMeDdB0bAvY=; b=WP19O2Z2SCivgvjn1crLKPNcM UQ9W6YV7krqdS4rWfh7JiAgbnBmlibmdZ4rXcol75eJN81J6tbRQnlKurNzd8K63N5yEYXwSTw/Gu P58smr0YCtEnyVCLiHnZlFGEKPiytrDmH7e9I5Ti6rrBuiF3xVH1q+PCPOrWpfdB5N8ZJWc1vPPOM xsSOlbrIQ/kUWGRGccQMsNqtmlAlgLJMQwoyF9fH7BmNu3Bn4SClLewIRdLVMl3AT9HvC9ZfhdiPa ALOWdVeSPh4VrqsMLSmey11iJgfqDqtE0HAxXD+olrouOPJ/3gNufEXGrtTIRg1Zdxiaky/vOxLiu PjwVk7CVA==; Received: from mail-io0-x242.google.com ([2607:f8b0:4001:c06::242]) by merlin.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eoovA-0003lA-D7 for linux-arm-kernel@lists.infradead.org; Thu, 22 Feb 2018 11:20:18 +0000 Received: by mail-io0-x242.google.com with SMTP id t126so5639394iof.4 for ; Thu, 22 Feb 2018 03:20:05 -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; bh=jsSE1wBGdj+4kK9YoZHE5wwBzlPAEkUMsMeDdB0bAvY=; b=A45/ZI6ksv7IFSWodYMWlt2ROlGlh6xw7p+baWy63g6Y5acLXiIR7eXnYhh+lsa+LL 9y37uXm1kpmb/jJqYOxtK24tndIZtxnL8OT8YYaE8W48mNzfRZT1B1kymcXclJ6d1Y+4 itvbBmEm6wY6I/b1M5oOmvb4ISdNnYzKPYAlU= 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; bh=jsSE1wBGdj+4kK9YoZHE5wwBzlPAEkUMsMeDdB0bAvY=; b=BQ+BXw6ILMBZqbRYAGaFwCOfGkIT2RDgbEixThxHL0HjRcHdytznt05IaiW+HQxDfv mEzCWqedaLm7XgjCsHN0F0YQrT28QQP3yc6eSrihcrmIXBWHos0m7woloM1uMmtH5FPK enz4FKXu6v2st6te4I7DR93hoekBsv1ddX78NqlQjq9pyc4kkj6Y8pFJJbf9wrgGTWxI Gf/V8XezSR+2+wV/3OyjDQZUcZiM8inDU6hZLQsn9p6UA0/Ggui6msTzZ1ZVQtF/LqhM sZofizT2wDwwJqmGVFTVi1pydU4oUmWpI2UtnUSRuuThrHFuT6do20Q2ruMlwrsFPXUv OUeg== X-Gm-Message-State: APf1xPANzEe8unQik5bs11+F9fipXckOjZ9uCL10/S8FECnystKyjEtS REZMBelldGPchPqzRfAxG8Nlow== X-Google-Smtp-Source: AG47ELtgmCeOYz3d3w/L84mPl9+Cs+IH1/zphd7iVJL8f2mxxy3QMWMA02DwqEpqw/cQzyio4Y82DQ== X-Received: by 10.107.138.35 with SMTP id m35mr8402008iod.81.1519298403844; Thu, 22 Feb 2018 03:20:03 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v140sm188171itb.42.2018.02.22.03.20.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Feb 2018 03:20:03 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org, julien.thierry@arm.com Subject: [PATCH v8 13/13] arm64: kexec_file: enable KEXEC_VERIFY_SIG for Image Date: Thu, 22 Feb 2018 20:17:32 +0900 Message-Id: <20180222111732.23051-14-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180222111732.23051-1-takahiro.akashi@linaro.org> References: <20180222111732.23051-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180222_062016_614177_E9EA0A1A X-CRM114-Status: GOOD ( 20.15 ) 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: AKASHI Takahiro , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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 --- arch/arm64/Kconfig | 24 ++++++++++++++++++++++++ arch/arm64/include/asm/kexec.h | 16 ++++++++++++++++ arch/arm64/kernel/kexec_image.c | 15 +++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 79ee27b8d2a0..e400edc291d4 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -839,6 +839,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 "Image signature verification is missing yet" + 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/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 592890085aae..85f6913f868f 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -132,6 +132,7 @@ struct arm64_image_header { }; static const u8 arm64_image_magic[4] = {'A', 'R', 'M', 0x64U}; +static const u8 arm64_image_pe_sig[2] = {'M', 'Z'}; /** * arm64_header_check_magic - Helper to check the arm64 image header. @@ -153,6 +154,21 @@ static inline int arm64_header_check_magic(const struct arm64_image_header *h) && h->magic[3] == arm64_image_magic[3]); } +/** + * arm64_header_check_pe_sig - Helper to check the arm64 image header. + * + * Returns non-zero if 'MZ' signature is found. + */ + +static inline int arm64_header_check_pe_sig(const struct arm64_image_header *h) +{ + if (!h) + return 0; + + return (h->pe_sig[0] == arm64_image_pe_sig[0] + && h->pe_sig[1] == arm64_image_pe_sig[1]); +} + extern const struct kexec_file_ops kexec_image_ops; struct kimage; diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c index de62def63dd6..816d5faf491d 100644 --- a/arch/arm64/kernel/kexec_image.c +++ b/arch/arm64/kernel/kexec_image.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -27,6 +28,9 @@ static int image_probe(const char *kernel_buf, unsigned long kernel_len) if ((kernel_len < sizeof(*h)) || !arm64_header_check_magic(h)) return -EINVAL; + pr_debug("PE format: %s\n", + (arm64_header_check_pe_sig(h) ? "yes" : "no")); + return 0; } @@ -84,7 +88,18 @@ static void *image_load(struct kimage *image, char *kernel, 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 };