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 518C4C433EF for ; Mon, 18 Apr 2022 05:46:25 +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=oJSYqWngUvxqRxEu+WVBbcqQXAmB75ZR57ptZCEuruw=; b=yYTjSwOQm/7fNT+KFRV1Y4q5FG jSBFjnpaXW8oEfQ55IWw0nG4KZjwNA5YCMQWWStfiMX9NLqbMYyS7vqlMeOgDI3lycLByD/kdoaQS d7DMhSQDk3DfxG9fb7Dlt6Cc2vCFcm5QrrOY8jdfgWaezHsqWaSrRWAfsa9JBR7EknP/0s4C5Pazv WfXE6X78PGoOtXM30yDd7vSR0of02VgKEpo4gf5YMZdWtE3TE3HyPrpt9efYowXVFehak+sdCWZ06 bZV9G0lfVhz5nShkDV7EWlmx5qahc8SzPuwKljz8Fo2PxaVNjlpKRDxnRKmOboL5S/fIw/4jIosYh EPlsDlhA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ngKCQ-00Fidf-Bb; Mon, 18 Apr 2022 05:45:22 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ngKCM-00Fibr-7i for linux-arm-kernel@lists.infradead.org; Mon, 18 Apr 2022 05:45:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650260715; 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=T1o3lDkKjJ1ubV1pkELZ5kYo2o2QIP5NYLC4ArKgbfs=; b=D6+XQqCmktxZNdiS1ByskyCGTgEhDXVMnRiSeQhVeudZrf/SH0O2DzTwiG9INtFpuZVjM3 ffmiNwZoXtGyhxKZRs4s1wpbVYGyhDuGxB8bmRdxOZbkP7G+iw51lCCxSWHZZEPHOuN5Vl ZJGuBXiffrVoQuG1M1ewR2yUe3I+7p8= 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-631-LURn3nSYO0Sl226bGvbmOg-1; Mon, 18 Apr 2022 01:45:14 -0400 X-MC-Unique: LURn3nSYO0Sl226bGvbmOg-1 Received: by mail-pg1-f200.google.com with SMTP id c32-20020a631c60000000b0039cec64e9f1so8254501pgm.3 for ; Sun, 17 Apr 2022 22:45: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:in-reply-to; bh=T1o3lDkKjJ1ubV1pkELZ5kYo2o2QIP5NYLC4ArKgbfs=; b=IyEfWByJ9ArTBrFiBZCU6aNLW2cSrUb9ftr8fW3s0Bo2Y3drahdc0df27V8zIJe2YO lwyl4OX0iKBvwAB+aNujMehojr3VEbnVFnMqsfe614mO1WTmV1fEiheMLgQJnm9WFTy5 JYKPOz0Hdk4Y2GdHnah9ArdRLtDguwdbIexGDbMaO6jvgoCmgpnOoL1kEr7gVypiFt1I w4rC5F8rHpsOMuh+XCvWljWsw7nKYIyoBMXR7ewtOdrsJh7yD1ziMMMwlJuNvVUy2Z1o jhg9HxhKOxaqB6wrKd+XqUQeh3W6V4UlGAVR4BxV0/qeRUhhkNQxs5JScWTfO6nmXlXx WRsA== X-Gm-Message-State: AOAM533ksSfwHYP+s141lTy3wssE1mEjvGdnY+XPjtJLJFTE/22XreLF kw/CCImS163ZgnJqyiRxctqTb0f6HjInYGFKIInxZBCZ6tvHJNMnzOvG3kg7KrM1AW7HSex8oed 8KCUG1bhS5Vsykxp2CyodCttqNlwJakZtw8o= X-Received: by 2002:aa7:9110:0:b0:4fa:e388:af57 with SMTP id 16-20020aa79110000000b004fae388af57mr10410818pfh.1.1650260713598; Sun, 17 Apr 2022 22:45:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymR0oZfWlFYrAEf8qnTbPoW8P8tQF737+NvuBY9kYfxQXTP0JBlH5CEWGh43eAvxmeN/jnaw== X-Received: by 2002:aa7:9110:0:b0:4fa:e388:af57 with SMTP id 16-20020aa79110000000b004fae388af57mr10410797pfh.1.1650260713196; Sun, 17 Apr 2022 22:45:13 -0700 (PDT) Received: from localhost ([240e:3a1:2e1:fc30:496c:36d3:5798:d144]) by smtp.gmail.com with ESMTPSA id p17-20020a056a0026d100b00505ff62176asm10524875pfw.180.2022.04.17.22.45.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Apr 2022 22:45:12 -0700 (PDT) Date: Mon, 18 Apr 2022 13:42:37 +0800 From: Coiby Xu To: Baoquan He 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@kernel.org, Thomas Gleixner , Yinghai Lu , 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 v6 2/4] kexec, KEYS: make the code in bzImage64_verify_sig generic Message-ID: <20220418054237.2rjt357op5nhttvk@Rk> References: <20220414014344.228523-1-coxu@redhat.com> <20220414014344.228523-3-coxu@redhat.com> MIME-Version: 1.0 In-Reply-To: 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-20220417_224518_376584_8022429D X-CRM114-Status: GOOD ( 23.51 ) 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: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Apr 18, 2022 at 09:53:32AM +0800, Baoquan He wrote: >On 04/14/22 at 09:43am, 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. >> >> Fixes: 278311e417be ("kexec, KEYS: Make use of platform keyring for signature verify") > >Will the code in bzImage64_verify_sig generic not being genric cause any >issue? Asking this because I don't get why making code generic need add >'Fixes' tag. Thanks for raising this question! This Fixes tag is for the problem as described in the 1st paragraph of the commit message and making the code generic is the solution. But if I misuse the Fixes tag, I can drop it. > >> Cc: kexec@lists.infradead.org >> Cc: keyrings@vger.kernel.org >> Cc: linux-security-module@vger.kernel.org >> Cc: stable@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.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