Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp210270iob; Thu, 12 May 2022 23:16:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2qmdZKgWPn34hXbgeJ6KmrpaZFE2YvF3+h9MBsbSf6hw3JNBMby9exqDo77U8EuWnbK3k X-Received: by 2002:a17:90b:2311:b0:1d9:277e:edad with SMTP id mt17-20020a17090b231100b001d9277eedadmr3307649pjb.190.1652422605514; Thu, 12 May 2022 23:16:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652422605; cv=none; d=google.com; s=arc-20160816; b=l7AHv9AtIpwboSdHOIj5B9/D55Wlu86XKcPvcpagN5vHk/6tZOMOVhTkFSTxGipeK2 xSiEcmKYlj8sjBCOYKpvQgR48uocLGDbtJ9xYDMFanspthWXq7YhpWGrwHUuq6ZKGPlK dSs46VVUXcMQ8oeYw01X8E9OyJkvBYbC0XU8ebdNmyHZ/vEgJ7sa1jSroLIynfQr+k9M FfGR1Kb+XhZmjsKWYhJr23U9ztUIWgpl9z2mBZGlNv45Y1IssD3D6iq+8T11coIdBNDp YVHhd2tI2DIusU4hW6qNlF4+3iLfSlXi2sohUiwW5r5hZGRigRyA63ERFEQrLuzoM/6Q toVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vgYiACZD6/G9rcKhEjYBMoQ95BxFfvkmBPg17ZEoIno=; b=gs6PmUARo+uQ/OuskIlwsAEndoDJ1ktzxKw961hfb/MZ+E1wWltZALWcoOYgH8t0qu r6xdpthJLoDH242OSZkbKCvB24ygM6Tkk1vgszAVByJodPaimkbqkuT5Tq1IU4179HYb ar58y+Z1yPlMv2OucXHfo4YGF49pYiTrAe4CIUTHHhwsT8mySVJC7IpXgAmtCSi7dom8 WPQLBxsgCOPi02/PWHtxTy6QiJxTNqroXAUTwgdYKzNs4kZOM8WoGokNf9hJTl7IxFLS 2cWZ5B7DbT8UgHm5wweiwXo+iSIEYjugUU9wdSHUDQYBSK9EHLvTrMBY1r/T9FoOtoZ0 z8ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=O3m7qXPh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v24-20020a63f858000000b003aae4f1097asi1738820pgj.559.2022.05.12.23.16.33; Thu, 12 May 2022 23:16:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=O3m7qXPh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236610AbiELHCW (ORCPT + 99 others); Thu, 12 May 2022 03:02:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350644AbiELHCL (ORCPT ); Thu, 12 May 2022 03:02:11 -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 EC50C4D604 for ; Thu, 12 May 2022 00:01:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652338902; 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=vgYiACZD6/G9rcKhEjYBMoQ95BxFfvkmBPg17ZEoIno=; b=O3m7qXPhaRfiMzbTxPMTc65ExmqwyKewEWNU+BvqGnBgw/4rPDCV7dAhMaRIWgQRyn+qdR I1KjdtT4T0IlzDI8/in9duSJD+3yn6ZRsbKIiH14p1QgUeUgPCTXLi07ogznYiYmCvoZ5w 77WfbP9WM5hm6k+lp+QchWTQrEjttvA= Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-619-iLrkcWd8OkmgMzezWuepRQ-1; Thu, 12 May 2022 03:01:33 -0400 X-MC-Unique: iLrkcWd8OkmgMzezWuepRQ-1 Received: by mail-pl1-f199.google.com with SMTP id i4-20020a17090332c400b0015f099f9582so2304522plr.11 for ; Thu, 12 May 2022 00:01:33 -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=vgYiACZD6/G9rcKhEjYBMoQ95BxFfvkmBPg17ZEoIno=; b=vyXcqqAyzNniqFylOyro5s2lQh9fJx6Q2WhQmoZr1dfKGtH+881d/U/LEp94W/aRrD JRRyrOu91oqU0F9QRUSVSQYZvNw6Me0s3wk2m0k7Ese7dNFO4hU/BFuqPE1sJf98VrYC S7BL3JryPgtFEVooJjfU/UCzTdyjCevCHlao5TnzL1hwIGljoJbEGtbQtDYNQNZgYFY7 kKrrtkExRBJA2+w8HO0yM0FY79E15hvZC2VAxBY3SN7CsR9RR6hgoUjKAGG8NfBp48xr Ye3KaQUMfqKh6O7wDzFJi/3hIr7N1yuTAsF6cWZfGCNULLvJSYc9jqa61p9js88sj4Wr YEYw== X-Gm-Message-State: AOAM530JxLm1ehTYOI8IIESMrc0OppyhOTZSKi4KUm458Uf8U3R1ANHV UHht0qcmooIhHHHrbh0Vx22ZBilRWrx+GGT3lz3NiLHIQeOx3ZdWzvefyOiUzWLqYHz3/Pr0s+6 PAAUA4oypJwoTguGPSS1SfVtM X-Received: by 2002:a63:fd51:0:b0:3c1:977e:1fed with SMTP id m17-20020a63fd51000000b003c1977e1fedmr23315479pgj.246.1652338892409; Thu, 12 May 2022 00:01:32 -0700 (PDT) X-Received: by 2002:a63:fd51:0:b0:3c1:977e:1fed with SMTP id m17-20020a63fd51000000b003c1977e1fedmr23315454pgj.246.1652338892150; Thu, 12 May 2022 00:01:32 -0700 (PDT) Received: from localhost ([240e:3a1:2e9:efa0:e73c:e550:ac9e:58fd]) by smtp.gmail.com with ESMTPSA id y24-20020a63de58000000b003c14af50643sm1035149pgi.91.2022.05.12.00.01.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 00:01:31 -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, 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 v8 2/4] kexec, KEYS: make the code in bzImage64_verify_sig generic Date: Thu, 12 May 2022 15:01:21 +0800 Message-Id: <20220512070123.29486-3-coxu@redhat.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220512070123.29486-1-coxu@redhat.com> References: <20220512070123.29486-1-coxu@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 makes 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. 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 413235c6c797..da83abfc628b 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. */ @@ -202,6 +203,12 @@ int arch_kexec_apply_relocations(struct purgatory_info *pi, const Elf_Shdr *relsec, const Elf_Shdr *symtab); int arch_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); +#endif +#endif int arch_kexec_locate_mem_hole(struct kexec_buf *kbuf); extern int kexec_add_buffer(struct kexec_buf *kbuf); diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 3720435807eb..754885b96aab 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -165,6 +165,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) { -- 2.35.3