From patchwork Thu Jul 14 13:40:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coiby Xu X-Patchwork-Id: 12917982 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 C209FC43334 for ; Thu, 14 Jul 2022 13:42:11 +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=IdOfXMMuBvwgCz4pU3OO9hNtQxi8ItKrGPyBHiWFsSQ=; b=uBCR3ENMvh9di+ qgxe64agidNsdYtfiotqqGCbF24Uz6I34JJ1hMMS5p82TWNOovbOscbfS+1rpkFrmVODpuTR34wzf Hmm6g/v5vYXY3iUGeS5Y2Lqj+goFdtDe6/4S5BHA2+dGYmaL33n2iBRYtpKarZh48CsxxdNKOgP0j XydtLaOfzfUo5Sn3S7xMQduCNK0Vr9qeCd+rC4MecVIRFTSyuBHWpWF6LrVE6+sIwl9dktx2HS6Xs Z9PZyl/QOwfCPxxJXhQYCtIPIuS3BE6cDrWWKdkiwsX0VU9VSnkWNmj41tBIeF9df7DXToa8UiKoG wGxggkitf38NCu6ZS/MA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oBz5W-00EoVC-IL; Thu, 14 Jul 2022 13:41: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 1oBz5K-00EoM8-9o for linux-arm-kernel@lists.infradead.org; Thu, 14 Jul 2022 13:40:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657806053; 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=aiVvGqWued69KlQMltHUGXgLkEsQEsLtjAg7jnmKF7w=; b=BzSo71S0fWnQ6FquKZCw3IpI4dxxkiHxfTvg/3CLhN6frbAZxdofV5AW0Y7nimg+FW3LcH 1+2JLHjFhe3CUnX6mtNIOmbns3EizGT4QDE2WPTEErgOxoZlI9BUK3HYBivTlkINA3Uerm tbXu/daq/AygfD2O3gmb4KCL9uOsAm8= 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-144-Vd3vdvanOkq9CUnhkf1bKg-1; Thu, 14 Jul 2022 09:40:46 -0400 X-MC-Unique: Vd3vdvanOkq9CUnhkf1bKg-1 Received: by mail-pg1-f200.google.com with SMTP id u11-20020a654c0b000000b00415ed4acf16so1243736pgq.22 for ; Thu, 14 Jul 2022 06:40:46 -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=aiVvGqWued69KlQMltHUGXgLkEsQEsLtjAg7jnmKF7w=; b=2f1Q5redeETyB3nI8VjK4Dc7GLlNVrbo2eI5ZHSmRFcqk56WoJlW8iT2uZHgxBDrmx 9CMArkgOmc9/rqNv+vtmEUNa50FPFglV1ewEVtEi26lK/SFmaQDrtKFSOzSHCX7jkpgz sodNCuPf8CoSechb4SuKUwrFiXwBMB0/JGMUpna+oLgL+Xm4MYUMoVC5CRXxBSXqPgJY TLGibM9am19VEbH4AmwXABJiP1JFAGNLnw2IWQc656sgbXsqfGzGfdbVdQWwr/UTYa9e Zhr6tJdU15SSZvgAQX6dTQoI2w7naAUkZvCReR7YQfAtgRlOOseNPkqBLdFlYqoDrYLE t+hw== X-Gm-Message-State: AJIora+MxkryNXWyTBnCQjjt08vJDDL3b10U/J1EpObkKAk/aBTVNXNk 6uRcvwTlVQhS1DbqVswQC5j9fEtZAUHaZFSG6MZi4lFHb/LcqvnzPPfYIqDTiTTQoq8+ZrOt1mo gTzraUWuc+lZFqLsk0DjiKQTlScMJc+Cix04= X-Received: by 2002:a17:903:2310:b0:16c:1546:19ba with SMTP id d16-20020a170903231000b0016c154619bamr8463337plh.57.1657806045389; Thu, 14 Jul 2022 06:40:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vR6P1tHGe2AUAKkpHoPoHZ3qPv099U+d+IUX/aj3wmn46jrsJ1Kfs8MRjpFEQ0YAvbKCgu6w== X-Received: by 2002:a17:903:2310:b0:16c:1546:19ba with SMTP id d16-20020a170903231000b0016c154619bamr8463303plh.57.1657806045096; Thu, 14 Jul 2022 06:40:45 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id o21-20020a170902779500b0016be24e3668sm1425461pll.291.2022.07.14.06.40.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 06:40:44 -0700 (PDT) From: Coiby Xu To: kexec@lists.infradead.org, linux-integrity@vger.kernel.org Cc: Mimi Zohar , linux-arm-kernel@lists.infradead.org, Michal Suchanek , Baoquan He , Dave Young , Will Deacon , "Eric W . Biederman" , Chun-Yi Lee , stable@vger.kernel.org, linux-kernel@vger.kernel.org (open list) Subject: [PATCH v10 1/4] kexec: clean up arch_kexec_kernel_verify_sig Date: Thu, 14 Jul 2022 21:40:24 +0800 Message-Id: <20220714134027.394370-2-coxu@redhat.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220714134027.394370-1-coxu@redhat.com> References: <20220714134027.394370-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-20220714_064054_458547_D4808D55 X-CRM114-Status: GOOD ( 15.16 ) 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 Before commit 105e10e2cf1c ("kexec_file: drop weak attribute from functions"), there was already no arch-specific implementation of arch_kexec_kernel_verify_sig. With weak attribute dropped by that commit, arch_kexec_kernel_verify_sig is completely useless. So clean it up. Note this patch is dependent by later patches so it should backported to the stable tree as well. Cc: stable@vger.kernel.org Suggested-by: Eric W. Biederman Reviewed-by: Michal Suchanek Acked-by: Baoquan He Signed-off-by: Coiby Xu --- include/linux/kexec.h | 5 ----- kernel/kexec_file.c | 33 +++++++++++++-------------------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 6958c6b471f4..6e7510f39368 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -212,11 +212,6 @@ static inline void *arch_kexec_kernel_image_load(struct kimage *image) } #endif -#ifdef CONFIG_KEXEC_SIG -int arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, - unsigned long buf_len); -#endif - extern int kexec_add_buffer(struct kexec_buf *kbuf); int kexec_locate_mem_hole(struct kexec_buf *kbuf); diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 0c27c81351ee..6dc1294c90fc 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -81,24 +81,6 @@ int kexec_image_post_load_cleanup_default(struct kimage *image) return image->fops->cleanup(image->image_loader_data); } -#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 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 - /* * Free up memory used by kernel, initrd, and command line. This is temporary * memory allocation which is not needed any more after these buffers have @@ -141,13 +123,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 (sig_enforce) { From patchwork Thu Jul 14 13:40:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coiby Xu X-Patchwork-Id: 12917983 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 376AEC43334 for ; Thu, 14 Jul 2022 13:42:45 +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=QCAv1+YVHrF/xsCTp2NbA42EOVPNfe93/dfq7K0qf+k=; b=uuhgDKO2KEg59J iC0vh6lzl5YnBevMmfm4lUYYGEAexseQhrkDk5iGiSrjph40ZzlVOccV3LRfxpJHzVfCFymd7CqpG Tt9ZlV+NlDZRJxvusR4OZ1aixoO/s8ZVWFX+LjQIs36LgirZWwBTjpdfYFAQQ2mkI3I55xo4LgLi3 xYt/ukZHrRCxJBq6mIoIXTJ3sbmw99mEVYad1876JMuAsPSRmJMss5mr0RS6j3WXDQ9tGgScPhu1d GPROhCdzDYrOgE/K7+QSbu+DYMXXJPda6WhG0nEbY6GKzhakAswhiD8VImT1Ly3dFbOUBAQy1ZASg pKfgXxYW3fAHADeFXJEQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oBz5x-00Eope-RV; Thu, 14 Jul 2022 13:41:34 +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 1oBz5U-00EoT4-Pg for linux-arm-kernel@lists.infradead.org; Thu, 14 Jul 2022 13:41:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657806063; 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=gPEtVWmsQSkTQzDvP4m8a65flxiE/Nesl9xf3cgMNG8=; b=W52e/vF8FMquICjClK7HXxFS/il6WppLxkk7tNQdyL+HszVOBPI9lNtQ0l2UWicY8LxCAD XavmMXteEPBzsk1BGF/84GW0LxWeCB80xdrmViDLhuH2nrkjpme6XJBlsc+ZudvyGyhCye RW7gw+yHsLWeSwGUUZL16xoM/NNAmSg= 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-38-9-gON8fTN0y1vhyXUjoMmg-1; Thu, 14 Jul 2022 09:40:56 -0400 X-MC-Unique: 9-gON8fTN0y1vhyXUjoMmg-1 Received: by mail-pg1-f197.google.com with SMTP id g67-20020a636b46000000b0040e64eee874so1268021pgc.4 for ; Thu, 14 Jul 2022 06:40:56 -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=gPEtVWmsQSkTQzDvP4m8a65flxiE/Nesl9xf3cgMNG8=; b=Wxx2+Z9YBtNa0NgWIP8CnHj+6298Js5wLSdoIX5979r2GbqMWzTxLGoeiYhgpNIUvY a6u5msniu+bl1L4c9C19zEFN67KHjBPalEjMVrtTyS4LIfYfitaXjJvLE6XCM0RjAUbV yexRkqpGwqdIJHsWQRPolgx/rEA15VOlnJV3TgrqEUGYk+CkeezWEHG0+Apf8+0GYl7O MEgIuC92nz51r65kRQvluAwvRx1WGRlKglStzCudw5reTbXPEHdT/BE/ygedjWlW9Io/ mip7E7c3fa+oFU0v49kOqb1ztI47Pboz53QDQNWbVAbNS9t+Qg0E7Kz6r81Uh9snawJF vBJw== X-Gm-Message-State: AJIora8lmcVv6RgaG9I+MBmAi2yud11yFZMQilmmH3U5HZiRpjNfd2yz kgTED3AsSKhz4PijMtvleUyc2xQ8cOKbXohWASXR+q0PParYYjBYRJlUz4CtF2lFKHy6DzzL5TW XPq1waKk7E0/AkzwEhONIlYUUSJg6/avcgwk= X-Received: by 2002:a05:6a00:228e:b0:52b:13d2:2627 with SMTP id f14-20020a056a00228e00b0052b13d22627mr6669609pfe.42.1657806055738; Thu, 14 Jul 2022 06:40:55 -0700 (PDT) X-Google-Smtp-Source: AGRyM1usVuR3eLQo75Dg0fkD9sxT+ABvKFZxKK5KiUodEx1pCPVlWbqKhxgcrRbiImMlDhzyfN0trw== X-Received: by 2002:a05:6a00:228e:b0:52b:13d2:2627 with SMTP id f14-20020a056a00228e00b0052b13d22627mr6669586pfe.42.1657806055485; Thu, 14 Jul 2022 06:40:55 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id z15-20020aa79f8f000000b00518a473265csm1651851pfr.217.2022.07.14.06.40.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 06:40:53 -0700 (PDT) From: Coiby Xu To: kexec@lists.infradead.org, linux-integrity@vger.kernel.org Cc: Mimi Zohar , linux-arm-kernel@lists.infradead.org, Michal Suchanek , Baoquan He , Dave Young , Will Deacon , "Eric W . Biederman" , Chun-Yi Lee , keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, 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 v10 2/4] kexec, KEYS: make the code in bzImage64_verify_sig generic Date: Thu, 14 Jul 2022 21:40:25 +0800 Message-Id: <20220714134027.394370-3-coxu@redhat.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220714134027.394370-1-coxu@redhat.com> References: <20220714134027.394370-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-20220714_064104_924837_5C434628 X-CRM114-Status: GOOD ( 16.47 ) 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 uses the keys on the .builtin_trusted_keys, .machine, if configured and enabled, .secondary_trusted_keys, also if configured, and .platform keyrings to verify the signed kernel image as PE file. Cc: kexec@lists.infradead.org Cc: keyrings@vger.kernel.org Cc: linux-security-module@vger.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 6e7510f39368..bf24e7fce1fc 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. */ @@ -212,6 +213,12 @@ static inline void *arch_kexec_kernel_image_load(struct kimage *image) } #endif +#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 + extern int kexec_add_buffer(struct kexec_buf *kbuf); int kexec_locate_mem_hole(struct kexec_buf *kbuf); diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 6dc1294c90fc..a7b411c22f19 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -123,6 +123,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 Jul 14 13:40:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coiby Xu X-Patchwork-Id: 12917985 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 E7D3CC43334 for ; Thu, 14 Jul 2022 13:43:23 +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=31Xvy6np8oF3d4eV5kSeWyJMGR5ltOVcjaOKADels4I=; b=LXHGEBT0LzgnN7 m/pBvcj9outY1yz1nnK/hQQpZ/Pf2f6kxeN+/ED20uWCOPNunrZszMy0wkjBwX5RMBzOrsbIctUYj 6TqwOEijuAeDvuhhJpptJYEXgazNe0xiu63J3W4bFAx+w9XinHUbg9XJhIA6zHtGW8bhMS3QPVkKX fryTy2rcVGLXqbvCn01cZK/MQnYsg/aDNbNLxHsKdSF7QQgsbfAx1gdTFQHgCpC5A8ktdKkdMKn0u mQi5EVk6tJrE+y94fz+oKjcrlVZ62LgULAOh01oV5cyp1M05Il5TmltkdB5o3FFcgDwsEsvIjL4d/ SKkYKq85PsW5nn8lmCdQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oBz6i-00EpKt-87; Thu, 14 Jul 2022 13:42:20 +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 1oBz5g-00Eocd-OO for linux-arm-kernel@lists.infradead.org; Thu, 14 Jul 2022 13:41:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657806075; 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=nYaKoPGAE5GuTNjUTcyk/8OnPeCKT4Q4LTaKkZkFBRE=; b=H/UE1SRusLP5anGHKm+7v1vieEh17DczxQ4FvaI+0hqmV/ALpfq4gE5qJb3nv7kZNrM1Fy TZ5nTUnXFUkILEw+pItXHzTgfm/qnWEzbJooYVMhgqB6mX0h6YbNbIWqdtnmsUV/HGD3KM sGONSp+tjyiFK2nsyGAsXm4JvZ8t3uE= 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-464-Fg9jTg7sMriWuHtX_Ith8Q-1; Thu, 14 Jul 2022 09:41:03 -0400 X-MC-Unique: Fg9jTg7sMriWuHtX_Ith8Q-1 Received: by mail-pj1-f69.google.com with SMTP id mi13-20020a17090b4b4d00b001ef9759d26aso1416350pjb.0 for ; Thu, 14 Jul 2022 06:41: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=nYaKoPGAE5GuTNjUTcyk/8OnPeCKT4Q4LTaKkZkFBRE=; b=iWG+SdKVtVkAynw+OS68rQq6hDo6QKh4OE8cfQHLc/PbPq7hlqA0jVYImqK+HtRhf+ wU7GhIO7A1o1i23qjXWS24N+6cz2zYLpt6OUPF5wzRCgO7suHrjISXXNngxpa/+65AJA le1py20z1y+0M3pUwH+uxZWQToXEJrx1J8E0N7avVW6jZh+aFTWiSLqX9QL6DhQK9uAY pMmVaOZ8dbuqv+aYiJZ7Y5lWX4YmVWIhaCI4B9ePde3KPhqRDovB5HJTqyTGgov7CtFp jfVS3ccIm1gx/tqwTRf1TVwKWWLZSrIu/luHQzty1n2YzXGPEzmFEVkhde9HuFzQ32Eb TcdQ== X-Gm-Message-State: AJIora8DAFBGLWsv/4Znft3/Giy9SefkK276M+2Ghif1/AXriZ063V46 jJd7x9LwRQD7DH+WsQfpEK6/mnDz1Avfe3Zzu/3lgYfQ19UavirM4DsbtcjYohQp6JYYfSv+Uas Q2D/Gd/Mq1xNw7aybhc50dilyE+COvGeZkB4= X-Received: by 2002:a17:90b:3c07:b0:1f0:eab4:79e4 with SMTP id pb7-20020a17090b3c0700b001f0eab479e4mr1116951pjb.186.1657806062496; Thu, 14 Jul 2022 06:41:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sPB4AJHTz7fd94myeXuSf8getkOgYveQhJicFIsXMd+oF8xCeEgRFuBRRxo5JHCdTOoHv9uw== X-Received: by 2002:a17:90b:3c07:b0:1f0:eab4:79e4 with SMTP id pb7-20020a17090b3c0700b001f0eab479e4mr1116928pjb.186.1657806062264; Thu, 14 Jul 2022 06:41:02 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id j31-20020a63fc1f000000b00419ab8f8d2csm1342551pgi.20.2022.07.14.06.41.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 06:41:01 -0700 (PDT) From: Coiby Xu To: kexec@lists.infradead.org, linux-integrity@vger.kernel.org Cc: Mimi Zohar , linux-arm-kernel@lists.infradead.org, Michal Suchanek , Baoquan He , Dave Young , Will Deacon , "Eric W . Biederman" , Chun-Yi Lee , stable@vger.kernel.org, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, Catalin Marinas , James Morse , AKASHI Takahiro , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v10 3/4] arm64: kexec_file: use more system keyrings to verify kernel image signature Date: Thu, 14 Jul 2022 21:40:26 +0800 Message-Id: <20220714134027.394370-4-coxu@redhat.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220714134027.394370-1-coxu@redhat.com> References: <20220714134027.394370-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-20220714_064116_892795_C0888F1C X-CRM114-Status: GOOD ( 14.61 ) 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, when loading a kernel image via the kexec_file_load() system call, arm64 can only use the .builtin_trusted_keys keyring to verify a signature whereas x86 can use three more keyrings i.e. .secondary_trusted_keys, .machine and .platform keyrings. For example, one resulting problem is kexec'ing a kernel image would be rejected with the error "Lockdown: kexec: kexec of unsigned images is restricted; see man kernel_lockdown.7". This patch set enables arm64 to make use of the same keyrings as x86 to verify the signature kexec'ed kernel image. Fixes: 732b7b93d849 ("arm64: kexec_file: add kernel signature verification support") Cc: stable@vger.kernel.org # 105e10e2cf1c: kexec_file: drop weak attribute from functions Cc: stable@vger.kernel.org # 34d5960af253: kexec: clean up arch_kexec_kernel_verify_sig Cc: stable@vger.kernel.org # 83b7bb2d49ae: kexec, KEYS: make the code in bzImage64_verify_sig generic Acked-by: Baoquan He Cc: kexec@lists.infradead.org Cc: keyrings@vger.kernel.org Cc: linux-security-module@vger.kernel.org Co-developed-by: Michal Suchanek Signed-off-by: Michal Suchanek Acked-by: Will Deacon Signed-off-by: Coiby Xu --- 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 }; From patchwork Thu Jul 14 13:40:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coiby Xu X-Patchwork-Id: 12917984 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 91BC0C43334 for ; Thu, 14 Jul 2022 13:43:15 +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=PV68GvftgQ+ubKITGLzMLax2UQUuXNM/Zznn41D0Ymo=; b=YN9iZietH/T8nn dVB/36xdqIQc0KMAcUHjUBVM1o5JBN+l5xTqNsKe7t9RKAFvG52x2nx2IKCalOYkZK60F/AQQBp0U XeXmbdRsyyH3Y/8nTz7s3xKvM3EPiB6pfYuCE1W7DHBt6HwGNQ2pLlK8GiAprc+Mq7CijFb8yggc5 eAP+cMrd9zoyFeUwk4gohp1sz0Um81NJFhgHsUqg8yozyT85AmpoWwzQOA0XroXxTppnGNyXljzmC A+hMlEnpjaMdun90/Bu82htDsgljzZwqj1CqeHiZwDdXBPR7WlKNgLpfxt27hCBgeJvLkvTRv9LvW Wn0nYmPDk7/Y1lveImqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oBz6T-00Ep91-1J; Thu, 14 Jul 2022 13:42:05 +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 1oBz5d-00Eoal-UW for linux-arm-kernel@lists.infradead.org; Thu, 14 Jul 2022 13:41:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657806073; 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=Sd8cjBSOdeaVjyH4f3lxl+0xYw15nzSjwpJw6bzSgLk=; b=OFcZbCyEuRKnOa/XeXIpOIJxZgZAE3FUT2ZpaAuGZgbatuhTKkwX20GYX4sWuCiyHRD8hy xjH4PRn0XzCFNGNJo/w1xgXcJOJRQmN4cDrdFzztajV8tHfwOATMlEuGlNgk27+Eo8vtez QbY6e1rYNyDpBZcp5rt9eylxJOd2R0I= Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-335-hkk2_myNO9m9Ph9SuhKbpQ-1; Thu, 14 Jul 2022 09:41:12 -0400 X-MC-Unique: hkk2_myNO9m9Ph9SuhKbpQ-1 Received: by mail-pf1-f197.google.com with SMTP id f13-20020a056a001acd00b0052ab9ae76fbso1224359pfv.20 for ; Thu, 14 Jul 2022 06:41:11 -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=Sd8cjBSOdeaVjyH4f3lxl+0xYw15nzSjwpJw6bzSgLk=; b=6TK9HK3LgcgquN9KxJM+OMfn+hMhh/RfoYLAp2lNCDphg1SbmSZl3/6R1Gz0q2oVdz NK6qbmippTPzbsz8Z3CXyL6nUsa3ifR7Pq+wGyc5Ijk7GK1OzjLPKsAYD6rVghWUDKmd 3xUmAHa2nAXRyUL1oPI8nGVqe7/qxuLGhruZ/YoqCHGsqGwlK05h3zxC/ncNiMVJJblw FiiPdDJwuVVHl7YUjxa/EqFLBJ+PT36Z2OPfL4zlYjR1QFu7D+5T8B0RcFHx1cWW8L2d Q0SdaiKmuKUpYOtgpqWbqaWSvNOMNeQ3+haU2Xl3AEh3H/3eknyDtAdDsGnHDxX/WV+K G3oA== X-Gm-Message-State: AJIora/ryVr8G13qsmniiIAErnIppZ4Glv2maA1UboQoLoNeEshmoIPm CXnPhcrKNu1pxxgStdpl9A9RGGZxoL8eEXXQTDmj+Erfo5MEJlLLVQt4sPgwJs6tNkU52FA38In DyEKyHaMZ0YASoTVf7F7nTtmIFw3+pGT8BrY= X-Received: by 2002:a17:90b:4b82:b0:1f0:196d:4204 with SMTP id lr2-20020a17090b4b8200b001f0196d4204mr16396535pjb.194.1657806070939; Thu, 14 Jul 2022 06:41:10 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v6W73kkND0lzdShUq0XCk7I59w6K6H/HhxbM9LJ4h4Bhv+gs6tfqbnzg5qbuZf1Ex6YUHUFA== X-Received: by 2002:a17:90b:4b82:b0:1f0:196d:4204 with SMTP id lr2-20020a17090b4b8200b001f0196d4204mr16396483pjb.194.1657806070591; Thu, 14 Jul 2022 06:41:10 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id h10-20020aa79f4a000000b00528d880a32fsm1663006pfr.78.2022.07.14.06.41.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 06:41:10 -0700 (PDT) From: Coiby Xu To: kexec@lists.infradead.org, linux-integrity@vger.kernel.org Cc: Mimi Zohar , linux-arm-kernel@lists.infradead.org, Michal Suchanek , Baoquan He , Dave Young , Will Deacon , "Eric W . Biederman" , Chun-Yi Lee , stable@vger.kernel.org, Philipp Rudo , keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Martin Schwidefsky , linux-s390@vger.kernel.org (open list:S390), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v10 4/4] kexec, KEYS, s390: Make use of built-in and secondary keyring for signature verification Date: Thu, 14 Jul 2022 21:40:27 +0800 Message-Id: <20220714134027.394370-5-coxu@redhat.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220714134027.394370-1-coxu@redhat.com> References: <20220714134027.394370-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-20220714_064114_127177_8F3F274F X-CRM114-Status: GOOD ( 12.93 ) 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 From: Michal Suchanek commit e23a8020ce4e ("s390/kexec_file: Signature verification prototype") adds support for KEXEC_SIG verification with keys from platform keyring but the built-in keys and secondary keyring are not used. Add support for the built-in keys and secondary keyring as x86 does. Fixes: e23a8020ce4e ("s390/kexec_file: Signature verification prototype") Cc: stable@vger.kernel.org Cc: Philipp Rudo Cc: kexec@lists.infradead.org Cc: keyrings@vger.kernel.org Cc: linux-security-module@vger.kernel.org Signed-off-by: Michal Suchanek Reviewed-by: "Lee, Chun-Yi" Acked-by: Baoquan He Signed-off-by: Coiby Xu --- arch/s390/kernel/machine_kexec_file.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/arch/s390/kernel/machine_kexec_file.c b/arch/s390/kernel/machine_kexec_file.c index 8f43575a4dd3..fc6d5f58debe 100644 --- a/arch/s390/kernel/machine_kexec_file.c +++ b/arch/s390/kernel/machine_kexec_file.c @@ -31,6 +31,7 @@ int s390_verify_sig(const char *kernel, unsigned long kernel_len) const unsigned long marker_len = sizeof(MODULE_SIG_STRING) - 1; struct module_signature *ms; unsigned long sig_len; + int ret; /* Skip signature verification when not secure IPLed. */ if (!ipl_secure_flag) @@ -65,11 +66,18 @@ int s390_verify_sig(const char *kernel, unsigned long kernel_len) return -EBADMSG; } - return verify_pkcs7_signature(kernel, kernel_len, - kernel + kernel_len, sig_len, - VERIFY_USE_PLATFORM_KEYRING, - VERIFYING_MODULE_SIGNATURE, - NULL, NULL); + ret = verify_pkcs7_signature(kernel, kernel_len, + kernel + kernel_len, sig_len, + VERIFY_USE_SECONDARY_KEYRING, + VERIFYING_MODULE_SIGNATURE, + NULL, NULL); + if (ret == -ENOKEY && IS_ENABLED(CONFIG_INTEGRITY_PLATFORM_KEYRING)) + ret = verify_pkcs7_signature(kernel, kernel_len, + kernel + kernel_len, sig_len, + VERIFY_USE_PLATFORM_KEYRING, + VERIFYING_MODULE_SIGNATURE, + NULL, NULL); + return ret; } #endif /* CONFIG_KEXEC_SIG */