Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp988463iob; Fri, 13 May 2022 18:44:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy83bzmdx362JMa1x3cVcx34/lUZl+Mhpo8bGQFqOftwl+jUmTtmWomdQk9kkggPta6VGTR X-Received: by 2002:adf:decb:0:b0:20a:c975:8eec with SMTP id i11-20020adfdecb000000b0020ac9758eecmr6102132wrn.438.1652492680424; Fri, 13 May 2022 18:44:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652492680; cv=none; d=google.com; s=arc-20160816; b=WP65ZCZJHriGS3+UxqQ24FvZLSO5I7FBx/TOwEKwbGRIGwvLHOG+yWPDb2rP1NuFdp FXXGAU6dB2o363ZwDBMnVzf2YqoWAFtRT/fXtquww9ajwl4RhNNHA/6cYL6g2k+Lzgwl nudQAgkKKDhTVMa1CSta2EJpO4OiVqKoQ6mMGowf94AXEtOiJ+5W7xTuijJdbnB8F9LH 2yKe5d2/KSUluzTwDI8hMYCRhXzeyLSNw7SghvxcjsDbmKVfh4CysC+FkYfJbqpcXnCq kRrRd0OjDcEp6CE9bESDK3396Nr6NODM9opW/K8+t44lJaauFo89xO0V6sh2YGEwl7RT ywjA== 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=2SKwInTDfwSjGYjczGeCpjDqlYEJ6dRe4uToWw6mvPw=; b=VpPx/MsXj6vRq2LZdhSK6KRU+Gf+JPbq3s9UHEO1nL8iRCmeOl/Jwfpn/0tIrACcJy aAH+NtvBMURPGruY8jn32zZYkMDBVEE3wxIFNLQ6pARLWXjvHrtxEwfDtxXeGqQO5seZ N8M+EQHue4GpAdAdfsPrpzcQF+2D/QZKf6GMqbAUCU94AkKDjf8puLfLE/TQL3LeBsR6 0EIPKuay01kKOllLjSf9suAf4YM4rslWpnlO1Cw7UxswHN/f2lEFl4DTylg2j+fV60Tn T2uTLm3QOwq/gmIcUxidb2dzC0bmeft1KxokFwN0iQRQi/8pN+TLqp8LYcL89/VPLkFm hcFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UDF1KfRN; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id a1-20020a5d4d41000000b00203e901958bsi3350256wru.783.2022.05.13.18.44.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 18:44:40 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UDF1KfRN; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BD3AA433C13; Fri, 13 May 2022 17:10:01 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344941AbiELDwf (ORCPT + 99 others); Wed, 11 May 2022 23:52:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345010AbiELDwa (ORCPT ); Wed, 11 May 2022 23:52:30 -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 9992436153 for ; Wed, 11 May 2022 20:52:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652327548; 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=2SKwInTDfwSjGYjczGeCpjDqlYEJ6dRe4uToWw6mvPw=; b=UDF1KfRNeGvrYoOD8wv7fmMcDRc1EtnO6AyKfqYixDbTy4CRYqBiXJd3BdKFiGOOm6VCqo +Mq23A+YkJAqaWJe+acduxGQVCepZHdszMZIKv1XDjg6bQrjPnWftzIrcZ0iyZW7Ui/rhF C2QNcwBT1B1+miFpow9/bLsbatV7xrA= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-644-ZhHGqITBNHqD11DJywYAPA-1; Wed, 11 May 2022 23:52:23 -0400 X-MC-Unique: ZhHGqITBNHqD11DJywYAPA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F2F173C01D99; Thu, 12 May 2022 03:52:22 +0000 (UTC) Received: from localhost (ovpn-13-226.pek2.redhat.com [10.72.13.226]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AE0491121314; Thu, 12 May 2022 03:52:12 +0000 (UTC) Date: Thu, 12 May 2022 11:52:09 +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: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_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:46am, Baoquan He wrote: > 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 Hold on, should we CC stable when it's not fixing an issue? Hi Coiby, Just to make clear , is this patch fixing an issue, or it's just an preparation for later patch's use? Or I should ask in another way, any problem is solved with this patch? > > 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 > > >