Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4477383imw; Tue, 19 Jul 2022 07:20:48 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sfk2iOcjsGn5LGVT0xrdNR2E8xxzD6FN5JtZ1MUu4IXVRhmyaslZdHCS59aWI8Nt7Q6TPz X-Received: by 2002:a17:906:cc5a:b0:72b:1459:6faa with SMTP id mm26-20020a170906cc5a00b0072b14596faamr31285878ejb.221.1658240448694; Tue, 19 Jul 2022 07:20:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658240448; cv=none; d=google.com; s=arc-20160816; b=mRyFq4E5oRUiuqoYJOZcdMeAtfOYZQXplYxqYnAS5LFJAkfUYikg3Q20zzAYjDmTQv soAI2bbKA8rVLXLsBOIRftalpLF2AEeok4Tz3sg6PSd2xrlZ/kKgEUuaeNz3cupAwVtK biyZMNeEelyh5PRqrLY2UF9qZYQbsDeGw/UHHK6kJShvI3poNIsdB2GWxScZIyzfw1SS PEykAKeMKDxm6vqgLtmk4IuAZzlrLt1vF0u97dbBy1DPq3luDDMhVK2owHgJkyk4V7Th pGUcIc0dHKkf/1Km5hAR/Jukxz0dgOu/VvDP1GUjPEftsdggyYLSvTLG+HjDvNb7bsw1 mW2Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=EeGwaEZj/1YOOZWtw3VtNyLAEpHymBbKb8bc+74xTDY=; b=YmiFVQIph5gxseD5rbQQzrUb0nSjnGzzAT3/7m0Mvzkvo6vwUXpP1smQQ3pXHYLMWD IzeGk+A+I9JUuytMgJBKtQBSMBcs3WxAE33jLR5llR5WYBeMzbLhP4HgudRlatEbFb82 cugH2Ym50qwBRFRuF8cNbfvwH6qHIqPbtXi9fzrMkDvleKkqWsMDEEIp1TFQ175ciwEN ZlO/sjzmDBDzLn/wu8e80/NnCfH/AEIHwngkR026W2ocUrmHwPvfRdxJh5RLB5R1KWhr 6WtViG+wcNvh5IXZ7wRf8WEkuQ6L/uG9dhU3Hm/pDgeqYp2R70gU8oWWqk0Y7RdntzoV Ef/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KskVcakU; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gs9-20020a1709072d0900b0072f1f41bf94si12366294ejc.244.2022.07.19.07.20.23; Tue, 19 Jul 2022 07:20:48 -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=@linuxfoundation.org header.s=korg header.b=KskVcakU; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241121AbiGSMlQ (ORCPT + 99 others); Tue, 19 Jul 2022 08:41:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241313AbiGSMjU (ORCPT ); Tue, 19 Jul 2022 08:39:20 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EC8C52FC8; Tue, 19 Jul 2022 05:15:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C9C90B81B08; Tue, 19 Jul 2022 12:15:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34B69C341CA; Tue, 19 Jul 2022 12:15:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232939; bh=cG48VpzWujqCH5sdjCd+09tH1Hd3kq6jlJ2Ki0S3mII=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KskVcakUJBWozpQTKT44aXSo36ORgS9Wy1C6775JnsX9IiNMCNO4Ix0E4eETeefKT 6g6e/xsnfldTtmWqHzldhTdnlSpiBTU+nMqVnNGE5wvrCmg72RElmHACzLPnH3+VFQ EDK7zCOfNBdsPfZYWMR5H68tl5i8q1wceQ9xGK04= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Coiby Xu , Mimi Zohar , Sasha Levin Subject: [PATCH 5.15 095/167] ima: force signature verification when CONFIG_KEXEC_SIG is configured Date: Tue, 19 Jul 2022 13:53:47 +0200 Message-Id: <20220719114705.675324341@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114656.750574879@linuxfoundation.org> References: <20220719114656.750574879@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 From: Coiby Xu [ Upstream commit af16df54b89dee72df253abc5e7b5e8a6d16c11c ] Currently, an unsigned kernel could be kexec'ed when IMA arch specific policy is configured unless lockdown is enabled. Enforce kernel signature verification check in the kexec_file_load syscall when IMA arch specific policy is configured. Fixes: 99d5cadfde2b ("kexec_file: split KEXEC_VERIFY_SIG into KEXEC_SIG and KEXEC_SIG_FORCE") Reported-and-suggested-by: Mimi Zohar Signed-off-by: Coiby Xu Signed-off-by: Mimi Zohar Signed-off-by: Sasha Levin --- include/linux/kexec.h | 6 ++++++ kernel/kexec_file.c | 11 ++++++++++- security/integrity/ima/ima_efi.c | 2 ++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 33be67c2f7ff..cf042d41c87b 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -452,6 +452,12 @@ static inline int kexec_crash_loaded(void) { return 0; } #define kexec_in_progress false #endif /* CONFIG_KEXEC_CORE */ +#ifdef CONFIG_KEXEC_SIG +void set_kexec_sig_enforced(void); +#else +static inline void set_kexec_sig_enforced(void) {} +#endif + #endif /* !defined(__ASSEBMLY__) */ #endif /* LINUX_KEXEC_H */ diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index e289e60ba3ad..f7a4fd4d243f 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -29,6 +29,15 @@ #include #include "kexec_internal.h" +#ifdef CONFIG_KEXEC_SIG +static bool sig_enforce = IS_ENABLED(CONFIG_KEXEC_SIG_FORCE); + +void set_kexec_sig_enforced(void) +{ + sig_enforce = true; +} +#endif + static int kexec_calculate_store_digests(struct kimage *image); /* @@ -159,7 +168,7 @@ kimage_validate_signature(struct kimage *image) image->kernel_buf_len); if (ret) { - if (IS_ENABLED(CONFIG_KEXEC_SIG_FORCE)) { + if (sig_enforce) { pr_notice("Enforced kernel signature verification failed (%d).\n", ret); return ret; } diff --git a/security/integrity/ima/ima_efi.c b/security/integrity/ima/ima_efi.c index 71786d01946f..9db66fe310d4 100644 --- a/security/integrity/ima/ima_efi.c +++ b/security/integrity/ima/ima_efi.c @@ -67,6 +67,8 @@ const char * const *arch_get_ima_policy(void) if (IS_ENABLED(CONFIG_IMA_ARCH_POLICY) && arch_ima_get_secureboot()) { if (IS_ENABLED(CONFIG_MODULE_SIG)) set_module_sig_enforced(); + if (IS_ENABLED(CONFIG_KEXEC_SIG)) + set_kexec_sig_enforced(); return sb_arch_rules; } return NULL; -- 2.35.1