From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EFE36C433EF for ; Thu, 14 Apr 2022 01:51:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=erZVh7bzQX8JJMcYSrprSjkybSH7NJ4qacT6fvE5lyI=; b=WThvZDayyc1YQ1RV6nUhXhl6kB yoR1VAonVKUkBpi0z7b+HkhRl8cc095/lH7rM6teS/R6uUTkdbk+WmAuC4cf+CIoSbsaUzEnTLQjv SPybKEwNs8kCPwi6JBe62Vd4Xchlg1KCZAq1utXacVhIY5O9SFvszkeh8zaqNVOSd0ILc9JLhziZQ rAoGPJOW5JmbX7+yj93rSf4KCURaanUBikB5BSswamyFVFzbeLlv6GZmgQKAI3si+FPA8MkU5UYrC kkopNObHjnD5jlM3L5SK9E3GCLk6VVz4vmOPc/ZBZmgWt29/ZE78alKVEhOb0SpuK6V4dKpcVvu/C bnC3Y+KA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1neocq-003Kzm-DQ; Thu, 14 Apr 2022 01:50:26 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1neoci-003KxS-QU for linux-arm-kernel@lists.infradead.org; Thu, 14 Apr 2022 01:50:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649901015; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LbIFt/hLvdmgH3emaym9nt7Eav8nywDFZBlv3s8K7FA=; b=B0U81MKWdYdR+ct83RL0WXqDgaCf3o3037cTqkwHl9lRhgyYEHHMJMVpLtTycYNrdbq99Y BaOSlCOUYG/Ikvqq5FADb6G0QFHR03JuFhgswvZwl/VqMEQ75uIfemiPY3Xg+FZyZLpXfU IKhnV1PH5UPlGA9IyURKE2ATsgq0x8c= Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-314-EilTCC0uPAmkKzSS5IYsFA-1; Wed, 13 Apr 2022 21:50:14 -0400 X-MC-Unique: EilTCC0uPAmkKzSS5IYsFA-1 Received: by mail-pg1-f200.google.com with SMTP id r15-20020a63fc4f000000b0039d0f8f0793so1964618pgk.22 for ; Wed, 13 Apr 2022 18:50:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=LbIFt/hLvdmgH3emaym9nt7Eav8nywDFZBlv3s8K7FA=; b=sVAx2P1iN6xwtftDa92DfxBRACQWbUhox7lWPRMuOU+2uTH3rQYXw1RrU7AsmobHMs UL8PRJU6uoUg1lAPDz6fhyFSngkWFIgIHDDIVuO/Eo/DgyjG0QaNxEvAZI0rsLgOh4+K G3jxa2yJA/FH3oTIByG4eIA9l9LrUxu8QRig8FPtVt64lHe5diyTdi9PgtayYNNl6p5r E8czjbEe0O2j+oQxIxKc8nGmNtN2U4eo6hOTUhm38J0Yrld57+Gwmu44gjEqm3G3SErr Nw8lf0poNYKu9CxtHcXAWPqPstRFnN4zTlvhh3L4vR48gZakbHsAybBLbhYBfdODbjgw 0w1w== X-Gm-Message-State: AOAM531kJIbiPzF8EkGjWhGrsuxaLjFWwQTrbxtDGyOw+Vu1TK7faIcu Hd/qzOQu+EpGyn56xb3Rjamac9jWFu+0pFBlcXRQzmz013rCiu2jufmSqTXHk2V5K5Eja8KwJcu JCU5fdCrmOMrnBD+xiWFK23U6OhawrF6Ce1s= X-Received: by 2002:a63:1725:0:b0:39d:7957:7396 with SMTP id x37-20020a631725000000b0039d79577396mr391342pgl.156.1649901013276; Wed, 13 Apr 2022 18:50:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxy8B6dsOxZIo58DE4+eOkMN6SM4w55xIwVO/TCzGYn0DvJ2qrUhkiBU4XfrhpTrC/j2yzOSA== X-Received: by 2002:a63:1725:0:b0:39d:7957:7396 with SMTP id x37-20020a631725000000b0039d79577396mr391315pgl.156.1649901012971; Wed, 13 Apr 2022 18:50:12 -0700 (PDT) Received: from localhost ([240e:3a1:31c:360:52fc:c968:cb41:efbc]) by smtp.gmail.com with ESMTPSA id y3-20020a056a00190300b004fa2411bb92sm345861pfi.93.2022.04.13.18.50.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 18:50:12 -0700 (PDT) Date: Thu, 14 Apr 2022 09:46:05 +0800 From: Coiby Xu To: Michal =?utf-8?B?U3VjaMOhbmVr?= Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Baoquan He , Dave Young , Will Deacon , "Eric W . Biederman" , 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 v5 2/3] kexec, KEYS: make the code in bzImage64_verify_sig generic Message-ID: <20220414014605.etdihzqs764v74gf@Rk> References: <20220401013118.348084-1-coxu@redhat.com> <20220401013118.348084-3-coxu@redhat.com> <20220411085411.GZ163591@kunlun.suse.cz> MIME-Version: 1.0 In-Reply-To: <20220411085411.GZ163591@kunlun.suse.cz> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=coxu@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220413_185016_979593_F82765BA X-CRM114-Status: GOOD ( 19.65 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Apr 11, 2022 at 10:54:11AM +0200, Michal Such=E1nek wrote: >On Fri, Apr 01, 2022 at 09:31:17AM +0800, Coiby Xu wrote: >> The code in bzImage64_verify_sig could make use of system keyrings >s/could make/makes/ >> 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-b= zimage64.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 kerne= l_len) >> { >> - int ret; >> - >> - ret =3D verify_pefile_signature(kernel, kernel_len, >> - VERIFY_USE_SECONDARY_KEYRING, >> - VERIFYING_KEXEC_PE_SIGNATURE); >> - if (ret =3D=3D -ENOKEY && IS_ENABLED(CONFIG_INTEGRITY_PLATFORM_KEYRING= )) { >> - ret =3D 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); >> } > >Maybe you can completely eliminate bzImage64_verify_sig and directly >assign kexec_kernel_verify_pe_sig to the fops? > >Other than that > >Reviewed-by: Michal Suchanek Applied, thanks for the suggestion and reviewing the patch! > >> #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_i= nfo *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 *i= mage) >> } >> >> #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 =3D verify_pefile_signature(kernel, kernel_len, >> + VERIFY_USE_SECONDARY_KEYRING, >> + VERIFYING_KEXEC_PE_SIGNATURE); >> + if (ret =3D=3D -ENOKEY && IS_ENABLED(CONFIG_INTEGRITY_PLATFORM_KEYRING= )) { >> + ret =3D 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 >> > -- = Best regards, Coiby _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel