Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp540736iob; Fri, 13 May 2022 07:16:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxScGeMZENEOe8VzNvjB/jUcqFJ/WOUpNB188nERlFT8Sbw6adN07vrTjd6cfVLUqpwsnk X-Received: by 2002:a17:907:9606:b0:6f3:f999:ed82 with SMTP id gb6-20020a170907960600b006f3f999ed82mr4628460ejc.368.1652451364022; Fri, 13 May 2022 07:16:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652451364; cv=none; d=google.com; s=arc-20160816; b=fyBYraR7DJZOgNkiQYnZuOHPTs6/LLSYCYspggCGrcOX3u0VwNUWcilBxkP1X3x+Ad Pc4U33ELOYoyhvnhhuKMTx69txIO8Rj+LPixDbRcLaXZPs7qozEBfeSTkjSyx4Cwac3f lMkKc7Yxun0lPZjgz5ZGVt68W5v6qiLqANGP23rET6p+VVII9RSxMHfdLcSZiJ2nC743 sFjR4VgoNdhItrF7NpIVuZ1ock9H+QNx0D77tWSsluDf6jf7+mTp41xjE89vCB3gPXux Py+3kMltLgDxDYW6k6/7dWa5qOjFrmk5MfdcLS8Yu5LGTZzm9AOK5E/hAC24j1GiIDfb EEPA== 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=uLW+m9ur/lMSYv/hoja8jsAABTcjuU8qCpLCY/fAt6g=; b=YIxMxzXwsul6zXkX1durbKD9QxxCECrCgcdFeTdugLcv49y5UqG8BA/QIvrCIjOhub EpVTtmKLDI2x0EVlNG44m5pYI6kmfxPVMulo5QBYyEdZAaTw5+ynul3leNmPqUbvGiz3 AMTDLvvf7Zyj9qGm7+I2thB4KuAEaTQBjrdApyuHI0oLYFsiVlNUtNe3fjGVvMQ7zKGt Czt/oGpfDyf1TKeNI/XSGLs4lRIZb4hIDhGX4guSdGtXzdn4XCeHcAE6YlwbetDlDCb7 1pR1K7AyAmSQyxjuXplxqlvTzU48sto/bXMpdnnOw3dvkap2Sdp3+jMDrL9JuJTN+0vV IgXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BnL819ns; 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 gs36-20020a1709072d2400b006efc0b0d8ebsi2388832ejc.809.2022.05.13.07.15.35; Fri, 13 May 2022 07:16:04 -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=BnL819ns; 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 S1350933AbiELHWT (ORCPT + 99 others); Thu, 12 May 2022 03:22:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350940AbiELHWO (ORCPT ); Thu, 12 May 2022 03:22:14 -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 D184529805 for ; Thu, 12 May 2022 00:22:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652340127; 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=uLW+m9ur/lMSYv/hoja8jsAABTcjuU8qCpLCY/fAt6g=; b=BnL819nsa08uMt327s7SBzXbdPMMMQIQQCNoeIttf/kI49wnn86dcfW7J7SNYZIqyfwGCS aZrA6LKMIQ0dFSd8hP7ZjOYfs7GeH5GTcEEZUNm13h6My+qzye2HywM342FL12RQYUcf2x yb00T9CAXSYCNoBNi7I0NOZr7KhlT88= 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-524-mMkE9jedOmKW7IZwGNGlhA-1; Thu, 12 May 2022 03:22:00 -0400 X-MC-Unique: mMkE9jedOmKW7IZwGNGlhA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0AD5F382ECC0; Thu, 12 May 2022 07:22:00 +0000 (UTC) Received: from localhost (ovpn-12-247.pek2.redhat.com [10.72.12.247]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2FD35416363; Thu, 12 May 2022 07:21:57 +0000 (UTC) Date: Thu, 12 May 2022 15:21:54 +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, 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 v8 2/4] kexec, KEYS: make the code in bzImage64_verify_sig generic Message-ID: References: <20220512070123.29486-1-coxu@redhat.com> <20220512070123.29486-3-coxu@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220512070123.29486-3-coxu@redhat.com> X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 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 03:01pm, 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. LGTM, Acked-by: Baoquan He > > 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 > --- > 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 >