From patchwork Thu Apr 14 01:43:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coiby Xu X-Patchwork-Id: 12812824 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 6CE13C433EF for ; Thu, 14 Apr 2022 01:45:33 +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-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=O9GBqdb6ersbhMsz7vsBNaTvA+zPO3VbAv3CeM69C1U=; b=mNPiIZFDTsFhai 6uLphCC/PMO7wp3n615oUN2+VXkMtlscnv4hUg0D+j255iR2OVxclQknLWSVntW62xWNqmpPpQwad DO1E7+pKjUmY/gZ6OckwplpM/8fSVqcojHKcGW9BvXdyYPO2a6NiD43IWqLKpzoMrhhpFbhoatgRL WJi2wnupFrfSrn9R786hj0P+WWfEjGvXapmU/UQ6wQXZPLh+gjeCYrCqCBcGxADKmhz/0xDIXJ8U+ IcWjMYHY8qHwZAwIVQP8j91xgJwL8qVa4BEWJ4/Xnv0UxLUQL4P+8d60EJPvzuG9fyFyZQUin8KXP ajDla8qAg62tffA8Wltg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1neoWp-003Iq7-Bp; Thu, 14 Apr 2022 01:44:11 +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 1neoWj-003IpE-JA for linux-arm-kernel@lists.infradead.org; Thu, 14 Apr 2022 01:44:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649900644; 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=jUo4znEOkRrWRs1sMxG9XXTvdlj/WDC4ky0CeyyLoSA=; b=Br6z+Yibw/BakuG+DPVvkib2e+usT2a5k/Iv4Pm4MBgF+5vsnpbE4YLQcYlLG4iiEPK8yc DKW6zPpnZ5I8nVyAp6H4DiJux0S+dqLT/yEy6r2UtXYYXvA1Ld1ozn0/R/QecXPW0Sf6Jk /BBmZs8ngtT1CrGBsqCw6ZmwNh4NYKs= Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-646-tUnTvj6bP22LtLH_xENrkg-1; Wed, 13 Apr 2022 21:44:03 -0400 X-MC-Unique: tUnTvj6bP22LtLH_xENrkg-1 Received: by mail-pg1-f197.google.com with SMTP id h14-20020a63530e000000b0039daafb0a84so1978611pgb.7 for ; Wed, 13 Apr 2022 18:44:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jUo4znEOkRrWRs1sMxG9XXTvdlj/WDC4ky0CeyyLoSA=; b=8HCo7oop7e5Aqm8KWx/HmoyGhtL09gF2kzjWI7jeHLhM1PcZdAAe/JzRO0z9HXKnah C7qm73OHho8S3XcLov0jr6dS+Bix8Q0gsFiZyQfWGRdtyJRPq8eoJWswumsyPnO7pImy SUFYQ9SLlJUKhit7w3Xx6LDLL938KjzzgXZwo7FyGdyDUVgi7AEg4pWhfWNI4kO9CMcl YVpIH6g5A/mZFuzuZMs43JuLo9dt3MR5fZ5yIkCVwTrogaw4dysdRreFYTzXOiIs1ky0 jzH+S094tY5wIfRvjyHoKTlHI93+iAdKr48qURl5sAG6wGFuqE1VwCKGuVIKFeiwzsyD oN3g== X-Gm-Message-State: AOAM532/dqVWIDiHmh7R6x45PsRYNbHLm3Uts2wJSHVlD8QzD0BQPvtH cZBPSqFZIiCpHmKguVDCzz8inw1BP6QX7SfU+Pq0Dz+oqgV4iFMo2HPdW3kF9b9f0XM6P5XVV/1 QA+tyDch0Sxdkz4SBN2K7dUFIP1gMnoqwVA8= X-Received: by 2002:a05:6a00:4211:b0:506:5061:3e38 with SMTP id cd17-20020a056a00421100b0050650613e38mr1591776pfb.74.1649900642600; Wed, 13 Apr 2022 18:44:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPUPsdDaV0SaXNU950qh/kHth5bPSWxu8nmDnhrsKNKGWJouIJSJ3+yN9qcKr5KVKvb/41OA== X-Received: by 2002:a05:6a00:4211:b0:506:5061:3e38 with SMTP id cd17-20020a056a00421100b0050650613e38mr1591763pfb.74.1649900642367; Wed, 13 Apr 2022 18:44:02 -0700 (PDT) Received: from localhost ([240e:3a1:31c:360:52fc:c968:cb41:efbc]) by smtp.gmail.com with ESMTPSA id ml1-20020a17090b360100b001cd40539cd9sm311141pjb.1.2022.04.13.18.44.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 18:44:01 -0700 (PDT) From: Coiby Xu To: kexec@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org, Michal Suchanek , Baoquan He , Dave Young , Will Deacon , "Eric W . Biederman" , Mimi Zohar , Chun-Yi Lee , stable@kernel.org, linux-kernel@vger.kernel.org (open list) Subject: [PATCH v6 1/4] kexec: clean up arch_kexec_kernel_verify_sig Date: Thu, 14 Apr 2022 09:43:41 +0800 Message-Id: <20220414014344.228523-2-coxu@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220414014344.228523-1-coxu@redhat.com> References: <20220414014344.228523-1-coxu@redhat.com> MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220413_184405_943165_74F33C5F X-CRM114-Status: GOOD ( 13.88 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently there is no arch-specific implementation of arch_kexec_kernel_verify_sig. Even if we want to add an implementation for an architecture in the future, we can simply use "(struct kexec_file_ops*)->verify_sig". So clean it up. Suggested-by: Eric W. Biederman Cc: stable@kernel.org Reviewed-by: Michal Suchanek Signed-off-by: Coiby Xu Acked-by: Baoquan He --- include/linux/kexec.h | 4 ---- kernel/kexec_file.c | 34 +++++++++++++--------------------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 58d1b58a971e..413235c6c797 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -202,10 +202,6 @@ 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 -int arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, - unsigned long buf_len); -#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 8347fc158d2b..3720435807eb 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -89,25 +89,6 @@ int __weak arch_kimage_file_post_load_cleanup(struct kimage *image) return kexec_image_post_load_cleanup_default(image); } -#ifdef CONFIG_KEXEC_SIG -static int kexec_image_verify_sig_default(struct kimage *image, void *buf, - unsigned long buf_len) -{ - if (!image->fops || !image->fops->verify_sig) { - pr_debug("kernel loader does not support signature verification.\n"); - return -EKEYREJECTED; - } - - return image->fops->verify_sig(buf, buf_len); -} - -int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, - unsigned long buf_len) -{ - return kexec_image_verify_sig_default(image, buf, buf_len); -} -#endif - /* * arch_kexec_apply_relocations_add - apply relocations of type RELA * @pi: Purgatory to be relocated. @@ -184,13 +165,24 @@ void kimage_file_post_load_cleanup(struct kimage *image) } #ifdef CONFIG_KEXEC_SIG +static int kexec_image_verify_sig(struct kimage *image, void *buf, + unsigned long buf_len) +{ + if (!image->fops || !image->fops->verify_sig) { + pr_debug("kernel loader does not support signature verification.\n"); + return -EKEYREJECTED; + } + + return image->fops->verify_sig(buf, buf_len); +} + static int kimage_validate_signature(struct kimage *image) { int ret; - ret = arch_kexec_kernel_verify_sig(image, image->kernel_buf, - image->kernel_buf_len); + ret = kexec_image_verify_sig(image, image->kernel_buf, + image->kernel_buf_len); if (ret) { if (IS_ENABLED(CONFIG_KEXEC_SIG_FORCE)) { From patchwork Thu Apr 14 01:43:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coiby Xu X-Patchwork-Id: 12812826 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 D3B66C433FE for ; Thu, 14 Apr 2022 01:45:41 +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-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9hXatwLDNgp12+RoNZHE8VRxY2PDqy//C3Y8ShpqoUo=; b=tJKaFhd2zSAdsl gmBxvLhcriju7JMvQWgdYzZVJGdHMf29ZtOMXr0hsIr+UGbljMJMhJgo2VqwfD6g7h+DLCcn95q1c +2jpDckexvObC68rRvK1mp3Yq+MLw3zuIJRbTgLttO0F9htaAajLNrw50vrGmyt1CQE93AmT0BHw8 EF3iEFzTolfYE53piCcfQx8BFBApjXOlHNuPbG67pQIeTKyh/rYMoHhQPoRKGIBHbNBPRXDagvVD7 iQSl1woHULIkAlc1QIGV1FDpAtsxWu3hyxGqBFDxKKXPky4c+yIyqzGNRSKs+UYzrPihUUI3WEOzX S975Np1RoTc/WTmsE8GA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1neoX1-003Iuh-Ii; Thu, 14 Apr 2022 01:44:23 +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 1neoWt-003Ire-Gz for linux-arm-kernel@lists.infradead.org; Thu, 14 Apr 2022 01:44:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649900654; 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=Vd6dGinkDQ+ERZGbhh7LGheOUAL1/G4cOFfIvwcXv0w=; b=BVHmC67+SytWMC5QtwCbzw0ozxyQc95k+IPR1uGj28YbwxJ+NjFhQu9QO2cA5zodsiMv1s Lq8Wipdli10mowvbKoeO1WPWbyGdy10KI9XIJMra5thxAw/WyWpErqpR8h6TdJc2EHK7BB QhDg7g9zf5s/H+GG/jQgyfJ4aX/EN8w= Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-259-xHIsgq3sO7mtaLEw4inZww-1; Wed, 13 Apr 2022 21:44:13 -0400 X-MC-Unique: xHIsgq3sO7mtaLEw4inZww-1 Received: by mail-pj1-f69.google.com with SMTP id p14-20020a17090a348e00b001cbc57fedc1so2250586pjb.3 for ; Wed, 13 Apr 2022 18:44:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Vd6dGinkDQ+ERZGbhh7LGheOUAL1/G4cOFfIvwcXv0w=; b=mdEw9PvGK1GB1wF9bzdonw31TN/PSc1NeLbw+8AD46DhOiia+cZwhiXln5+kwIuC2k H6wBYhwWbuSuHTWj48t2ie3yccoktrIzXTuBEMNNNAbAIciA4zLSCEn50l4KCI4ZeO7o FfInk6+OukS9YDSQYWHwDbZbcJGv1VprSiHE14rb1JwPQi18PoA4KACqGNQLcvro+oq2 eVcAsyH/DBc4d+zYUmDxCa22uRxn79Wwe2y5pXVJ3ShPnqq/DhbW23ODjMJQ1AgMbfsg xm7W6qaWM6Ppnaxfl2MWCqYGhyIXTNDoZX+qrIAJNRtKBu/q8dI1/Wx4a+T27Y2hN2Ec V6jA== X-Gm-Message-State: AOAM532K9MyWbbXZFxkSudLsVygHDsnNwyBAn1QD0W7psKGO7m8IYiDP w9r5zYIW9gqYHnMfOTEH+7aTNj6y5DTFVKTIKnpbWwpHIqOPfYfqoh3jgUAm3bE0M+wOGw7PDVQ J71GgJau7ocBQBlMKOj4hRD9yGzAvA7qLFBU= X-Received: by 2002:a17:903:124a:b0:154:c7a4:9375 with SMTP id u10-20020a170903124a00b00154c7a49375mr44981230plh.0.1649900651071; Wed, 13 Apr 2022 18:44:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSgcCqZWhETgn3SMmtU4LkqvxAQAdH4WIMasH4oGV8IV/wkQ4upyzvRDsL1mE0nxbO0jb+sg== X-Received: by 2002:a17:903:124a:b0:154:c7a4:9375 with SMTP id u10-20020a170903124a00b00154c7a49375mr44981222plh.0.1649900650830; Wed, 13 Apr 2022 18:44:10 -0700 (PDT) Received: from localhost ([240e:3a1:31c:360:52fc:c968:cb41:efbc]) by smtp.gmail.com with ESMTPSA id b12-20020a17090aa58c00b001ca977b49d5sm295456pjq.31.2022.04.13.18.44.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 18:44:10 -0700 (PDT) From: Coiby Xu To: kexec@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org, Michal Suchanek , Baoquan He , 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 , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "H. Peter Anvin" , Kairui Song , linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)) Subject: [PATCH v6 2/4] kexec, KEYS: make the code in bzImage64_verify_sig generic Date: Thu, 14 Apr 2022 09:43:42 +0800 Message-Id: <20220414014344.228523-3-coxu@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220414014344.228523-1-coxu@redhat.com> References: <20220414014344.228523-1-coxu@redhat.com> MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220413_184415_685898_85EF063C X-CRM114-Status: GOOD ( 16.14 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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") 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) { From patchwork Thu Apr 14 01:43:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coiby Xu X-Patchwork-Id: 12812827 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 3BAC1C433EF for ; Thu, 14 Apr 2022 01:45:53 +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-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=j2UaAbuqN0GhbTFxE5THJ07NeZpzhcmUUUoz9Ia0jdc=; b=rg14m5zdwiFLUu J+5aBkHkE7entUl2lGOHPHGae5bOhfihaiBIGfT8+tzPCUvknfJpCR/fQnyDoATHSFU1vxIX0ahKx sxJkXJny1RQJE70NWFBo2rOaYKEk3eIIzvP2Dr0bbXHHelb0C3l1LcSX8xiwR4w8olcH3d48eX9ax p1zbS4R2UrlSLj4I3LyU9Exyl9Wc2aeZu4AomUaG8YBJWVg7iEGmU/+uYiUKfkZlxc3VzCLgTlmRJ /3ZEgWGavSHQNHND4x5Ez+jlqB7oBMjZ3cab6skHYmEZNWm4CTdu1w7wlyqrR5NUcJDsXSmtPuwcT Qy2v7bSYxKG3cxkus3hw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1neoXF-003J2R-TM; Thu, 14 Apr 2022 01:44:38 +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 1neoX2-003Iut-1B for linux-arm-kernel@lists.infradead.org; Thu, 14 Apr 2022 01:44:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649900663; 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=rZWiQAF9GRIP7WU8AYwYkyBhsIYEfbcorZXD7uAiyqQ=; b=YSBpawGx0AvNmr+RobPmhGRbzrs8X9bXok0ykJ4Aw6B6mKK4aUHCSpgZhm8TTPTul2pLEz PxvwLLauW/5DTCcgnSGvUua69PURhoc3dBKbLu4OVGId2Nlih5YmyjdmHmKaH82yUoYpSx yXrRCb1ohl94qlmcotjVbZYsLc8uXQE= Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-352-fr8LehWlN5KJW5Ou3NDaYg-1; Wed, 13 Apr 2022 21:44:20 -0400 X-MC-Unique: fr8LehWlN5KJW5Ou3NDaYg-1 Received: by mail-pg1-f198.google.com with SMTP id z132-20020a63338a000000b003844e317066so1957806pgz.19 for ; Wed, 13 Apr 2022 18:44:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rZWiQAF9GRIP7WU8AYwYkyBhsIYEfbcorZXD7uAiyqQ=; b=l/h6ji/mhsl2yEO5cQZ8kxBtQEOCa+N1WFpkC2armjq4hrv8Xnh5TZeNuzj9ebYmMh 3+m7hLHolonLAOrn6FJdKlWmKdrRT077wGor9P7jiw9P+zVuvl1fpZ9qSzRmvc3PXncO Iq3tef2K/gU2dfPV57hjGnDE5TmXXB5+xxUNRb01zHesb68zU8UJU0lfltrMMtMBKpW7 5PuQIugQ+50SpH7xoiq7cvRr11hJOfe1MMh2d6m4fDvGonzDvABJ423XzkjzyajBAO4F grTaUno9iwYIIElnXDfpLzwixpSTMwyGPBhT9Bryb8lTgS7D9WpH4hFtUs/TZj4/XYPa PEfQ== X-Gm-Message-State: AOAM533FPrJFpomH3Pkp3I9xmE/T66b/dbsMvBnqArNxC+MVwXkVnges PzWP9voAJnrWy59SvKAz5MPppWGTLjsEcWyskUOYztnb2eYsZvOD2kecBYjMU+/+dwCjJnOhZDA +oGv6yCmvEoNB6VmxDkkKz3LKCBjT+iYbFks= X-Received: by 2002:a17:90a:dd45:b0:1bc:9466:9b64 with SMTP id u5-20020a17090add4500b001bc94669b64mr1694830pjv.23.1649900659138; Wed, 13 Apr 2022 18:44:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdzkDNxJ5ETNGa8+WNGA9rufymeL8qpXrk4exAuId9yogv97m9d/zBf7JK2uUxgm00wjeIBg== X-Received: by 2002:a17:90a:dd45:b0:1bc:9466:9b64 with SMTP id u5-20020a17090add4500b001bc94669b64mr1694808pjv.23.1649900658928; Wed, 13 Apr 2022 18:44:18 -0700 (PDT) Received: from localhost ([240e:3a1:31c:360:52fc:c968:cb41:efbc]) by smtp.gmail.com with ESMTPSA id e6-20020a056a001a8600b004fac74c8382sm334069pfv.47.2022.04.13.18.44.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 18:44:18 -0700 (PDT) From: Coiby Xu To: kexec@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org, Michal Suchanek , Baoquan He , 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, Catalin Marinas , James Morse , AKASHI Takahiro , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v6 3/4] arm64: kexec_file: use more system keyrings to verify kernel image signature Date: Thu, 14 Apr 2022 09:43:43 +0800 Message-Id: <20220414014344.228523-4-coxu@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220414014344.228523-1-coxu@redhat.com> References: <20220414014344.228523-1-coxu@redhat.com> MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220413_184424_163500_BC4E38B4 X-CRM114-Status: GOOD ( 14.06 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently, a problem faced by arm64 is if a kernel image is signed by a MOK key, loading it via the kexec_file_load() system call would be rejected with the error "Lockdown: kexec: kexec of unsigned images is restricted; see man kernel_lockdown.7". This happens because image_verify_sig uses only the primary keyring that contains only kernel built-in keys to verify the kexec image. This patch allows to verify arm64 kernel image signature using not only .builtin_trusted_keys but also .platform and .secondary_trusted_keys keyring. Fixes: 732b7b93d849 ("arm64: kexec_file: add kernel signature verification support") Cc: kexec@lists.infradead.org Cc: keyrings@vger.kernel.org Cc: linux-security-module@vger.kernel.org Cc: stable@kernel.org Co-developed-by: Michal Suchanek Signed-off-by: Michal Suchanek Acked-by: Will Deacon Signed-off-by: Coiby Xu Acked-by: Baoquan He --- arch/arm64/kernel/kexec_image.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c index 9ec34690e255..5ed6a585f21f 100644 --- a/arch/arm64/kernel/kexec_image.c +++ b/arch/arm64/kernel/kexec_image.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -130,18 +129,10 @@ static void *image_load(struct kimage *image, return NULL; } -#ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG -static int image_verify_sig(const char *kernel, unsigned long kernel_len) -{ - return verify_pefile_signature(kernel, kernel_len, NULL, - VERIFYING_KEXEC_PE_SIGNATURE); -} -#endif - const struct kexec_file_ops kexec_image_ops = { .probe = image_probe, .load = image_load, #ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG - .verify_sig = image_verify_sig, + .verify_sig = kexec_kernel_verify_pe_sig, #endif };