From patchwork Sat Oct 9 09:54:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coiby Xu X-Patchwork-Id: 12547417 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC488C433FE for ; Sat, 9 Oct 2021 09:59:31 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id AA16260F70 for ; Sat, 9 Oct 2021 09:59:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org AA16260F70 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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=2Alx255b3wgYCqy1ZSSaV+m/1it8UubOVm0kynPmnkI=; b=o5EaDmyr+SC8pc mgKYpMpZqHGvhora2c2dFGuEO7oQfe2LUhY2EfRdVZr3kxSrlt6PNdWbrbmnFthOa3hRD6O7IcZKO xxgEtlb9ASwhA36kfDMET3LxpNnFlQepduXhFaTRg7OM4M8P6fVASvUwwfFB+G+m87psSpGSl+d50 2ssNOk2WKNoK8FqYGNnL7PXfFjSQDZLbmDZxD9ZZ6Poi72d88+wyv6HAbtWgeAO7WuiRkYqzDvVFs 0p+JpqqaQ0qRR0iiaxWODfbqBeA3qXzV9XrbECGEsRtA2tyEryI5HMZjhFaFYO17CvhoB4w2a8hh8 WFfgNhF09Xp3KKZyk0WQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mZ96W-005ORF-04; Sat, 09 Oct 2021 09:57:20 +0000 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mZ96Q-005OQd-Cu for linux-arm-kernel@lists.infradead.org; Sat, 09 Oct 2021 09:57:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633773433; 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=fsLPwwfJMvJmM4PrEHlGw5zfIwX7nOgCAknVMv1VPzs=; b=GITX/vRaWzhXFFXk1RbLqO4tTraV4LKA1eFFccoLsw6i3so9fSdMyR+8YTqhVopApYMsY0 Imbs9Zn8C+PYKps26w3zl8HG0DQF4TtBz8eeAZydKlPfuiNNgQ5mCW861Ubm2dPhDO7s/f n6ckAWiPYzrn7QSHWWd5mxqlMHWHPlU= Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-579-32SBfkk2OKOjCgNi7LEKGQ-1; Sat, 09 Oct 2021 05:55:16 -0400 X-MC-Unique: 32SBfkk2OKOjCgNi7LEKGQ-1 Received: by mail-pl1-f197.google.com with SMTP id h3-20020a170902704300b0013dbfc88e14so5820851plt.13 for ; Sat, 09 Oct 2021 02:55:16 -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=fsLPwwfJMvJmM4PrEHlGw5zfIwX7nOgCAknVMv1VPzs=; b=c6aswTGrc9qQLVnl1fCocNVgW1kQMDQ+9Qe97wi2gktVBli3UniHch3u7/qwNc9Jet RuZVAuZKlBxeftANYMyN8M/+rjw2+QNi1P2gLvjZ9skHwBoQXwA18W3ytbi9ZaG143hW fFMSF1dRWccDafSTsKGuDQ3iWAdz/XFTnS+W63MXMaYh3cvMIuWct6slb5z4LX500sfK 5bWPOrRSZe9gjFSYBJrGbQFCmATUVwR9+EiAO5ihTZuw8t5QFrsxkDzR1fLbVquVn8he 3m7GS0q9466jZcoHLKT47ZNjBUppVsIx5y9liNDaQH6SfZhVTVyVQ9FKrpUdx/Q8kVSt JWLQ== X-Gm-Message-State: AOAM533//FTNG2rooLUY9wwr/HOUQD1wgZ8PNVBRLZZSbUcJE0buGkKv 1D6jkkfGrgCqPQybhlOWxUl9ARBCi4jKeNeVXdqPTb4B9k6r+TzUWxv2WQk/KHpdo0XbgLkv0jw O2972m4Q6wwkCTEFFsxlH3+Bany9EaiJKPvc= X-Received: by 2002:a17:90b:388a:: with SMTP id mu10mr17419760pjb.0.1633773315166; Sat, 09 Oct 2021 02:55:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8syPDNVODcQ5AMjYRz3SYVVr1GIyZ7ZZ6GvjFVwJAP1874M9w4yiCQDFY0ja6waqA6RZSbg== X-Received: by 2002:a17:90b:388a:: with SMTP id mu10mr17419745pjb.0.1633773315001; Sat, 09 Oct 2021 02:55:15 -0700 (PDT) Received: from localhost ([240e:473:3c30:93d:5429:b8e4:3097:6ec8]) by smtp.gmail.com with ESMTPSA id d18sm2106657pgk.24.2021.10.09.02.55.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Oct 2021 02:55:14 -0700 (PDT) From: Coiby Xu To: kexec@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org, Dave Young , Will Deacon , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "H. Peter Anvin" , Eric Biederman , linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)) Subject: [PATCH v2 1/2] kexec, KEYS: make the code in bzImage64_verify_sig generic Date: Sat, 9 Oct 2021 17:54:57 +0800 Message-Id: <20211009095458.297191-2-coxu@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211009095458.297191-1-coxu@redhat.com> References: <20211009095458.297191-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-20211009_025714_528086_1B7BC764 X-CRM114-Status: GOOD ( 14.35 ) 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 --- arch/x86/kernel/kexec-bzimage64.c | 13 +------------ include/linux/kexec.h | 3 +++ kernel/kexec_file.c | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c index 170d0fd68b1f..4136dd3be5a9 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 arch_kexec_kernel_verify_pe_sig(kernel, kernel_len); } #endif diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 0c994ae37729..d45f32336dbe 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -19,6 +19,7 @@ #include #include +#include #ifdef CONFIG_KEXEC_CORE #include @@ -199,6 +200,8 @@ 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); +int arch_kexec_kernel_verify_pe_sig(const char *kernel, + unsigned long kernel_len); #endif int arch_kexec_locate_mem_hole(struct kexec_buf *kbuf); diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 33400ff051a8..0530275b7aa3 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -106,6 +106,23 @@ int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, { return kexec_image_verify_sig_default(image, buf, buf_len); } + +#ifdef CONFIG_SIGNED_PE_FILE_VERIFICATION +int arch_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 #endif /* From patchwork Sat Oct 9 09:54:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coiby Xu X-Patchwork-Id: 12547419 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9755C433EF for ; Sat, 9 Oct 2021 09:59:50 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id B8AB660F24 for ; Sat, 9 Oct 2021 09:59:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B8AB660F24 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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=homKlvrqk2YpeFGpTbzsT6sFIoRn9Jv0lAeRLt7Flak=; b=Qe/IXJzU59/yN9 9duLfWLkMmKTj6OsABLa2DxwE5DONMRiqnmPFOcKxEkXxsfEnXhUnqzp8VdBccmt7TDZGUyksy+1M mjZ/7lC4LAU6i2krvtJ7mfMLovPO7vTTdy5qbTnoWSC8hsP1MDi20z6rQ1oEK20r/9sj00I5RBiYj oSVscLpkA1RA0D27eA4x5p0Hy8jmWC39DX8pz1Alyk7QmlbX2wbtUaTtUHlTWphJEEKhbt2TLcF/i NtJFQ1bIZ8NuJJ9VP/ydBN6Huf1QhbH75LiaOmK0VMHMajPBLLDgNUP695tEVL2tYggA3Ft37yZzV SSb5Me88tL5CoSQ2mM+A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mZ97G-005OYK-5R; Sat, 09 Oct 2021 09:58:06 +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 1mZ97C-005OWv-KM for linux-arm-kernel@lists.infradead.org; Sat, 09 Oct 2021 09:58:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633773481; 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=7pixb7rhSe9gW9mPovHeBhJ7x5GxJTOJKpjxWylVhVA=; b=I8KK1ScbDdDtKdgUul5g41rVLZAEVN4ULVIT2knf6Z9i3Zv5OfqgEjaQGEHnsHkSKQBk9/ IvtNBrFfaRoqK1QMAnkM44fNKRjAsmgh/UFWsVWFFea+akN9+7ua/ZVbfNozpxkfNUYmEA pKbcssu85vt3SLfhNeQhVSWRaP6GhjY= Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-534-9uUgVd2HOxWugnjRhjGvBg-1; Sat, 09 Oct 2021 05:55:23 -0400 X-MC-Unique: 9uUgVd2HOxWugnjRhjGvBg-1 Received: by mail-pg1-f200.google.com with SMTP id n9-20020a63e049000000b002951886c1c5so3296770pgj.0 for ; Sat, 09 Oct 2021 02:55:23 -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=7pixb7rhSe9gW9mPovHeBhJ7x5GxJTOJKpjxWylVhVA=; b=JLCl86DKow5q8RdPCFyKjmlNxjfTzoEmMWNjLAWEO3renGGMFge4Q8/jyOWquw+jsl RqAfhloDU8d7PoWLUJdtjBVXHDH2bJw2CnfR7LNQm7oWUfSJHYQ/pY+uRofdWH6LjOfg Q7W3itzO+nFysnSfYc9B6+3fL5IGvJkPYuGeXBWoz31NxD6YdFw+TBt85/cQ81ekv9vB QI0MElLop13JPgX0JH/0iwNHPmGQW6ZOzdEXJt/XifnVh77DdPSGaBhnOq8TqYp2Ol+K 173iYt3UbuP5djHmUQi/JNFaZT69X+9tmEDLUbF8ZkT4/unjR02jm7HiyZ17gRJd0pdX a1hw== X-Gm-Message-State: AOAM533QkvRkIksl9E4OL9NScOem1gOLvbM3NXhtQLQWDtjetVI/Mp9m 23zuBdW6WmgzI3/wirIn6+yC15fJtvjdRqVfJ5VprB1idWh04WV9gcYdUg3Fly07fNgrcWq6fXV IAsZEUN6PI60XFBZai+3VhCladf2aRo/ZHz8= X-Received: by 2002:a17:90a:5515:: with SMTP id b21mr17273645pji.239.1633773322278; Sat, 09 Oct 2021 02:55:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1rCjIedQornvFaznhwr+Y/s6YTuLq2BT1YqbQI1e6qIeVqUoNK1CiLqatpJukq936/FQJzQ== X-Received: by 2002:a17:90a:5515:: with SMTP id b21mr17273625pji.239.1633773322100; Sat, 09 Oct 2021 02:55:22 -0700 (PDT) Received: from localhost ([240e:473:3c30:93d:5429:b8e4:3097:6ec8]) by smtp.gmail.com with ESMTPSA id r8sm2023753pgp.30.2021.10.09.02.55.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Oct 2021 02:55:21 -0700 (PDT) From: Coiby Xu To: kexec@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org, Dave Young , Will Deacon , Catalin Marinas , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 2/2] arm64: kexec_file: use more system keyrings to verify kernel image signature Date: Sat, 9 Oct 2021 17:54:58 +0800 Message-Id: <20211009095458.297191-3-coxu@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211009095458.297191-1-coxu@redhat.com> References: <20211009095458.297191-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-20211009_025802_750587_7B21BB90 X-CRM114-Status: GOOD ( 10.77 ) 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 This allows to verify arm64 kernel image signature using not only .builtin_trusted_keys but also .secondary_trusted_keys and .platform 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..2357ee2f229a 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 arch_kexec_kernel_verify_pe_sig(kernel, kernel_len); } #endif