Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1500049imm; Fri, 7 Sep 2018 01:03:40 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdakl7EXEpfChBiaLflczwNIKdHQ8HUEH++Xannm/aHu4n7PmxdyyA9COGQvD5nm3qn6IJ+m X-Received: by 2002:a63:6ce:: with SMTP id 197-v6mr6810775pgg.338.1536307420565; Fri, 07 Sep 2018 01:03:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536307420; cv=none; d=google.com; s=arc-20160816; b=ysWf06r0aC/tupFWqY89eaj9RH4HP30L953jWeyKqG+1MwVgtjqEK5y7joF0IawWuT EEeQI3U4NQYVoFCvRBxIrRf3p0l5+/NkcmOrRe0tF0qyrEv6PHptV5tL5bnz40mifZcY lAmS/N3rmT4+YQsXdrxeKMdm8sKMllozkTLr1nnrjCOp/8oPWbymutk7/2g+/LkQxdJK u0GdgUCci4qgAhr7qL1yEw6CR6wdNkhs8QlQaVb2+1FCOATt/T988Ca+toh+3oNyJNMr DXXkb+J70Nf7Pr+ZRFiVUwFtXIoNxBtGcbMwCOPtawRaCfkbcdNn/2GyYQHCmNullujn EO0w== 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; bh=X+GJm3Xbex0yl0OP8EjZbRJpEMSGQ2q0tg8RxWU9Kqk=; b=fOICvZ4Z0C50uSCwDrVfDU04aLE2uxh3YSE7VUh35HtRS2paqCkMT0NSQdKdRlWvPP HDMKmkW78Zlm28rxmIT6ovmatjNiyxH4HnvLCATKM4Yqu0haWRECjIBwAqvUqJJxglwH c4TptzA9Q53Nai1eWLcJAnz6ePY7Jlvt5D/I6x2I7pJR/52VcAFdlk/Jm2rwJ4AY9tId tG3YjImSfDVCz6rT9cK+mTWih02lXIieFnpsDuo8MQ/SzgAsdTuR0clB3nvR6LV6JV0b pYYME9UZsB6tDjNvVk8NCVfyx1m8WJIzTP1a11DCnkBVVLtXLWPWXSqPwAZ6UzPQBQlx 8HQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="TIULu/RG"; 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 j64-v6si6884429pgd.199.2018.09.07.01.03.25; Fri, 07 Sep 2018 01:03:40 -0700 (PDT) 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="TIULu/RG"; 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 S1728068AbeIGMla (ORCPT + 99 others); Fri, 7 Sep 2018 08:41:30 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:42289 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727963AbeIGMla (ORCPT ); Fri, 7 Sep 2018 08:41:30 -0400 Received: by mail-pg1-f195.google.com with SMTP id y4-v6so6592297pgp.9 for ; Fri, 07 Sep 2018 01:01:45 -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=X+GJm3Xbex0yl0OP8EjZbRJpEMSGQ2q0tg8RxWU9Kqk=; b=TIULu/RGQB3wXUBgnC5RwUQ9/bNFnHHSDDKNtaFC+Q8/PpJxLVYEw28tUbns0p3F1L u1PsnlOT3uNO/5a7ZeZEKpa8FEhI8W/IQeNDmXKvPECPhg9oFZRuRJs9LJsfYkxL82ic 4AeW/x0IC9qVSA2Z9h3APE+d+YfNkSakbAPok= 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=X+GJm3Xbex0yl0OP8EjZbRJpEMSGQ2q0tg8RxWU9Kqk=; b=IRE7DsYdNN38ZPaKoYX4WjW1Gjzs26YB1JEZKiukqk5pS14/FHeeaPZIcuF7lSDHKc R3BxV9kvRR2TywaetS8VW1m3Wxkp9uKHRetcHDF57LL2OhM3891p3XIYC0pMuGVd2/5y qjcQRov/T4gJql7/9KVaXPVvceaGdTaESTTSM4uWNL4SP4TBZUE7zHJazp760JDzjMcM f8tetGM6Io1sh6zasBtQ8hl/IRnx+0nYZ+libkzPGc+1mVzcR/5aHfr+zczRCGG+nfO8 S09rTGTIKkidVwa5e/E5l85NyKTyrYOG9FwxlMxe5FCJWkPMcA6IPvve1xzkBCF7gyDF qqaA== X-Gm-Message-State: APzg51CTMQZIuQhfWV9RxLzAvywFuu5g7cUhEZUP26zhE6cW1XI1yFwH LG78WPbI6G8kYxNJcVM5W6TkWg== X-Received: by 2002:a63:4826:: with SMTP id v38-v6mr6907762pga.379.1536307304938; Fri, 07 Sep 2018 01:01:44 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id r19-v6sm10530577pgo.43.2018.09.07.01.01.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:01:44 -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 Cc: prudo@linux.ibm.com, ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v14 15/16] arm64: kexec_file: add kernel signature verification support Date: Fri, 7 Sep 2018 17:00:39 +0900 Message-Id: <20180907080040.4967-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907080040.4967-1-takahiro.akashi@linaro.org> References: <20180907080040.4967-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 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 }; -- 2.18.0