Received: by 10.223.185.116 with SMTP id b49csp1796934wrg; Thu, 22 Feb 2018 03:21:23 -0800 (PST) X-Google-Smtp-Source: AH8x226HIQKxaen9CWM0Nvm133DXLiVeiItVeGGNou/xJ3TW6JQ9juWSAK55zLbgZyUlOkQYWNbi X-Received: by 10.99.109.79 with SMTP id i76mr5204169pgc.402.1519298482912; Thu, 22 Feb 2018 03:21:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519298482; cv=none; d=google.com; s=arc-20160816; b=n67+9ctcEFLAOEeocy6ag1ODpdOqq4ugp3u57ePnNKBPsXcjsTzepUkXaWkzxUW24v /kzoY6cM89pg1eaZi9+5J1R73cGXNsgQ4Q58eAnlcNhn86Jt+WqGzXo2JnoMKerUgHgY Y9akQEGO6wy5ABhIHkJ2vEuB1uQIG/xxjN8+MvFxwMa3nPdPAEnmOU8ZZddy35bdQEav c2P+3AJ97Xum5XPAHIu3npNLVBwx1cICHFF9aDh5es/ws6rxS8TP8hEw7Irvz22cmid7 vvOZE45i4msbrg59w6oQRlUtCeh9b7zDZI4iqH0D0mMd8H0kTuzhw1gtJiU3uvjocpKf NAqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=jsSE1wBGdj+4kK9YoZHE5wwBzlPAEkUMsMeDdB0bAvY=; b=XIDKyjsUIsb+1c8S6wEJeQgaT5EZ3FZIvDWB0shOD4v/gif5b+aS5Ty9V91RDuahCg z9sxZnfBTjVzrsh3K1EMIX18mzQ7TkgKPHZr84hB/UuktwoKIWQUJSbCG1U3lAUvtpaY x990DJCEnjEBanxhRZRlIN8NWdWsDZvga+EmqyT+Z0hJjpXfGInI+1ceV/emRZqArwdp qljAhLsQh/BHGEONGF9XpdkPC5EL8wrCLOEyP36EsUhfM+5+5FRDPqY7S2euMCV2YiJm IuNZwRASgUEeRtVUXo915hkBJgiKPLixU2NqtReERcLL4j7/KEfD1bvESQrQJdbiNuxO 2Bpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A45/ZI6k; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p9-v6si879187plr.622.2018.02.22.03.21.08; Thu, 22 Feb 2018 03:21:22 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A45/ZI6k; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932245AbeBVLUH (ORCPT + 99 others); Thu, 22 Feb 2018 06:20:07 -0500 Received: from mail-io0-f194.google.com ([209.85.223.194]:39066 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932080AbeBVLUE (ORCPT ); Thu, 22 Feb 2018 06:20:04 -0500 Received: by mail-io0-f194.google.com with SMTP id b34so5634951ioj.6 for ; Thu, 22 Feb 2018 03:20:04 -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=GCGHeF3dAVIGVNY+yb+k/fbo8ZbHhNHE23gNInhqEhpd8LgFENlytx77FT3z+8Kr43 C8lgj4Y4wR51gNjAkX4+qYB4bqADpITOjwSOiJGf1apFcwTJUveynk8i89ITijBs621O tbrPA9jQ8kZ1M2h7Ncb3tt4bpF7XekdMA+CTkFZG7Q9csFqISFgxngpNyU5mQNqsrX2F 4F5sWOYVizRumTdULGy9Yu428jLauoOyq9C8AeAR5dd/WLLyp1YfI83ai3nuYshuZuRr TOkfjd/DxbX3fihTvvg7kxr3XSwwa1ldIXsXeqAQBF4y4heUCZlqE7ZVGpnTHkBCS8KY hTxA== X-Gm-Message-State: APf1xPA4qMgEE1hU2JJlJ+mEl5X0SzUEl/FxSuQtPdXZUoBhn+wQqe68 0sMYxg9pgfq+LZ4/TnOAFSKbOQ== 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 Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 }; -- 2.16.2