From patchwork Fri Apr 1 01:31:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coiby Xu X-Patchwork-Id: 12797834 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 D9F1AC433EF for ; Fri, 1 Apr 2022 01:33:26 +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=P+sfDhvWhTKZ7m+oABa6rQZXkcHFGxmTPXHZdT6RDUg=; b=jicRS0WHGxCJYn sBMRGBRW+FfU+RaJMVJhTO0nK/ctcyxqhIFaR2LBFuVptwHF0RYscGUvFbaORGysQLDBQ+lNDXGQV 78hRXs1Nu9flW+i8BBnn6Qw1E0NYlojKDDg+GinIlw373o7W+ZkkCydFHczXBv7K7Fu4EUrUN2X8/ rcVZ8R9sGTMKd6nHd7D1GcBmm/XGnQq/k1CXl6BwJwWtAExa1k3skhFx5u2EPOu5rM0Gmf1i65CvJ jyKiQBYVzZUSd7+2PHwPi7BmRsMPd10pdDO3dhZZdWvylnI0cy9XUZmLnrF3AGtzwdkZcSx0sD0v3 mxjRpTg3vRENt98FZfoQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1na68Z-004Akl-73; Fri, 01 Apr 2022 01:31:39 +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 1na68O-004Ai9-7s for linux-arm-kernel@lists.infradead.org; Fri, 01 Apr 2022 01:31:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648776687; 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=63ahIHb1A6QnEpYKNiglm5VmzrC+Q55jXB/IrtWitwg=; b=ViDJzlNxeUOhhbIxMQiZWHqfSBk29jrYxjr9CjoABOCM63k1f9czxhLrxU5aKxgeR0Kzpa NZbo7L74ve6YSMj5aJHSOPEPj91HNkxMHzCrBfj0veLUHpSvA01FYAM4tULeXUvuIxK86n JzTZ/DeSuXg4XkZtdkVqmH/Fm3eUbOE= Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-608-Dt0sa7M3OpSW1cbIJV0WcA-1; Thu, 31 Mar 2022 21:31:26 -0400 X-MC-Unique: Dt0sa7M3OpSW1cbIJV0WcA-1 Received: by mail-pj1-f70.google.com with SMTP id j15-20020a17090a2a8f00b001c6d6b729f1so619223pjd.3 for ; Thu, 31 Mar 2022 18:31:26 -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=63ahIHb1A6QnEpYKNiglm5VmzrC+Q55jXB/IrtWitwg=; b=gNaDrFE3p7bSV6Ee5fBG4gMV51HsSWFgtSHJACb8UbXBAMZFtEvlD3p9TV01je/vYO z7zEsRsOzOgltZnaazRVylAMQvudVXcxdIdWI0IJa5oczJ2PGzkuJCN01JqSx/RHE2Z7 hlFh2NzBkQgbt4O8XLIKH7Je9ZHN2IEGYj3NTrWSr0OhkA0usHOP2K9VvwISJyNxCpU7 YotFOo1Yn5uU6XOmGw7V49T0wY3hLP1Asqa0q05TQt806sUHIvvHqNdROiN88EGvOVtD GnezAW3CBL04KdfjBlh30O5kCr9++3d+l0HfmJb6C1htt1e5IZxmjBlNSO4U5Lji5JrI pE/g== X-Gm-Message-State: AOAM533WTOnb8CMiMOuxQQHy623f2m2ux6/G9wiwAY532DGjCL+qignv lS0KNFHlJVGtBwKMABle6Xo4nIIUvU6MawKuqewSTemYNTRWcjIWp+ms0kBv0H4PvMjvzENGFL/ lJ0H+sNP9q0LIvVtHGeLwI248ySyLNruTDZA= X-Received: by 2002:a17:902:8491:b0:14e:dad4:5ce5 with SMTP id c17-20020a170902849100b0014edad45ce5mr7839471plo.76.1648776684810; Thu, 31 Mar 2022 18:31:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxe5ZnYVdI4Y0iKlg94zYCaIwF36XwQHqq65KsuJ52g066rNTebA/TD0z8Q++cV2HBL58QVCA== X-Received: by 2002:a17:902:8491:b0:14e:dad4:5ce5 with SMTP id c17-20020a170902849100b0014edad45ce5mr7839451plo.76.1648776684509; Thu, 31 Mar 2022 18:31:24 -0700 (PDT) Received: from localhost ([240e:3a1:31c:360:52fc:c968:cb41:efbc]) by smtp.gmail.com with ESMTPSA id q15-20020a056a00150f00b004fb28ea8d9fsm741915pfu.171.2022.03.31.18.31.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Mar 2022 18:31:23 -0700 (PDT) From: Coiby Xu To: kexec@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org, Baoquan He , Dave Young , Will Deacon , "Eric W . Biederman" , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v5 1/3] kexec: clean up arch_kexec_kernel_verify_sig Date: Fri, 1 Apr 2022 09:31:16 +0800 Message-Id: <20220401013118.348084-2-coxu@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220401013118.348084-1-coxu@redhat.com> References: <20220401013118.348084-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-20220331_183128_388334_1C77CF36 X-CRM114-Status: GOOD ( 14.17 ) 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 Signed-off-by: Coiby Xu Reviewed-by: Michal Suchanek --- 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 0c994ae37729..755fed183224 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -196,10 +196,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 Fri Apr 1 01:31:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coiby Xu X-Patchwork-Id: 12797836 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 1835CC433F5 for ; Fri, 1 Apr 2022 01:33:32 +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=Uf73j6MUsj7nM4RP3K0XGueviZ2t8MBXz4APboZN63s=; b=YAFCO7Bzi0CBfU p7VS0CIEkkQykHQgwktB8N5FEtX//MN+Ar0D17BzXF9mfWH20LG1TKQXrqtybjGJvvpr5UOM9F9d1 Kwt082x1e+/sXwyzyau2EdwlfP+vZ9emWn+45EIiwv3u0VZ2llc40n+C0dt09YvZFIw3QOziuOQPu ETfK4UOAwyLZKARov5denrIKwMcPte8uuKGBWHvbYPyuEWZthtZQEq4hq+e+xnywbVDv+aNvcWuHt iMEySOFTswAYVBcrtnx/Dess98CqYc7xb3T1HfUW6ATEe1h24OQY/FX5EEkHvZmfT0mayV1gqTUeN MqzVVM4z4vF9f+Voub9w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1na68l-004Anv-8q; Fri, 01 Apr 2022 01:31:51 +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 1na68S-004AjE-5W for linux-arm-kernel@lists.infradead.org; Fri, 01 Apr 2022 01:31:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648776691; 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=XVmPCPO0oF3pRYu+F7qpHdcQzaq88pJ0kcN8pmyvV4M=; b=Ae+CQpwEDuPDhjSQ0Jh4PZjw7Yv7Xf9NmUA/+fOLR1/4uKj7UBjTpdFQDpbC/pBENim+Li kIlhfTuL6KlbTAIsiCzUK9ran6OKszco210TWK31Xq9/fT0zysWew9V4B4Htxzb5pcoWfJ qzsEoUQ7ous66im3UF6+6ZBnNrQVVNo= 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-97-V0apz8BmNWSWBZ61bDy59w-1; Thu, 31 Mar 2022 21:31:29 -0400 X-MC-Unique: V0apz8BmNWSWBZ61bDy59w-1 Received: by mail-pj1-f69.google.com with SMTP id mw8-20020a17090b4d0800b001c717bb058eso2848650pjb.0 for ; Thu, 31 Mar 2022 18:31:29 -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=XVmPCPO0oF3pRYu+F7qpHdcQzaq88pJ0kcN8pmyvV4M=; b=XhwQfkx3f67HmD7KEu1nezHGhK2Do5Kf0gX42kxyR6XIrBuYmUmKqIN8pNSO0ap3YH pIE5xR1uh80wgkTGnQQ/FHvKyLTGRFmOguFpiMo3GMKgtYD0JiLBHEEsTfstdAJJ65L4 K/i4tN0pyCT3TLeiALwtOuN+AB9lbmp4ZQ9ko2Wc3yAdeTpoafLpPLlgVerzJktW3Wk6 PFfEN6/7SGMks89ZmnKgdDqLiDB2dRrOKujHXPRS/hIBblIOajfkjoR3y1X0RlGadzRP bU5tl8SyYIvUSOrmZLDVWHyBWiVoAD112a1ylOU+fDXt6nnmUncblkjMNs5g29nDULiE 7SZw== X-Gm-Message-State: AOAM531CI4nzMLGpGsgROyufgMGlRErO0qJtSF/wjGMIC99HgHCuMXgG O9i1HTTwDJgmcXP4b4Mi/y+lggGLEPkfMZWyvqWtUjEF+0wFTDHrV7lWthypy8FJelOyTz/pIzh aA8iXp3VE+2GjEpBZWouxrmMvTAKEz3j8Wqk= X-Received: by 2002:a17:903:20cc:b0:154:8c7f:1ed3 with SMTP id i12-20020a17090320cc00b001548c7f1ed3mr7854403plb.131.1648776688284; Thu, 31 Mar 2022 18:31:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyk8pGREHFgs4EKOdX9WUE7Kapxs8ssHrqs3uFxMkIE8BiXg/yu0dkJv+gF0OWTAflQuu0kcg== X-Received: by 2002:a17:903:20cc:b0:154:8c7f:1ed3 with SMTP id i12-20020a17090320cc00b001548c7f1ed3mr7854375plb.131.1648776688014; Thu, 31 Mar 2022 18:31:28 -0700 (PDT) Received: from localhost ([240e:3a1:31c:360:52fc:c968:cb41:efbc]) by smtp.gmail.com with ESMTPSA id p34-20020a056a000a2200b004cd49fc15e5sm759358pfh.59.2022.03.31.18.31.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Mar 2022 18:31:27 -0700 (PDT) From: Coiby Xu To: kexec@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org, Baoquan He , Dave Young , Will Deacon , "Eric W . Biederman" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "H. Peter Anvin" , linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)) Subject: [PATCH v5 2/3] kexec, KEYS: make the code in bzImage64_verify_sig generic Date: Fri, 1 Apr 2022 09:31:17 +0800 Message-Id: <20220401013118.348084-3-coxu@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220401013118.348084-1-coxu@redhat.com> References: <20220401013118.348084-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-20220331_183132_323975_2C1B0455 X-CRM114-Status: GOOD ( 14.30 ) 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 The code in bzImage64_verify_sig could make 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. Signed-off-by: Coiby Xu Reviewed-by: Michal Suchanek --- 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-bzimage64.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 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; + return kexec_kernel_verify_pe_sig(kernel, kernel_len); } #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_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 Fri Apr 1 01:31:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coiby Xu X-Patchwork-Id: 12797837 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 CFF66C433F5 for ; Fri, 1 Apr 2022 01:33:43 +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=uova1sNyynHLEDH3ymuchY5u3kplYpYuujGr8bEGDg8=; b=f3J3D31mdAL8/v ftBapCM4d9zmMykma3jrJLgIydGQyzVU+degB1p7PRlcU3GNcnwt68dNzzWEUGyZeeZKjOyvZFai1 Hp8Oh8ybMOoH8OsAsWzgT+6Y3VMM51fcTp4ghYXgcRZ+PFuEbFUrt4tx0yvXvs21IcC6Hrhuu+HMH Vsp/mGmrpPOYxCXZJJbO58dY/0bAEeHQ7l0mtGKgJVCCbzbomrRYWdgpQ6lZoynpN5dUl0HVObanV M8lChVScz2sfAVzgGYv+ySsRM82VEDwDJ9UFx/fcVx6WZ3pVGb1CC5iYFDf5h/rozjemwBzT5s7Go V3lQsYAg+uS+miCK9xOA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1na68x-004ArG-8G; Fri, 01 Apr 2022 01:32:03 +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 1na68U-004Ajz-OB for linux-arm-kernel@lists.infradead.org; Fri, 01 Apr 2022 01:31:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648776693; 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=Ur4bX7kLocMyHlMkWd6be/nI5FhdYUXpSu22PLx25Yc=; b=O2svxs8cdXpCvAjxACuk+MKQ2IHbu9wXdtU2jbpFyEnaAvHADeKOynY0zQCEafNLPk8iUJ vZr6mfYVDoOXQcv69s/enoEppOrrF7UWNx9hVEFKstlv43wl6fd1Ux1uP5auGQYYHhvw45 iFWLMZWwBWY6POfdqEDIkefLejjZjGM= Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-52-ON9iDdqUMtKWQLciJn9DLg-1; Thu, 31 Mar 2022 21:31:32 -0400 X-MC-Unique: ON9iDdqUMtKWQLciJn9DLg-1 Received: by mail-pj1-f72.google.com with SMTP id iq24-20020a17090afb5800b001c685a314d6so439791pjb.4 for ; Thu, 31 Mar 2022 18:31:32 -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=Ur4bX7kLocMyHlMkWd6be/nI5FhdYUXpSu22PLx25Yc=; b=OoVEA4XKJ9dK3pQ5xcaGb3CrlBX/4As0zBzoFR2Y+EuKrotZK66T/43hJh98uhWfi4 R1p7U2E+DDSKbqh7ztH+LkuYsd7m1bo9dDsiVbnhjAIff9V6uPe0dqZvtG7YulAy1uQU 3dk9P3mnu2KcFf/nSREKsziJFUWolpkoPD9ElOQtHa4kOPTnG61sAcknVZoGOs/kR4dj SyFsqSRuH8SKF48tK980qbc3XEocIBuLexjpiRFrAz8o/Jy62b2i5+Qpx5S1nD8tL8wV 5uf56zzMQhEkRbwAO8Ot+2Gc0UfEDrIrSZPiWvBPzMsVvJzAbvY27oGqTpPVTlHX9NYS FmqA== X-Gm-Message-State: AOAM531bJw2YFCxxmJL2u7pGyJ4jV1+R7XKqcODBjvUZoGW2DejUo924 6eYBZPX1KpCTKfXKmZToWgRxnPnRF228KZFDCgUR2Elc6jfLhPKHfhAg9NBqt/B4/liN2LwvMKI JsAYeBd9p5PmrOTFJ0YDmEIhWfCcqw9Ex1RA= X-Received: by 2002:a17:902:708b:b0:156:1a0a:5c3d with SMTP id z11-20020a170902708b00b001561a0a5c3dmr7767914plk.18.1648776691480; Thu, 31 Mar 2022 18:31:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytKI0smTf2h5pDtZ1Ru/oJPC2Djio4Q2XzblwlhHZObk3685LSZ1jxpUWN1pqTW4oEpdgQqA== X-Received: by 2002:a17:902:708b:b0:156:1a0a:5c3d with SMTP id z11-20020a170902708b00b001561a0a5c3dmr7767892plk.18.1648776691177; Thu, 31 Mar 2022 18:31:31 -0700 (PDT) Received: from localhost ([240e:3a1:31c:360:52fc:c968:cb41:efbc]) by smtp.gmail.com with ESMTPSA id y15-20020a17090a1f4f00b001c7ecaf9e13sm544181pjy.35.2022.03.31.18.31.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Mar 2022 18:31:30 -0700 (PDT) From: Coiby Xu To: kexec@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org, Baoquan He , Dave Young , Will Deacon , "Eric W . Biederman" , Catalin Marinas , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v5 3/3] arm64: kexec_file: use more system keyrings to verify kernel image signature Date: Fri, 1 Apr 2022 09:31:18 +0800 Message-Id: <20220401013118.348084-4-coxu@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220401013118.348084-1-coxu@redhat.com> References: <20220401013118.348084-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-20220331_183134_898177_D38AFBCD X-CRM114-Status: GOOD ( 13.15 ) 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 patch allows to verify arm64 kernel image signature using not only .builtin_trusted_keys but also .platform and .secondary_trusted_key keyring. Acked-by: Will Deacon Signed-off-by: Coiby Xu --- arch/arm64/kernel/kexec_image.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c index 9ec34690e255..51af1c22d6da 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 @@ -133,8 +132,7 @@ static void *image_load(struct kimage *image, #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); + return kexec_kernel_verify_pe_sig(kernel, kernel_len); } #endif