Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1288785rwb; Fri, 23 Sep 2022 10:27:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4fw5Y2FhK+qQteOr+k8yftL25tffLRtsUxtRiStmjknRHJkqamWHNL9sPblobMWJqi56R3 X-Received: by 2002:a05:6402:849:b0:453:10c3:2ee3 with SMTP id b9-20020a056402084900b0045310c32ee3mr9620911edz.339.1663954023804; Fri, 23 Sep 2022 10:27:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663954023; cv=none; d=google.com; s=arc-20160816; b=sMYp+7a9HlWRTkfXoRn9Mr3dnkmrlmIAtz8dbN2VVtaijJ3x09Z4D+OjIcAfhlDWGg pfqyReonQD19YBWH7j5l1tq/IYD8YFLA64DFA07aFe2CTRISxB/KfbPfWpxjwoRMV+n2 ca6x1L3Hs2HXZ8z6TpGk7uDVL87muNka8YSXCALtKhYL0Nl0IUi1m5Y4xWe8ApiN3paw dICjDilY+SKKuxOOJVTdFmidcxIRsOxEbKWeWbxHg9bP+d0Lrv6bUD4P5t4bXY61lVZU 9Ctx/ysSY3HSwf3chMXJK/m2Z/PVYnSRVjucUnVUBCWATtRQm92BsJboApIzkR5DQWYF OQCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=Rmyc7+NXxSKrvuh1Oxes12NMTBkZbYvg0p3QHUHFwAk=; b=PO7wAIZ4OgxPrbThXo3plGFekd+95AFj5ppz+VzFe3E8QcO0pkySEI+H/KMCR0N1tQ l9dFFv3ePaCdJ3G0gSyJ4oSnKM6qM1gUOGSs4KFRBIKMVGNDsT+RqLTz12X0/2VgmX/F ivgBbNIG+DncrQ0MuxW8PMM1RuiBAemR8MyD8Wl6hKVBk/TiwCPTCoY+Zc2oLKMSDhqm pZAjha8UGiNgZ3nEkaTaZy+noYbroZ0Een5HQXpuwAWSPqusWrSEK4I9fEcICYemqXHS FEIIsqMbcuBMFXoXXkIHyNT3FelLnwlGYApyL+v6L36XIX0tL21aS16vCTe0jyHOUpCi ZvWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=0okAljIZ; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hq30-20020a1709073f1e00b007824786a7easi5133942ejc.724.2022.09.23.10.26.37; Fri, 23 Sep 2022 10:27:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=0okAljIZ; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231601AbiIWRLS (ORCPT + 99 others); Fri, 23 Sep 2022 13:11:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232287AbiIWRKz (ORCPT ); Fri, 23 Sep 2022 13:10:55 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FBED147692; Fri, 23 Sep 2022 10:10:53 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 4ACD221A39; Fri, 23 Sep 2022 17:10:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1663953052; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Rmyc7+NXxSKrvuh1Oxes12NMTBkZbYvg0p3QHUHFwAk=; b=0okAljIZr+W1vgFvro+h1w1DeSfzGLvmWklZkBfsdvj9UzlpIN1exoRqL6t4SYtpO7Zy7M GT4b51Wjs1iuS+A75vliMgkqEkea4NCiNvKHTw5JCCgI50weB8OTkbTqHh1N6QOljA8XQ3 TR7/ki4fwb1uHc2z227q7ITjzA9G9p0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1663953052; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Rmyc7+NXxSKrvuh1Oxes12NMTBkZbYvg0p3QHUHFwAk=; b=symqT+AAemfpN0Bky/MVOHY5dYy0iRKssfzEGEcxb1JR2M6MH9k9AKE2/u91O0fNo5aHXz CFf6Wvd+5VdRspAA== Received: from kitsune.suse.cz (kitsune.suse.cz [10.100.12.127]) by relay2.suse.de (Postfix) with ESMTP id 0AC0D2C171; Fri, 23 Sep 2022 17:10:52 +0000 (UTC) From: Michal Suchanek To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "H. Peter Anvin" , Eric Biederman , Michal Suchanek , Coiby Xu , Mimi Zohar , kexec@lists.infradead.org (open list:KEXEC), keyrings@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [PATCH 5.15 5/6] kexec, KEYS: make the code in bzImage64_verify_sig generic Date: Fri, 23 Sep 2022 19:10:33 +0200 Message-Id: <7f9c49c652d30c1093aeb4bac42c27dd88610388.1663951201.git.msuchanek@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Coiby Xu commit c903dae8941deb55043ee46ded29e84e97cd84bb upstream. commit 278311e417be ("kexec, KEYS: Make use of platform keyring for signature verify") adds platform keyring support on x86 kexec but not arm64. The code in bzImage64_verify_sig uses the keys on the .builtin_trusted_keys, .machine, if configured and enabled, .secondary_trusted_keys, also if configured, and .platform keyrings to verify the signed kernel image as PE file. Cc: kexec@lists.infradead.org Cc: keyrings@vger.kernel.org Cc: linux-security-module@vger.kernel.org Reviewed-by: Michal Suchanek Signed-off-by: Coiby Xu Signed-off-by: Mimi Zohar Signed-off-by: Michal Suchanek --- arch/x86/kernel/kexec-bzimage64.c | 20 +------------------- include/linux/kexec.h | 7 +++++++ kernel/kexec_file.c | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c index 170d0fd68b1f..f299b48f9c9f 100644 --- a/arch/x86/kernel/kexec-bzimage64.c +++ b/arch/x86/kernel/kexec-bzimage64.c @@ -17,7 +17,6 @@ #include #include #include -#include #include #include @@ -528,28 +527,11 @@ static int bzImage64_cleanup(void *loader_data) return 0; } -#ifdef CONFIG_KEXEC_BZIMAGE_VERIFY_SIG -static int bzImage64_verify_sig(const char *kernel, unsigned long kernel_len) -{ - int ret; - - ret = verify_pefile_signature(kernel, kernel_len, - VERIFY_USE_SECONDARY_KEYRING, - VERIFYING_KEXEC_PE_SIGNATURE); - if (ret == -ENOKEY && IS_ENABLED(CONFIG_INTEGRITY_PLATFORM_KEYRING)) { - ret = verify_pefile_signature(kernel, kernel_len, - VERIFY_USE_PLATFORM_KEYRING, - VERIFYING_KEXEC_PE_SIGNATURE); - } - return ret; -} -#endif - const struct kexec_file_ops kexec_bzImage64_ops = { .probe = bzImage64_probe, .load = bzImage64_load, .cleanup = bzImage64_cleanup, #ifdef CONFIG_KEXEC_BZIMAGE_VERIFY_SIG - .verify_sig = bzImage64_verify_sig, + .verify_sig = kexec_kernel_verify_pe_sig, #endif }; diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 46f113961dbc..1dd7b679fcf9 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -19,6 +19,7 @@ #include #include +#include #ifdef CONFIG_KEXEC_CORE #include @@ -206,6 +207,12 @@ static inline void *arch_kexec_kernel_image_load(struct kimage *image) } #endif +#ifdef CONFIG_KEXEC_SIG +#ifdef CONFIG_SIGNED_PE_FILE_VERIFICATION +int kexec_kernel_verify_pe_sig(const char *kernel, unsigned long kernel_len); +#endif +#endif + extern int kexec_add_buffer(struct kexec_buf *kbuf); int kexec_locate_mem_hole(struct kexec_buf *kbuf); diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 8d73d6d4f0a6..289bb20e6075 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -123,6 +123,23 @@ void kimage_file_post_load_cleanup(struct kimage *image) } #ifdef CONFIG_KEXEC_SIG +#ifdef CONFIG_SIGNED_PE_FILE_VERIFICATION +int kexec_kernel_verify_pe_sig(const char *kernel, unsigned long kernel_len) +{ + int ret; + + ret = verify_pefile_signature(kernel, kernel_len, + VERIFY_USE_SECONDARY_KEYRING, + VERIFYING_KEXEC_PE_SIGNATURE); + if (ret == -ENOKEY && IS_ENABLED(CONFIG_INTEGRITY_PLATFORM_KEYRING)) { + ret = verify_pefile_signature(kernel, kernel_len, + VERIFY_USE_PLATFORM_KEYRING, + VERIFYING_KEXEC_PE_SIGNATURE); + } + return ret; +} +#endif + static int kexec_image_verify_sig(struct kimage *image, void *buf, unsigned long buf_len) { -- 2.35.3