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 /*