Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp1202855rdb; Sun, 20 Aug 2023 23:34:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFFph2t/LX0NuKiqN+BHE2CcssoIBTFzqbM2RTrfxsgaMxs8qii+joSvzC3/crVQ/1okhHn X-Received: by 2002:a17:903:11cc:b0:1b9:da8b:4eac with SMTP id q12-20020a17090311cc00b001b9da8b4eacmr3545481plh.56.1692599652061; Sun, 20 Aug 2023 23:34:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692599652; cv=none; d=google.com; s=arc-20160816; b=AwiY93roTrVzAUx3rX0dfr13bZ7OgPcBQyLW0iWXejIZdm8TdWS2igQbSlJlkJCYLQ k+aP4W07TZArYGMM1VnYOk6OgQNMAnCyw4u1odgI73AKWz3Q1+vKtk/UuzTeu6XQkGLA 8eLm1wx4UgBEh7WloqiEt6D8QleimSgi6kDcLL621+9JqeLrGGHelVmykWWf8m7e1dwd Zswfy/mP40mpYc43AV9EbVpu9Ptb12pJHpVp4QEZy6mJfu4b4Ns5mhRXGrLHLR5s9Byz U6g6squ+DRk5UIAL+KKkIYM3QM/bGz4EAOXFErL06ev71dnTLXj/vcVKpcFSF2neRRgd q+gQ== 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=2oQyuFqcNWTWvYoeXdOO9zAQhyNBhidiKegrzrcovjI=; fh=1KVrD/LnRsN9N7k2d12iARV4DA2tVMW012QtKSrD46c=; b=NU9NkGfA3xSAUtMAfDQpOutrpM10BhSqkwqE4cqo7KrkEPZ8LZZTwJtcYqcJOIY8gH KVNT896AwthRsWT3v2NFaXJLu1XqBnwlAMQvrQ1VQFbgs2ZptJxg82nMLMzZG3mvHhta 6SK3PTbeXVu/1eOQtY7+S9w0+igpS1AuPkxBLm/s7rdsvBQ6ELBhrhEklJQlZ+tUn6HF fuDlx861cyiHx+MapYvaVAkq1HfkCsxWclSnVnupJGdChCROQlaYVcfBUEQuJC/6lmR2 2g+BgDsGveqEVwjT46TYsNuKSCqxHtD93TNPhPSsQG6qrjNBwWvs9SDEMuaexhTDaj8L Q8hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GnLGpssL; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o20-20020a170902e01400b001bd94d06ce4si6231054plo.171.2023.08.20.23.34.00; Sun, 20 Aug 2023 23:34:12 -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=@kernel.org header.s=k20201202 header.b=GnLGpssL; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232344AbjHUBTw (ORCPT + 99 others); Sun, 20 Aug 2023 21:19:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232280AbjHUBTk (ORCPT ); Sun, 20 Aug 2023 21:19:40 -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 EA75EA0 for ; Sun, 20 Aug 2023 18:19:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 81601625E7 for ; Mon, 21 Aug 2023 01:19:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 771CAC433C7; Mon, 21 Aug 2023 01:19:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692580774; bh=VITXRxzmYd+x/eSRYov7MGSe9fadUUYm+SsVHZIsK90=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GnLGpssLnig19O7XuSvdqyualyIfVZTWxLdMDmAAacwE+GksIRYECU8G7PQslNpbK d6oCA8KNuFpFq3VATCubAtmsAKmBk2NxTrojDL5nd1iFqvISpn4+w7FAo3LDlKYtWR UcP1OVJmK56gMEZPq/A/5nmiI2NovhEel36iKEWx1xohExLur1nEJjQAI6GbuaiyIG IKSyv/Md+WFfSif6c5kFykUcW56oatRIPlCwOi1whRLTu00j7NBotuXEwgckCA8DOs PxapRxvuGyPIuHX46fwMyE430CCwrQ/KOxewOJC0Ol8rSjxo3xWU1Jr2ZMjouP9LQ4 vNzbMmLyEdQvg== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Borislav Petkov , Peter Zijlstra , Babu Moger , Paolo Bonzini , Sean Christopherson , David.Kaplan@amd.com, Andrew Cooper , Nikolay Borisov , gregkh@linuxfoundation.org, Thomas Gleixner Subject: [PATCH 13/22] x86/srso: Fix vulnerability reporting for missing microcode Date: Sun, 20 Aug 2023 18:19:10 -0700 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 The SRSO default safe-ret mitigation is reported as "mitigated" even if microcode hasn't been updated. That's wrong because userspace may still be vulnerable to SRSO attacks due to IBPB not flushing branch type predictions. Report the safe-ret + !microcode case as vulnerable. Also report the microcode-only case as vulnerable as it leaves the kernel open to attacks. Fixes: fb3bd914b3ec ("x86/srso: Add a Speculative RAS Overflow mitigation") Signed-off-by: Josh Poimboeuf --- Documentation/admin-guide/hw-vuln/srso.rst | 22 +++++++++---- arch/x86/kernel/cpu/bugs.c | 36 +++++++++++++--------- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/Documentation/admin-guide/hw-vuln/srso.rst b/Documentation/admin-guide/hw-vuln/srso.rst index b6cfb51cb0b4..4516719e00b5 100644 --- a/Documentation/admin-guide/hw-vuln/srso.rst +++ b/Documentation/admin-guide/hw-vuln/srso.rst @@ -46,12 +46,22 @@ The possible values in this file are: The processor is not vulnerable - * 'Vulnerable: no microcode': +* 'Vulnerable': + + The processor is vulnerable and no mitigations have been applied. + + * 'Vulnerable: No microcode': The processor is vulnerable, no microcode extending IBPB functionality to address the vulnerability has been applied. - * 'Mitigation: microcode': + * 'Vulnerable: Safe RET, no microcode': + + The "Safe Ret" mitigation (see below) has been applied to protect the + kernel, but the IBPB-extending microcode has not been applied. User + space tasks may still be vulnerable. + + * 'Vulnerable: Microcode, no safe RET': Extended IBPB functionality microcode patch has been applied. It does not address User->Kernel and Guest->Host transitions protection but it @@ -72,11 +82,11 @@ The possible values in this file are: (spec_rstack_overflow=microcode) - * 'Mitigation: safe RET': + * 'Mitigation: Safe RET': - Software-only mitigation. It complements the extended IBPB microcode - patch functionality by addressing User->Kernel and Guest->Host - transitions protection. + Combined microcode/software mitigation. It complements the + extended IBPB microcode patch functionality by addressing + User->Kernel and Guest->Host transitions protection. Selected by default or by spec_rstack_overflow=safe-ret diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index aeddd5ce9f34..f24c0f7e3e8a 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -2353,6 +2353,8 @@ early_param("l1tf", l1tf_cmdline); enum srso_mitigation { SRSO_MITIGATION_NONE, + SRSO_MITIGATION_UCODE_NEEDED, + SRSO_MITIGATION_SAFE_RET_UCODE_NEEDED, SRSO_MITIGATION_MICROCODE, SRSO_MITIGATION_SAFE_RET, SRSO_MITIGATION_IBPB, @@ -2368,11 +2370,13 @@ enum srso_mitigation_cmd { }; static const char * const srso_strings[] = { - [SRSO_MITIGATION_NONE] = "Vulnerable", - [SRSO_MITIGATION_MICROCODE] = "Mitigation: microcode", - [SRSO_MITIGATION_SAFE_RET] = "Mitigation: safe RET", - [SRSO_MITIGATION_IBPB] = "Mitigation: IBPB", - [SRSO_MITIGATION_IBPB_ON_VMEXIT] = "Mitigation: IBPB on VMEXIT only" + [SRSO_MITIGATION_NONE] = "Vulnerable", + [SRSO_MITIGATION_UCODE_NEEDED] = "Vulnerable: No microcode", + [SRSO_MITIGATION_SAFE_RET_UCODE_NEEDED] = "Vulnerable: Safe RET, no microcode", + [SRSO_MITIGATION_MICROCODE] = "Vulnerable: Microcode, no safe RET", + [SRSO_MITIGATION_SAFE_RET] = "Mitigation: Safe RET", + [SRSO_MITIGATION_IBPB] = "Mitigation: IBPB", + [SRSO_MITIGATION_IBPB_ON_VMEXIT] = "Mitigation: IBPB on VMEXIT only" }; static enum srso_mitigation srso_mitigation __ro_after_init = SRSO_MITIGATION_NONE; @@ -2406,13 +2410,10 @@ static void __init srso_select_mitigation(void) { bool has_microcode = boot_cpu_has(X86_FEATURE_IBPB_BRTYPE); - if (!boot_cpu_has_bug(X86_BUG_SRSO) || cpu_mitigations_off()) + if (!boot_cpu_has_bug(X86_BUG_SRSO) || cpu_mitigations_off() || srso_cmd == SRSO_CMD_OFF) goto out; - if (!has_microcode) { - pr_warn("IBPB-extending microcode not applied!\n"); - pr_warn(SRSO_NOTICE); - } else { + if (has_microcode) { /* * Zen1/2 with SMT off aren't vulnerable after the right * IBPB microcode has been applied. @@ -2427,6 +2428,12 @@ static void __init srso_select_mitigation(void) srso_mitigation = SRSO_MITIGATION_IBPB; goto out_print; } + } else { + pr_warn("IBPB-extending microcode not applied!\n"); + pr_warn(SRSO_NOTICE); + + /* may be overwritten by SRSO_CMD_SAFE_RET below */ + srso_mitigation = SRSO_MITIGATION_UCODE_NEEDED; } switch (srso_cmd) { @@ -2456,7 +2463,10 @@ static void __init srso_select_mitigation(void) setup_force_cpu_cap(X86_FEATURE_SRSO); x86_return_thunk = srso_return_thunk; } - srso_mitigation = SRSO_MITIGATION_SAFE_RET; + if (has_microcode) + srso_mitigation = SRSO_MITIGATION_SAFE_RET; + else + srso_mitigation = SRSO_MITIGATION_SAFE_RET_UCODE_NEEDED; } else { pr_err("WARNING: kernel not compiled with CPU_SRSO.\n"); } @@ -2696,9 +2706,7 @@ static ssize_t srso_show_state(char *buf) if (boot_cpu_has(X86_FEATURE_SRSO_NO)) return sysfs_emit(buf, "Mitigation: SMT disabled\n"); - return sysfs_emit(buf, "%s%s\n", - srso_strings[srso_mitigation], - boot_cpu_has(X86_FEATURE_IBPB_BRTYPE) ? "" : ", no microcode"); + return sysfs_emit(buf, "%s\n", srso_strings[srso_mitigation]); } static ssize_t gds_show_state(char *buf) -- 2.41.0