From patchwork Fri Aug 25 06:18:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengen Du X-Patchwork-Id: 1825794 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=ocHqcScp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RX8sv1YTdz1yg8 for ; Fri, 25 Aug 2023 16:18:59 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1qZQ9j-0004VQ-BI; Fri, 25 Aug 2023 06:18:51 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1qZQ9g-0004TP-1F for kernel-team@lists.ubuntu.com; Fri, 25 Aug 2023 06:18:48 +0000 Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id CACF73F21F for ; Fri, 25 Aug 2023 06:18:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1692944327; bh=xhXV4Hk839H5iwPbE5GVmiOWTcXerJNJbhtO2vylqqU=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ocHqcScpwU0V6ITlscSoZCzjaI1cF5r9F/DPPAr2V8ldrRHRcpqXAF+28wuq1ysQn uSD2Y0giE280QNemlkNvye9VZknTiOUieskYC1V3QJaBQAV5en6nkIAe7uqiqCLhrt mUkKMIsdwp2sb53L0mv2+cSODXYEWx0K90sZvijICv468sWS3A+Ynxrqtt63ytDkV8 yhsbMb6VpK0Z65qpY5eEO1a/Rg7FAIduhyJiDJUAf8yS3oYXDz1JaniMNH3hUGV1es l/fiebGHKum/cnD7KwGoTq93HgL5+Cc97RfwK5hsm6VaaEkUYYnWcQK4zFUjP0fz+Q z/UR827HKTyXg== Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-68bf123af64so764868b3a.2 for ; Thu, 24 Aug 2023 23:18:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692944326; x=1693549126; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xhXV4Hk839H5iwPbE5GVmiOWTcXerJNJbhtO2vylqqU=; b=UOIXudKSPdzQXP1g6CKHN6XloeCBvRh31vceU6cdTQLsyMdvsit0iX2zvdgtEgiJcR 8GxsiW49xtqC/a1gPUsD3AKWYQ4F55axMpVnKC/0xwnreQgfwsRVZ7aCZPxTjt0QDz+s sjYvpQbMKIrRoxOoEwwnWcju9F+XJ46BW7902QSXo133b5V5aX2GhtQzobiJLAPpC1Hf mEcG8ebYX2rlm0wwRDZXCz0wDSElEX672G1K568Y1KGVR5uo/5IIspWFL08TRjsLWiWA VSp1coFGLRoLaifVo9TlFBtYkZR3Ix93CupGW7AlWzPJaIVHBbKD/qkIZSVZcihiU3G9 vxqQ== X-Gm-Message-State: AOJu0Yz37uwqmFY65Cew9Ukgoj7stONTwyt2DGD6rUWHICJRPStXc7Kd slYuq2F6wftCYu1WibFxTXLvnEzeLeAF5J+FMdUsp/zNzfz/Sj1T1A83U6BOYkTGVIX1ljBoeKC nj27Ku9Jrf2pcGB7akZhcWRHor1G8Sv0ziNPt2W3r5uh6GmFnNQ3VhpM= X-Received: by 2002:a05:6a00:1492:b0:68a:4312:e0d6 with SMTP id v18-20020a056a00149200b0068a4312e0d6mr16749686pfu.10.1692944326124; Thu, 24 Aug 2023 23:18:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGniWfVtJQHjdNDn4PNQLHuV54v4uGD4AqF7Y+o4DoMquLGCBzSPEVA38syPKdmBazjc2+rYA== X-Received: by 2002:a05:6a00:1492:b0:68a:4312:e0d6 with SMTP id v18-20020a056a00149200b0068a4312e0d6mr16749676pfu.10.1692944325787; Thu, 24 Aug 2023 23:18:45 -0700 (PDT) Received: from chengendu.. (111-248-109-24.dynamic-ip.hinet.net. [111.248.109.24]) by smtp.gmail.com with ESMTPSA id u4-20020aa78484000000b00660d80087a8sm728664pfn.187.2023.08.24.23.18.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 23:18:45 -0700 (PDT) From: Chengen Du To: kernel-team@lists.ubuntu.com Subject: [SRU][J][PATCH 2/3] kexec, KEYS: make the code in bzImage64_verify_sig generic Date: Fri, 25 Aug 2023 14:18:38 +0800 Message-Id: <20230825061839.52444-3-chengen.du@canonical.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230825061839.52444-1-chengen.du@canonical.com> References: <20230825061839.52444-1-chengen.du@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Coiby Xu 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 Signed-off-by: Mimi Zohar (backported from commit c903dae8941deb55043ee46ded29e84e97cd84bb) [chengen - not to adopt the refined function, kexec_image_verify_sig] Signed-off-by: Chengen Du --- 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 88c289ce3039..6a2e02276801 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -19,6 +19,7 @@ #include #include +#include #ifdef CONFIG_KEXEC_CORE #include @@ -194,6 +195,12 @@ int arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, #endif int arch_kexec_locate_mem_hole(struct kexec_buf *kbuf); +#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 1fb7ff690577..f187ee019b91 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -159,6 +159,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 kimage_validate_signature(struct kimage *image) {