From patchwork Thu Apr 14 01:43:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coiby Xu X-Patchwork-Id: 12812827 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 3BAC1C433EF for ; Thu, 14 Apr 2022 01:45:53 +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=j2UaAbuqN0GhbTFxE5THJ07NeZpzhcmUUUoz9Ia0jdc=; b=rg14m5zdwiFLUu J+5aBkHkE7entUl2lGOHPHGae5bOhfihaiBIGfT8+tzPCUvknfJpCR/fQnyDoATHSFU1vxIX0ahKx sxJkXJny1RQJE70NWFBo2rOaYKEk3eIIzvP2Dr0bbXHHelb0C3l1LcSX8xiwR4w8olcH3d48eX9ax p1zbS4R2UrlSLj4I3LyU9Exyl9Wc2aeZu4AomUaG8YBJWVg7iEGmU/+uYiUKfkZlxc3VzCLgTlmRJ /3ZEgWGavSHQNHND4x5Ez+jlqB7oBMjZ3cab6skHYmEZNWm4CTdu1w7wlyqrR5NUcJDsXSmtPuwcT Qy2v7bSYxKG3cxkus3hw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1neoXF-003J2R-TM; Thu, 14 Apr 2022 01:44:38 +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 1neoX2-003Iut-1B for linux-arm-kernel@lists.infradead.org; Thu, 14 Apr 2022 01:44:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649900663; 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=rZWiQAF9GRIP7WU8AYwYkyBhsIYEfbcorZXD7uAiyqQ=; b=YSBpawGx0AvNmr+RobPmhGRbzrs8X9bXok0ykJ4Aw6B6mKK4aUHCSpgZhm8TTPTul2pLEz PxvwLLauW/5DTCcgnSGvUua69PURhoc3dBKbLu4OVGId2Nlih5YmyjdmHmKaH82yUoYpSx yXrRCb1ohl94qlmcotjVbZYsLc8uXQE= Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-352-fr8LehWlN5KJW5Ou3NDaYg-1; Wed, 13 Apr 2022 21:44:20 -0400 X-MC-Unique: fr8LehWlN5KJW5Ou3NDaYg-1 Received: by mail-pg1-f198.google.com with SMTP id z132-20020a63338a000000b003844e317066so1957806pgz.19 for ; Wed, 13 Apr 2022 18:44:19 -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=rZWiQAF9GRIP7WU8AYwYkyBhsIYEfbcorZXD7uAiyqQ=; b=l/h6ji/mhsl2yEO5cQZ8kxBtQEOCa+N1WFpkC2armjq4hrv8Xnh5TZeNuzj9ebYmMh 3+m7hLHolonLAOrn6FJdKlWmKdrRT077wGor9P7jiw9P+zVuvl1fpZ9qSzRmvc3PXncO Iq3tef2K/gU2dfPV57hjGnDE5TmXXB5+xxUNRb01zHesb68zU8UJU0lfltrMMtMBKpW7 5PuQIugQ+50SpH7xoiq7cvRr11hJOfe1MMh2d6m4fDvGonzDvABJ423XzkjzyajBAO4F grTaUno9iwYIIElnXDfpLzwixpSTMwyGPBhT9Bryb8lTgS7D9WpH4hFtUs/TZj4/XYPa PEfQ== X-Gm-Message-State: AOAM533FPrJFpomH3Pkp3I9xmE/T66b/dbsMvBnqArNxC+MVwXkVnges PzWP9voAJnrWy59SvKAz5MPppWGTLjsEcWyskUOYztnb2eYsZvOD2kecBYjMU+/+dwCjJnOhZDA +oGv6yCmvEoNB6VmxDkkKz3LKCBjT+iYbFks= X-Received: by 2002:a17:90a:dd45:b0:1bc:9466:9b64 with SMTP id u5-20020a17090add4500b001bc94669b64mr1694830pjv.23.1649900659138; Wed, 13 Apr 2022 18:44:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdzkDNxJ5ETNGa8+WNGA9rufymeL8qpXrk4exAuId9yogv97m9d/zBf7JK2uUxgm00wjeIBg== X-Received: by 2002:a17:90a:dd45:b0:1bc:9466:9b64 with SMTP id u5-20020a17090add4500b001bc94669b64mr1694808pjv.23.1649900658928; Wed, 13 Apr 2022 18:44:18 -0700 (PDT) Received: from localhost ([240e:3a1:31c:360:52fc:c968:cb41:efbc]) by smtp.gmail.com with ESMTPSA id e6-20020a056a001a8600b004fac74c8382sm334069pfv.47.2022.04.13.18.44.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 18:44:18 -0700 (PDT) From: Coiby Xu To: kexec@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org, Michal Suchanek , Baoquan He , Dave Young , Will Deacon , "Eric W . Biederman" , Mimi Zohar , Chun-Yi Lee , keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, stable@kernel.org, Catalin Marinas , James Morse , AKASHI Takahiro , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v6 3/4] arm64: kexec_file: use more system keyrings to verify kernel image signature Date: Thu, 14 Apr 2022 09:43:43 +0800 Message-Id: <20220414014344.228523-4-coxu@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220414014344.228523-1-coxu@redhat.com> References: <20220414014344.228523-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-20220413_184424_163500_BC4E38B4 X-CRM114-Status: GOOD ( 14.06 ) 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 happens because image_verify_sig uses only the primary keyring that contains only kernel built-in keys to verify the kexec image. This patch allows to verify arm64 kernel image signature using not only .builtin_trusted_keys but also .platform and .secondary_trusted_keys keyring. Fixes: 732b7b93d849 ("arm64: kexec_file: add kernel signature verification support") Cc: kexec@lists.infradead.org Cc: keyrings@vger.kernel.org Cc: linux-security-module@vger.kernel.org Cc: stable@kernel.org Co-developed-by: Michal Suchanek Signed-off-by: Michal Suchanek Acked-by: Will Deacon Signed-off-by: Coiby Xu Acked-by: Baoquan He --- 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 };