From patchwork Fri Sep 28 06:48:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10619089 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 E2803913 for ; Fri, 28 Sep 2018 07:23:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA3E02A8A0 for ; Fri, 28 Sep 2018 07:23:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BCE9C2A8AD; Fri, 28 Sep 2018 07:23:55 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE 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 082E42A8A0 for ; Fri, 28 Sep 2018 07:23:51 +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=mkKMci5dXzCP0Bi10c73r89PbAOOWtCrRyymcS+LaB8=; b=fuZc2HbXLqe5t+ e3xsvDNN/H/HYef8IRipmTViA58gGWrVbFnpCbc35lVYazKqBi6Q++OaAxtG2PYIwJ9ykR0XGvWjk srtukCqMbYv4xiVrluJYNOoG1gZmq6Wm57/V0VVOoSzGba9gwrFPBeVfhxbOGvqEAXxXkVR629n1C RLr0yrV9WjSsj++ZcyIXyf3y/UGOVS3eHJf9bKx+3p0d+Q+A6+e3mfAszFNXG0XRbUcApl1ycmUwL GWeDi9rUtl8JzkEwbKV+R8hsowgwJdMtjkGgG/psfNDfeQ5njrRWJWJ+wM1MViyWe50ChWAMfvvJn uVPcdaqeSG9JOCetRLmQ==; 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 1g5n7n-0006Yg-TP; Fri, 28 Sep 2018 07:23:43 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5mb7-0004xJ-So for linux-arm-kernel@lists.infradead.org; Fri, 28 Sep 2018 06:50:37 +0000 Received: by mail-pf1-x442.google.com with SMTP id s5-v6so3626885pfj.7 for ; Thu, 27 Sep 2018 23:49:32 -0700 (PDT) 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=/+rOwpZAq7LVQH0becYmXtiL//qU2xu/pSqOkMjD4f0=; b=KB4DyH3/aOOCTeE+ulXend4IlnHljB8l5FxwaLh7zMawvTxl7hXakSbyIdy2GdfBCW TNu6W9rqd6YcC/Kpzk+yYa5fv0ttZ9AtOK1qLnCv7Fg6BTui3hGcYghBqoaFUVpmiYPY HiRibIaRnhkbDmMNt9I9kQiq9lvDDFVFZnlyk= 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=/+rOwpZAq7LVQH0becYmXtiL//qU2xu/pSqOkMjD4f0=; b=T4koretZ0rgY52PugUp3vgeaE+ZAxGHDGM8SyztEN9esh2ADsw3yipj55V7BIHTKND c2RPA6aGJOw18khcQ/gshY8KEYWc2uXBCR+/JPPor0lKX9ddB3SJAwov3j6anYH2VBOH k3zt+HRq10CnQpCW56YXx3+LvEseRlQyn7aSh5mCkr1x2D5N28RUB1n6KXQ1uzSsFVwd cDLei4nQxcss0qlx0lsnN2UaPNXJ74JyZ/KQZMzTS+tfnx2+YewdJBms2JfWn86Q2XD2 vKqYjtBIlkOe4tnXB1AykLmdnEiWBziuG0IrD3wN7q1oOoss0Ik+6qydiDN1k/Pg4zew iYJg== X-Gm-Message-State: ABuFfojLANWjAnGRh4X5XZ1D+SyZ7RYJ6+LshgUCbTUJO3mlH/mwsSy9 7xB+FN7Mh0WEyN5p7ST4OffKeA== X-Google-Smtp-Source: ACcGV60SDpQTkxHCAGmUi4T9yL5fxZ5izgApfms5Yuq6163677NqEYfYEU7DiQUy9rUdcK58yn0tTg== X-Received: by 2002:a17:902:4e:: with SMTP id 72-v6mr14655909pla.318.1538117371502; Thu, 27 Sep 2018 23:49:31 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id c79-v6sm195047pfc.92.2018.09.27.23.49.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 23:49:30 -0700 (PDT) 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 v15 15/16] arm64: kexec_file: add kernel signature verification support Date: Fri, 28 Sep 2018 15:48:40 +0900 Message-Id: <20180928064841.14117-16-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180928064841.14117-1-takahiro.akashi@linaro.org> References: <20180928064841.14117-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-20180927_234958_117229_03299AEB X-CRM114-Status: GOOD ( 16.26 ) 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 | 15 +++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 5eb18d0cb513..e7de9500bf0b 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -852,6 +852,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 d64f5e9f9d22..578d358632d0 100644 --- a/arch/arm64/kernel/kexec_image.c +++ b/arch/arm64/kernel/kexec_image.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,9 @@ static int image_probe(const char *kernel_buf, unsigned long kernel_len) memcmp(&h->magic, ARM64_MAGIC, sizeof(h->magic))) return -EINVAL; + pr_debug("PE format: %s\n", + memcmp(&h->mz_magic, "MZ", 2) ? "no" : "yes"); + return 0; } @@ -102,7 +106,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 };