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: 12812831 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6AA06C433EF for ; Thu, 14 Apr 2022 01:44:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239476AbiDNBqs (ORCPT ); Wed, 13 Apr 2022 21:46:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239487AbiDNBqq (ORCPT ); Wed, 13 Apr 2022 21:46:46 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8ECB5C35 for ; Wed, 13 Apr 2022 18:44:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649900661; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rZWiQAF9GRIP7WU8AYwYkyBhsIYEfbcorZXD7uAiyqQ=; b=aFW65Cp9B6fSGMVo6hPBII3kNnb33LH3KjcDPMzAmihRkqaUBX0mHCqKtZNQnNLy2S5KgC bCqXOxhbAtwCKTTEVvDVbxtvgWmjWBXt/EcvpoZxnFQBhBldYsWY7BRs30iOvfzSNhl+Bv edaVdj4cwJSh3fXTczEg1CQMlwQxi7w= Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-99-rII5iLUTPZaj_tkEQ4gkLg-1; Wed, 13 Apr 2022 21:44:20 -0400 X-MC-Unique: rII5iLUTPZaj_tkEQ4gkLg-1 Received: by mail-pj1-f71.google.com with SMTP id z88-20020a17090a6d6100b001cb89a1969fso2061874pjj.1 for ; Wed, 13 Apr 2022 18:44:20 -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=pBZDGhMCs1kbAhmbt8h+mfvoT1DVfb5kIqlaxPxT+aJaxuZ77MkM+iZjKp99i7kt3u JzIffqw30OpykCBoDTfVM6A4VDfpVu2Iu+INO8Z/OKE/WSoRP44o7kFBD9Q45L5QeNhk kj55OzCApCsNkWfeRAMCmRS/u9whyyStfRnnRBjEFONs7EW9PDVCY4fgAWPSVp/0LLeT 3iWUf2Kk/Vb05uRlAc8wB37fiKxL4bXigBGBZ4l6g0tIu6RdxF/F4xkC7CrSLAaq5ULj Zb1VBG53+mVX07/MjmL5Z6f/gdO/5w+8NgrOCXhCWT5wvccPi+PUtHXSn+FR7arCZixD iL/Q== X-Gm-Message-State: AOAM530xWSIjffE/sp9H9C+C2A9pIKByJSJIeyBdk8rodQrxUU7GXdpU t0iExmiQnSKRNKW55yPqPol4tSw6k7fT14KWB/pN4TCI8xq87mRkkt26QcII9XCRd7wRFNKaKAl SYn9zAJWMS9D6ED/rDY0= X-Received: by 2002:a17:90a:dd45:b0:1bc:9466:9b64 with SMTP id u5-20020a17090add4500b001bc94669b64mr1694827pjv.23.1649900659137; 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 Precedence: bulk List-ID: X-Mailing-List: keyrings@vger.kernel.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 };