Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp869137iob; Fri, 13 May 2022 15:01:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBHCb8cpbDjRvTRF3945IuN86S5bZZzu8c8B61yt8Mm8krMbOXaTxgGgKTiXY6bDjLhBkj X-Received: by 2002:a17:906:1b1b:b0:6f3:9044:5fb4 with SMTP id o27-20020a1709061b1b00b006f390445fb4mr5909294ejg.763.1652479272949; Fri, 13 May 2022 15:01:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652479272; cv=none; d=google.com; s=arc-20160816; b=xGy886BNabda16iQZBE3wZ5OuK/rnEFkpXsfKUSQ6bqhUNpAWAKuQ80YlrB5+R9fxm jwwbIg3XXNt2x8WfyvaMS4D1iwF/6VdxePbloeRNuRqGKoDLUwwI9SEEwdqyqiwz0ibB 7TTTKJoLdPsp6gZhatZdBzkilbDkJJT5ghvsB2l9NhLjGZM94S638ycRPUCJNXTPkWoM ++8/ZHLVtiqxB6GPSbEZ6TrdPoIMWKLKI+wNsL843R75+7NgOvERE43o/ONMStwokqiH Ep9+tXoumyfH80KQSFlrc0D0r4t3KJMUFoUREE9whxACxcb9vjN7g1WETkfP3UfPD4jj x/Cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=EzuImZzUXRQk55j7AQx9zRKfVsHLp/8M2JdEt3xnOyA=; b=M9aVTtBzcvJfn8eTLG32iEkNbkeVBnoBF2dpPf+JiB/abEH8MahiLEe1M0HSpt2xFS +B5EnlBymcqrMzz7PMI49LFZNgKLGHsGwUIxcFCJ3+gH5hweRb7QmjNOuyh9p9S2iB/m Xxg6p89XkoNXoi1dYUokwPJDcbPKplPbnqmBluga+4s5x/UB73sMCtzretiQqmmJT+1O yffmFLGmWADNz8oH0RwOaJ84LZY0/vAidGUztQTsKfuD5cQ7WxXv5m6tGhPgKuCHYyjP PGuTaDOp3XD26U5oIBkH4p3AKp/m4PBs+qtdER3SkUqFJfQ5Stqfwoq8vZ2Xmm6g7Zqa Ekxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QVHmF9gP; 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 dp13-20020a170906c14d00b006e89f4b112csi3097622ejc.719.2022.05.13.15.00.46; Fri, 13 May 2022 15:01:12 -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=QVHmF9gP; 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 S243067AbiELCrJ (ORCPT + 99 others); Wed, 11 May 2022 22:47:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243042AbiELCrH (ORCPT ); Wed, 11 May 2022 22:47:07 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C2A0F3E0C2 for ; Wed, 11 May 2022 19:47:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652323624; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=EzuImZzUXRQk55j7AQx9zRKfVsHLp/8M2JdEt3xnOyA=; b=QVHmF9gPx8DMRK1OxyhX7jiEbbRrEJMMr4vJ8rJjmUSA6el3M1vtdNN08Mv0kvVgomQQXU XYnNr9hgtHRNF7EVX5f3BKTWCJLlCH8a+0A5xNCH8H2sVXpdBkt9zOUumS8YCY/cV92TMc 6BNfa2vIzn2K2chNbU+0aNYWluAuz7Q= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-449-vEHXaPuYOvumFqfq10WoPw-1; Wed, 11 May 2022 22:46:59 -0400 X-MC-Unique: vEHXaPuYOvumFqfq10WoPw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 87163811E76; Thu, 12 May 2022 02:46:58 +0000 (UTC) Received: from localhost (ovpn-13-226.pek2.redhat.com [10.72.13.226]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D96F62026D2D; Thu, 12 May 2022 02:46:41 +0000 (UTC) Date: Thu, 12 May 2022 10:46:37 +0800 From: Baoquan He To: Coiby Xu Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Michal Suchanek , Dave Young , Will Deacon , "Eric W . Biederman" , Mimi Zohar , Chun-Yi Lee , keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, stable@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" , "open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)" Subject: Re: [PATCH v7 2/4] kexec, KEYS: make the code in bzImage64_verify_sig generic Message-ID: References: <20220512023402.9913-1-coxu@redhat.com> <20220512023402.9913-3-coxu@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220512023402.9913-3-coxu@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On 05/12/22 at 10:34am, Coiby Xu wrote: > 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 makes 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. > > Note this patch is needed by a later patch so Cc it to the stable tree > as well. This note should not be added in log. > > Cc: kexec@lists.infradead.org > Cc: keyrings@vger.kernel.org > Cc: linux-security-module@vger.kernel.org > Cc: stable@vger.kernel.org # 34d5960af253: kexec: clean up arch_kexec_kernel_verify_sig > Reviewed-by: Michal Suchanek > Signed-off-by: Coiby Xu > --- You can put the note here, it won't be added to commit log when merged. Maybe it can be removed when merged. Otherwise, LGTM Acked-by: Baoquan He > 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 413235c6c797..da83abfc628b 100644 > --- a/include/linux/kexec.h > +++ b/include/linux/kexec.h > @@ -19,6 +19,7 @@ > #include > > #include > +#include > > /* Location of a reserved region to hold the crash kernel. > */ > @@ -202,6 +203,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.35.3 >