Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1816951pxb; Sat, 2 Apr 2022 04:49:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+JfFlq5pMrHl/Gup/5L5nsxFOFyVuJbeHMnEemx3uf/19hL1AJZuu32J83pZ58L9Xl2hb X-Received: by 2002:a05:6402:6da:b0:3fd:cacb:f4b2 with SMTP id n26-20020a05640206da00b003fdcacbf4b2mr24857670edy.332.1648900162841; Sat, 02 Apr 2022 04:49:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648900162; cv=none; d=google.com; s=arc-20160816; b=VGInFNDC9ju2S5fDoK/YD4BclPQENNMI2c9m9h3n2iP2EN5fT5aHioSp8/45bSw6Jn cTT5hAAgTBaq8mJfB5upgKAH3+65E2GQqd/ObRuS5y23oknnMcpBaQ9LxtknHwagsMjT 3UEfZk7e8+1392HJNHo/iEbHs0Yxe9s47+S3w366t8OnQI6l4E4fENS0CwU4gfAvwmXy C0iAHysqHsGRhhDH4NSz6OH5s6Qr+GA4w1PB1iC+jdw4ZeHveadEzt+ZqpCAhQ+drfk2 atlfedi9SzEdSDLVEnMolSYH/jB7KNHT0aENU6AWSCMKQ7xsaTLR0i1t13XWijOnMSwM Izfg== 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=XVmPCPO0oF3pRYu+F7qpHdcQzaq88pJ0kcN8pmyvV4M=; b=EBSOZxr6JjKF3zCMJqs6/yNAaObxmnyiycanxrbQmJpHXSy3KBlt9elMbig8t76gHF 66NjfmPd/2ckPZLi3OvQlLBEGBIrlyf8YlaXyGs2HkawglGtbf/DAyvZ4IMqR17rcAve xM6tPkI6g92yYaDes/u9Zb43+dPJOByEXZ2r/g/pR2mzRYDkEbdIcq6AonPFcpND8EmU alcKOeahdgv3iTQOabT5CPnknX7vPj95RRWYN51tKB9JDN6GvQpdiNL9TiGoOcZeDtjC DsUttPN4j1ECc2yh+9O1dD3U1yN6Nf5xPxnK0Fuz1ctmZSC6jMYXqpNKf1lZcMaBH3vf DZeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=D+LSA6SE; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ay9-20020a170906d28900b006e14834bb6bsi3274495ejb.279.2022.04.02.04.48.58; Sat, 02 Apr 2022 04:49:22 -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=@redhat.com header.s=mimecast20190719 header.b=D+LSA6SE; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243755AbiDABdX (ORCPT + 99 others); Thu, 31 Mar 2022 21:33:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243749AbiDABdU (ORCPT ); Thu, 31 Mar 2022 21:33:20 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 711881EC63B for ; Thu, 31 Mar 2022 18:31:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648776691; h=from:from:reply-to:subject:subject: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=XVmPCPO0oF3pRYu+F7qpHdcQzaq88pJ0kcN8pmyvV4M=; b=D+LSA6SEubz6jrEXxyxhlxgA0vSOLveHLHyYHkJjaMb2VX6I/wOaIEixfS9NUNfBYOB+IZ FnAE9Q9HwzcKN3aOc3+5aKc42X8WHnKsiuID4gxJXVaDV3+xxi0zVkaViJmx+W8WM5lVTx gN8FQun4vVPIBYDv1/c0qKGFkgDspXM= Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-102-DNJHqsv9OAmkOx7bStQSYg-1; Thu, 31 Mar 2022 21:31:29 -0400 X-MC-Unique: DNJHqsv9OAmkOx7bStQSYg-1 Received: by mail-pj1-f70.google.com with SMTP id oo16-20020a17090b1c9000b001c6d21e8c04so2815587pjb.4 for ; Thu, 31 Mar 2022 18:31:29 -0700 (PDT) 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=XVmPCPO0oF3pRYu+F7qpHdcQzaq88pJ0kcN8pmyvV4M=; b=KXGaOH5zHvllRU/82zrhYHInKAXtOv+nPAzaZYt4e4Bg1/aUWV+GMcZ6MtnPJYHqE/ Nxk+3yIDgv+Wj2c3O5QjqO8WBPDdY06qNdwDL3CKSCZ4M+UMsiiDzJBgtzzAg8tn87L3 f8f+sBvZ5FzuS18uaWSXewHWHFPiHLN9qoG52yWNCbaglUeAIEODoKaFmRd820yqW5g7 VmXIYx9XeRd3xVn4f3kvlzL6rhQsC8zOJuJhJOk/W1vs7HXghmlAnJqlBLeZEjtqmv4b roBgUurVvf9lPo6W/5AIreKwLBDpvp/NAFRdkQSkoQ98QZ8vvpEDWdYrkizrTV3MzzXr sGog== X-Gm-Message-State: AOAM533yPMZFqVb45a/XNNKd4eIk1kYBudqqEU0fhZfiIMqz2waXockz cKTjtCazWE5HTo25Dn9wP/A+7oAuEtzPTC/ZI+0dbqmKVIeD4MZkvkDDjOUbn3bo/wiylSXhGWX Ms27y3gLQ+dXRglZ7b5tCFJ92 X-Received: by 2002:a17:903:20cc:b0:154:8c7f:1ed3 with SMTP id i12-20020a17090320cc00b001548c7f1ed3mr7854398plb.131.1648776688284; Thu, 31 Mar 2022 18:31:28 -0700 (PDT) X-Received: by 2002:a17:903:20cc:b0:154:8c7f:1ed3 with SMTP id i12-20020a17090320cc00b001548c7f1ed3mr7854375plb.131.1648776688014; Thu, 31 Mar 2022 18:31:28 -0700 (PDT) Received: from localhost ([240e:3a1:31c:360:52fc:c968:cb41:efbc]) by smtp.gmail.com with ESMTPSA id p34-20020a056a000a2200b004cd49fc15e5sm759358pfh.59.2022.03.31.18.31.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Mar 2022 18:31:27 -0700 (PDT) From: Coiby Xu To: kexec@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org, Baoquan He , Dave Young , Will Deacon , "Eric W . Biederman" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "H. Peter Anvin" , linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)) Subject: [PATCH v5 2/3] kexec, KEYS: make the code in bzImage64_verify_sig generic Date: Fri, 1 Apr 2022 09:31:17 +0800 Message-Id: <20220401013118.348084-3-coxu@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220401013118.348084-1-coxu@redhat.com> References: <20220401013118.348084-1-coxu@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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 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. Make it generic so both x86_64 and arm64 can use it. Signed-off-by: Coiby Xu --- arch/x86/kernel/kexec-bzimage64.c | 13 +------------ include/linux/kexec.h | 7 +++++++ kernel/kexec_file.c | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c index 170d0fd68b1f..f73aab3fde33 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 kexec_kernel_verify_pe_sig(kernel, kernel_len); } #endif diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 755fed183224..2fe39e946988 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -19,6 +19,7 @@ #include #include +#include #ifdef CONFIG_KEXEC_CORE #include @@ -196,6 +197,12 @@ int arch_kexec_apply_relocations(struct purgatory_info *pi, const Elf_Shdr *relsec, const Elf_Shdr *symtab); int arch_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); +#endif +#endif int arch_kexec_locate_mem_hole(struct kexec_buf *kbuf); extern int kexec_add_buffer(struct kexec_buf *kbuf); diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 3720435807eb..754885b96aab 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -165,6 +165,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.34.1