From patchwork Sat Jun 23 02:20:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10483447 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 42EE0602CB for ; Sat, 23 Jun 2018 03:05:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22D7F29000 for ; Sat, 23 Jun 2018 03:05:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 13FF729081; Sat, 23 Jun 2018 03:05:39 +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 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 18D5A29000 for ; Sat, 23 Jun 2018 03:05:38 +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=8afjIx213w66KyfPhqP+xCDjB1m4tlh00zHZTLhFBhc=; b=IKKr6ZaytGnATmH3teGhITrnTj mp7fwrrojvPaj0DtvnK7uAJ9O9bf6HQyB4Uc2hj4hzf0GK7I1Z5zNrKIrw7hwRYbUpaE8YU+j6gzg 3+n+OZB36455BYMCPn+qZn9ouYdxG8JKPaMH5u8SFUgfPU1eI8SD0G8x3fq88DJBdh1hiSi83CkPY H+NouoiQSj5rawX+FrJ/s7szRoFclLTs+A0P+AdW72lRBQBZZzfMAcrEp554qKp35bJ9hHcE3Z91U Vyg6wI4X0fHCRPAhBQSND2DtJwBOQAx7pBREzpAvoklFIcqcS7/24nONKml71mYKEjVvThB6k4neU LpGEIQAA==; 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 1fWYrf-0007GC-Rq; Sat, 23 Jun 2018 03:05:27 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fWYrc-0007Fz-PP for linux-arm-kernel@bombadil.infradead.org; Sat, 23 Jun 2018 03:05:24 +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=6iq0k8J5XruMuCEwI5GOPO4br/vpHgLgOsDlsPLUiok=; b=OtPn6/LmFmK1OBjRRIFlgJL6L P8M/0YObDkzLdlgg6ujPqsEuc9SymBndnfMKfEjcU1c0McKWyI0AFZD0v4CFBUfmEXJDiHiQflOCm +Gz3XnQpKdNS206QZy5rQgC9XBniiztSH6wHlELELMVNmpcFCIJZZYrE9OnTfH9KURmNvtnKrKOx3 ViayYqhOroXPQnkt2+D8m7ImEDQESDKTaFtLx5NagfAR+Bc88pOut3TOCveePEZ8Kj/jsi47SU0WZ DibVR02sfJEyWUE1k0IYgm74vrwANetMxyxMcpkHibng6CrBGMMxCii+GjN2F8ZtIEA2kEyiuMy0o v8UlJQ7RQ==; Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fWYBc-0004Zx-N0 for linux-arm-kernel@lists.infradead.org; Sat, 23 Jun 2018 02:22:01 +0000 Received: by mail-pf0-x242.google.com with SMTP id x23-v6so67527pfn.11 for ; Fri, 22 Jun 2018 19:21:50 -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; bh=6iq0k8J5XruMuCEwI5GOPO4br/vpHgLgOsDlsPLUiok=; b=W8+e0NFMFkGddfjFaPG1FKSmMrI7Z40eg2qdQG8pnuZtGQ85tzz04ZNWG5JbnyHGTv JJwBwgapq3zQ/spzzYHxKJ+2Ou+QEIPuBoVwZWWmYgFnDBWpEFCQ790mxYfJ+R3Gfzzp TponLKQ5lPM0HVg7YVluoO2ZOrsh8OrbjDY0g= 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=6iq0k8J5XruMuCEwI5GOPO4br/vpHgLgOsDlsPLUiok=; b=icX9lYv5S0A3xCFslk05gSHxDQaYj/x+oQ/z4655hXbCW2KrXE+AtDoiWNNmx7Zmo2 jIN8xJiolKRe1dRQziShBA1eYAhVypeSfG6ZxPO7ojXZ6DeENRkfMxuIoB4NYTR7nRCK tF0VYWRDp1bBcrSlhyEyjaI6d3rIXbxe/x+26/Mgqr4D0p5VjAkjs8yAFnBiZZY7fmrz 7yuphtJsLoEu0b7vccwSVIBTHb8P8m+Ts/jVfTKLbQKle4REZLlBG6Zpr9gxzuAfYFfy lM68sc9P8Gsivo6noSHCIOyclWzhsO9pLebRCvi8emG8GcShXzIsrP/5Eh0Rffdjy5en si9Q== X-Gm-Message-State: APt69E3UTPShQbN/GQqY32+KHoO84qB7gRjSmhgeyW3DdyKGjyHLyFVW wSQuTw2wyZ4VFLberyDaYlZCFw== X-Google-Smtp-Source: ADUXVKLv/K01s4UDZALSdo36absYM2DLdjfK6Pe52MG0SC6lTDGYtAcMC/8dWKq1aKCwUXfz62Oykg== X-Received: by 2002:a63:5ec4:: with SMTP id s187-v6mr3363726pgb.72.1529720508470; Fri, 22 Jun 2018 19:21:48 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v15-v6sm24129368pfk.12.2018.06.22.19.21.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Jun 2018 19:21:47 -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 Subject: [PATCH v10 13/14] arm64: kexec_file: add kernel signature verification support Date: Sat, 23 Jun 2018 11:20:57 +0900 Message-Id: <20180623022058.10935-14-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180623022058.10935-1-takahiro.akashi@linaro.org> References: <20180623022058.10935-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180622_222200_808110_B8E0D410 X-CRM114-Status: GOOD ( 18.54 ) 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, AKASHI Takahiro , james.morse@arm.com, 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/kernel/kexec_image.c | 15 +++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index f68318f61c85..5133c22a01ab 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -845,6 +845,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/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c index df1e341d3a28..bb0a95add197 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(ARM64_MAGIC))) return -EINVAL; + pr_debug("PE format: %s\n", + memcmp(&h->mz_magic, "MZ", 2) ? "no" : "yes"); + return 0; } @@ -107,7 +111,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 };