Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp3509386pxb; Sun, 26 Sep 2021 17:52:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAKsSNRyx7mgzqrHUjkBPoMcJNOQ2UchKmN6fhxXJtwF/KkqYMzYrSrvDJt+h7UnKnzcwb X-Received: by 2002:a17:907:7785:: with SMTP id ky5mr24890723ejc.247.1632703964403; Sun, 26 Sep 2021 17:52:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632703964; cv=none; d=google.com; s=arc-20160816; b=pA8HvxXfB/moJGzusTX+879PDCwTTwDoz9SBIuPKFx/6Y+vhf4Jm5ibNz2eJTytPQn ThFLdGcdFxo/QAxPphbFHt4YgHePfj5zG5iJtN4d8mumBLYpwkW8wmXUuiuY0QNT0074 1aRl1ugW7qPAkgPECGcoyWwZbJdtIee4I91m95oK0PBISOOKvEqGem4S1lXPV3CbVSy0 v/sDSA04/JZRhoMSPHcV4mmcDlhvh/4XOHC3NXpNLS9rzsIgpxNPlpJCPkWcEguR97ru iYE6MTHhsvrm0ulIXYVv1g4Pe2Ydx46MJb7k3HaBa7Elk4Go3NQdpidfmjDbdM6HTF+1 4V1w== 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; bh=QsdM6aopx9gxxLgRRxYhXTLHWovYEZKaxBqN+pAsLlI=; b=09dOoz4qAQ5AClYwX8OJzL3A50RVnQ5BYPSPoPsh86Dc1CxietDH8dCz+os4Oz8sFU PDxZi5Z3np3hmglIgU7s/aQoYx2BmTIuGankRcnNdFrfus0oFrdRyUm3YYns6pS+c1v3 Vc/I8grlEnhEu4ylH/OMpBmGbn+s2kTYgrGyVunoWzRnWTpPVU8Ylk+RX4dlOKZYEqQT fNFBnuGARK6rjQHgwnIz/nCVmduq3JfqDT9h7gwOGrfysLgBhZaiyMfwbCEPK42wD4bQ 7yRmC9xpP5SlffKD/daK8hGbFsZbd2uVboJVkSSFEb3Jd4om35h+Yd8HyB6FtXJ1Cyad ETRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=iCYCIrYH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kx3si20648701ejc.108.2021.09.26.17.52.20; Sun, 26 Sep 2021 17:52:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=iCYCIrYH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231873AbhI0Awk (ORCPT + 99 others); Sun, 26 Sep 2021 20:52:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229865AbhI0Awj (ORCPT ); Sun, 26 Sep 2021 20:52:39 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13ECDC061570 for ; Sun, 26 Sep 2021 17:51:03 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id e7so16205031pgk.2 for ; Sun, 26 Sep 2021 17:51:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QsdM6aopx9gxxLgRRxYhXTLHWovYEZKaxBqN+pAsLlI=; b=iCYCIrYHrbK8cdGtn6MR8fwASSIoV80M93RdizJldcwb0F1vOjxJeH29f4/xfyieDS hOrYSxPnhwLJ8ZDSqC9qdnuiQ8Yuvu4/RYvmMRMqra5oAneJoGvmFsmtclMK/RIE8MaY cJSKPWqGgl8X6ycl8vhsvvhde25kem3DuC4ZZfvZHcKb3ZFke1656iCbrEeySSAB9E/H dAvxN/urxoD4mCaYCcPKGfpQ3EdAT4d0L6DlSZ2bcqCzP/tmp/SG3cV3l+XUJEkFsSdk 1nuzuYsNzMhN1EIJa/YfLlg/xqrVgNomi5CC3Czb0hM1TIpZ+4sXV+YHDAKiXp25JBoQ aQqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QsdM6aopx9gxxLgRRxYhXTLHWovYEZKaxBqN+pAsLlI=; b=5KwdimOrQ1ZGG+Dbf557bGvBsRWz91IVJaFLkhukgE1qNDumEcSpQsOYbziTpfYqbj F1PuOhClQhvTJvDAaRaFRmvd44iTaIF8rYU1/Xs2l6BBw70smUC6ArQkymEAccWWHUjg G6KJljJRtGuTHkClvnSM4Ek+AsYR2EK/quGAewRb5EuhxTwb9ukh7H69+EIQGio5azrO A703zte8ixFk87zwyiKL35d3hnci/XrDYCnYJ3hk/a9sau4jQLEKLpPFF9MzYGcQyoPY fJLsFLxPv6k7awRlObqTFPHs+sMvnG6eo8N1pzcZ3bp7S8mBObuCWZQwlvqxSHbsXOHr DQWA== X-Gm-Message-State: AOAM533+TxFKsUr1KNtCqCykmHO1i3SDoqpbxM5ZCyNoo0Jt20ima6aN L1QAulI/koD7+kZ9Z5kY6bM= X-Received: by 2002:a62:8855:0:b0:44b:8cc3:8f6d with SMTP id l82-20020a628855000000b0044b8cc38f6dmr2739498pfd.44.1632703862615; Sun, 26 Sep 2021 17:51:02 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id i27sm15032280pfq.184.2021.09.26.17.51.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Sep 2021 17:51:02 -0700 (PDT) From: Coiby Xu To: kexec@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org, Coiby Xu , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "H. Peter Anvin" , Eric Biederman , linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)) Subject: [PATCH 1/2] kexec, KEYS: make the code in bzImage64_verify_sig public Date: Mon, 27 Sep 2021 08:50:03 +0800 Message-Id: <20210927005004.36367-2-coiby.xu@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210927005004.36367-1-coiby.xu@gmail.com> References: <20210927005004.36367-1-coiby.xu@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Coiby Xu The code in bzImage64_verify_sig could make use of system keyrings including .buitin_trusted_keys, .secondary_trusted_keys and .platform keyring to verify signed kernel image as PE file. Move it to a public function. Signed-off-by: Coiby Xu --- arch/x86/kernel/kexec-bzimage64.c | 13 +------------ include/linux/kexec.h | 3 +++ kernel/kexec_file.c | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c index 170d0fd68b1f..4136dd3be5a9 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 @@ -531,17 +530,7 @@ static int bzImage64_cleanup(void *loader_data) #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; + return arch_kexec_kernel_verify_pe_sig(kernel, kernel_len); } #endif diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 0c994ae37729..d45f32336dbe 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -19,6 +19,7 @@ #include #include +#include #ifdef CONFIG_KEXEC_CORE #include @@ -199,6 +200,8 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image); #ifdef CONFIG_KEXEC_SIG int arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, unsigned long buf_len); +int arch_kexec_kernel_verify_pe_sig(const char *kernel, + unsigned long kernel_len); #endif int arch_kexec_locate_mem_hole(struct kexec_buf *kbuf); diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 33400ff051a8..85ed6984ad8f 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -106,6 +106,21 @@ int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, { return kexec_image_verify_sig_default(image, buf, buf_len); } + +int arch_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 /* -- 2.33.0