Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4373196imw; Tue, 19 Jul 2022 05:33:55 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tTmN5+BUkUw6RB0cgNa31IEjIWrCeLpIWEaFfY/sxHKCgETOXoLMMjO82crw7610FkU84j X-Received: by 2002:a17:902:dc81:b0:16c:7132:cc57 with SMTP id n1-20020a170902dc8100b0016c7132cc57mr33557243pld.87.1658234035418; Tue, 19 Jul 2022 05:33:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658234035; cv=none; d=google.com; s=arc-20160816; b=q4ASguOGrLccH0/AybV65Vbx97+OB5cmJHliQ97oGwqorG5x9UpVbdcH3TnPOBShqB PlE/8dyuqVaz8du8NpJV3BPLzWkO5wgb+l2Qs/Ew7Ck53OUjgDvoaRdvLrevh2c6mJp4 ykqb41Cx57i/tqF0PqZ2aSEozKmLiWjJYyS6jV09dBsDaWi1BkMqDLZzjJedYi2VAHoT TBGhtjs9D06BGBHGzXSrTNF9ycpy3uO2H6WJG+Jfta0js6p8X7XwIw0I6EanaGGHtudj yFaD3cLfkpiupoZE9FnRRpk0bAQvt4GJ+e2G84TdCQ7KZNhnZt/6/z2Va+MRxuzwERdj DOxA== 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=9v+3hW8J4hlBJbaKTs89QI+rYcCZ/jn/3LvzMYzayQw=; b=ag3CSUgmecx4gldM9qUXlQA2r0kW8JyD8G0Dlno55XDim4nEyuln6u05JyptZzaABy PIFTlUjh+I8KIu1HZjFvcmqjQILa5fsoOIrYazP9ILu7Od7dvPIrfBeS46MK4fov5kH4 G1zzc2DVsS8vO4ApvmY6tj0d53bYcLBTO5OzHJcsH/xm6b+5Jp560cwfFY9e2NBYF9Xz vkYTtqPV/IlzLv8zX6ZDFIFut2/IF8iIOj2jAIDJBOkRIg91YHS9jeUuJF7VYd81f8mM PDz3XYXBg6dhZJsQySeFtyCFyyNffwSsez3JwhG32piaav/ve26puaKKuAAxE5vh59Q+ THgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=J2sNmNEL; 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 d8-20020a170902b70800b0016cffdac0ddsi3209780pls.278.2022.07.19.05.33.39; Tue, 19 Jul 2022 05:33:55 -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=J2sNmNEL; 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 S239931AbiGSM0S (ORCPT + 99 others); Tue, 19 Jul 2022 08:26:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240207AbiGSMYp (ORCPT ); Tue, 19 Jul 2022 08:24:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F2924A81A; Tue, 19 Jul 2022 05:09:32 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 08CEC6177F; Tue, 19 Jul 2022 12:09:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7192C341D3; Tue, 19 Jul 2022 12:09:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232557; bh=vjxibplRmYoM5AjjTBzU2tI1aoEEjXJTn1NajLk+/d8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J2sNmNEL6miIgnVyy1aMirhGIXsiWpMMpuY+2CSDQzB4eTOu4b5a3YP2TQT/fdVAa TaMBpDXxBEoytt9ooNVScNnUCxxVH7jWQy8ZZh6kf0XMVR9IDjfdRF36DVOB6Dt+nY Zm2WkaOK3LchVsD4/KgykkcFx5MgT0EQGxo85sbM= 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.10 065/112] ima: force signature verification when CONFIG_KEXEC_SIG is configured Date: Tue, 19 Jul 2022 13:53:58 +0200 Message-Id: <20220719114632.773018707@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114626.156073229@linuxfoundation.org> References: <20220719114626.156073229@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 --- arch/x86/kernel/ima_arch.c | 2 ++ include/linux/kexec.h | 6 ++++++ kernel/kexec_file.c | 11 ++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/ima_arch.c b/arch/x86/kernel/ima_arch.c index 7dfb1e808928..bd218470d145 100644 --- a/arch/x86/kernel/ima_arch.c +++ b/arch/x86/kernel/ima_arch.c @@ -88,6 +88,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; diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 037192c3a46f..a1f12e959bba 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -442,6 +442,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 2e0f0b3fb9ab..fff11916aba3 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; } -- 2.35.1