Page MenuHomeFreeBSD

D61643.1794945183.diff
No OneTemporary

Authored By
Unknown
Size
7 KB
Referenced Files
None
Subscribers
None

D61643.1794945183.diff

diff --git a/share/man/man7/mitigations.7 b/share/man/man7/mitigations.7
--- a/share/man/man7/mitigations.7
+++ b/share/man/man7/mitigations.7
@@ -28,7 +28,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd January 29, 2025
+.Dd November 11, 2026
.Dt MITIGATIONS 7
.Os
.Sh NAME
@@ -487,6 +487,51 @@
utility
.Pc .
.El
+.Ss Transient Scheduler Attacks
+The Transient Scheduler Attacks
+.Pq TSA ,
+CVE-2024-36350 and CVE-2024-36357, described in AMD security bulletin
+AMD-SB-7029, affect AMD Family 19h and 1Ah processors.
+Under specific timing conditions, data from the store queue or the L1 data
+cache can be inferred across privilege boundaries.
+Processors that are not affected report
+.Dv TSA_SQ_NO
+and
+.Dv TSA_L1_NO
+in CPUID leaf 0x80000021, and also
+.Dv TSA_FILL_NO
+on Family 1Ah.
+With updated microcode, the
+.Dv VERW
+instruction clears the affected buffers.
+Processors may report this with
+.Dv VERW_CLEAR
+in the same leaf, but Family 19h microcode does not, so on bare metal
+.Fx
+compares the microcode revision with the minimum fixed revisions listed
+in the bulletin.
+When the mitigation is enabled,
+.Fx
+executes
+.Dv VERW
+on return to user mode.
+This mitigation is disabled by default.
+To it are associated the following knobs:
+.Bl -tag -width indent
+.It Va machdep.mitigations.tsa.enable
+A read-write integer tunable and sysctl indicating whether the mitigation should
+be disabled (0), enabled (1) or enabled only if the processor is affected and
+.Dv VERW
+clears the affected buffers (2).
+.It Va machdep.mitigations.tsa.state
+A read-only string indicating the current mitigation state.
+It can be either
+.Dq not affected ,
+.Dq inactive ,
+.Dq inactive, no microcode
+or
+.Dq VERW .
+.El
.Pp
The performance impact and threat models related to these mitigations
should be considered when configuring and deploying them in a
diff --git a/sys/amd64/vmm/x86.c b/sys/amd64/vmm/x86.c
--- a/sys/amd64/vmm/x86.c
+++ b/sys/amd64/vmm/x86.c
@@ -311,6 +311,12 @@
AMDFE2_VERW_CLEAR | AMDFE2_NULL_SEL_CLR_BASE |
AMDFE2_AUTOIBRS | AMDFE2_PREFETCHI |
AMDFE2_SRSO_NO | AMDFE2_SRSO_USER_KERNEL_NO;
+ /*
+ * Family 19h microcode that makes VERW clear the
+ * buffers affected by TSA does not report VERW_CLEAR.
+ */
+ if (x86_tsa_verw_clears())
+ regs[0] |= AMDFE2_VERW_CLEAR;
regs[1] = 0;
regs[2] &= AMDFE2_ECX_TSA_SQ_NO |
AMDFE2_ECX_TSA_L1_NO | AMDFE2_ECX_TSA_FILL_NO;
diff --git a/sys/x86/include/x86_var.h b/sys/x86/include/x86_var.h
--- a/sys/x86/include/x86_var.h
+++ b/sys/x86/include/x86_var.h
@@ -152,6 +152,7 @@
void hw_ssb_recalculate(bool all_cpus);
void x86_taa_recalculate(void);
void x86_rngds_mitg_recalculate(bool all_cpus);
+bool x86_tsa_verw_clears(void);
void zenbleed_sanitize_enable(void);
void zenbleed_check_and_apply(bool all_cpus);
void nmi_call_kdb(u_int cpu, u_int type, struct trapframe *frame);
diff --git a/sys/x86/x86/cpu_machdep.c b/sys/x86/x86/cpu_machdep.c
--- a/sys/x86/x86/cpu_machdep.c
+++ b/sys/x86/x86/cpu_machdep.c
@@ -1378,6 +1378,139 @@
sysctl_hw_mds_disable_state_handler, "A",
"Microarchitectural Data Sampling Mitigation state");
+/*
+ * AMD Transient Scheduler Attacks, CVE-2024-36350 and CVE-2024-36357
+ * (AMD-SB-7029). Family 19h and 1Ah processors are affected unless CPUID
+ * 0x80000021 reports TSA_SQ_NO and TSA_L1_NO, plus TSA_FILL_NO on family
+ * 1Ah. With updated microcode VERW clears the affected buffers, and the
+ * MDS VERW handler is used. Family 19h microcode does not set VERW_CLEAR,
+ * so on bare metal the microcode revision is checked against the minimum
+ * fixed revisions from AMD-SB-7029.
+ */
+static int hw_tsa_enable;
+TUNABLE_INT("machdep.mitigations.tsa.enable", &hw_tsa_enable);
+
+static const struct {
+ uint8_t model;
+ uint8_t stepping;
+ uint32_t ucode;
+} hw_tsa_ucode[] = {
+ { 0x01, 0x1, 0x0a0011d7 },
+ { 0x01, 0x2, 0x0a00123b },
+ { 0x08, 0x2, 0x0a00820d },
+ { 0x11, 0x1, 0x0a10114c },
+ { 0x11, 0x2, 0x0a10124c },
+ { 0x18, 0x1, 0x0a108109 },
+ { 0x21, 0x0, 0x0a20102e },
+ { 0x21, 0x2, 0x0a201211 },
+ { 0x44, 0x1, 0x0a404108 },
+ { 0x50, 0x0, 0x0a500012 },
+ { 0x61, 0x2, 0x0a60120a },
+ { 0x74, 0x1, 0x0a704108 },
+ { 0x75, 0x2, 0x0a705208 },
+ { 0x78, 0x0, 0x0a708008 },
+ { 0x7c, 0x0, 0x0a70c008 },
+ { 0xa0, 0x2, 0x0aa00216 },
+};
+
+static bool
+hw_tsa_affected(void)
+{
+ u_int fam, no;
+
+ if (cpu_vendor_id != CPU_VENDOR_AMD)
+ return (false);
+ fam = CPUID_TO_FAMILY(cpu_id);
+ if (fam == 0x19)
+ no = AMDFE2_ECX_TSA_SQ_NO | AMDFE2_ECX_TSA_L1_NO;
+ else if (fam == 0x1a)
+ no = AMDFE2_ECX_TSA_SQ_NO | AMDFE2_ECX_TSA_L1_NO |
+ AMDFE2_ECX_TSA_FILL_NO;
+ else
+ return (false);
+ return ((amd_extended_feature2_ecx & no) != no);
+}
+
+bool
+x86_tsa_verw_clears(void)
+{
+ uint32_t rev;
+ u_int i;
+
+ if ((amd_extended_feature2 & AMDFE2_VERW_CLEAR) != 0)
+ return (true);
+ if (cpu_vendor_id != CPU_VENDOR_AMD ||
+ CPUID_TO_FAMILY(cpu_id) != 0x19 || vm_guest != VM_GUEST_NO)
+ return (false);
+ rev = (uint32_t)rdmsr(MSR_BIOS_SIGN);
+ for (i = 0; i < nitems(hw_tsa_ucode); i++) {
+ if (hw_tsa_ucode[i].model == CPUID_TO_MODEL(cpu_id) &&
+ hw_tsa_ucode[i].stepping == (cpu_id & CPUID_STEPPING))
+ return (rev >= hw_tsa_ucode[i].ucode);
+ }
+ return (false);
+}
+
+static bool
+hw_tsa_want_verw(void)
+{
+ switch (hw_tsa_enable) {
+ case 1:
+ return (true);
+ case 2:
+ return (hw_tsa_affected() && x86_tsa_verw_clears());
+ default:
+ return (false);
+ }
+}
+
+static int
+sysctl_tsa_enable_handler(SYSCTL_HANDLER_ARGS)
+{
+ int error, val;
+
+ val = hw_tsa_enable;
+ error = sysctl_handle_int(oidp, &val, 0, req);
+ if (error != 0 || req->newptr == NULL)
+ return (error);
+ if (val < 0 || val > 2)
+ return (EINVAL);
+ hw_tsa_enable = val;
+ hw_mds_recalculate();
+ return (0);
+}
+
+static int
+sysctl_tsa_state_handler(SYSCTL_HANDLER_ARGS)
+{
+ const char *state;
+
+ if (cpu_vendor_id == CPU_VENDOR_AMD && mds_handler == mds_handler_verw)
+ state = "VERW";
+ else if (!hw_tsa_affected())
+ state = "not affected";
+ else if (!x86_tsa_verw_clears())
+ state = "inactive, no microcode";
+ else
+ state = "inactive";
+ return (SYSCTL_OUT(req, state, strlen(state)));
+}
+
+SYSCTL_NODE(_machdep_mitigations, OID_AUTO, tsa,
+ CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
+ "AMD Transient Scheduler Attacks Mitigation");
+
+SYSCTL_PROC(_machdep_mitigations_tsa, OID_AUTO, enable, CTLTYPE_INT |
+ CTLFLAG_RWTUN | CTLFLAG_NOFETCH | CTLFLAG_MPSAFE, NULL, 0,
+ sysctl_tsa_enable_handler, "I",
+ "AMD Transient Scheduler Attacks Mitigation "
+ "(0 - off, 1 - on, 2 - auto)");
+
+SYSCTL_PROC(_machdep_mitigations_tsa, OID_AUTO, state,
+ CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0,
+ sysctl_tsa_state_handler, "A",
+ "AMD Transient Scheduler Attacks Mitigation state");
+
_Static_assert(__offsetof(struct pcpu, pc_mds_tmp) % 64 == 0, "MDS AVX512");
void
@@ -1395,7 +1528,10 @@
* For the similar reasons, and for testing, allow to enable
* mitigation even when MDS_NO cap is set.
*/
- if (cpu_vendor_id != CPU_VENDOR_INTEL || hw_mds_disable == 0 ||
+ if (cpu_vendor_id == CPU_VENDOR_AMD) {
+ mds_handler = hw_tsa_want_verw() ? mds_handler_verw :
+ mds_handler_void;
+ } else if (cpu_vendor_id != CPU_VENDOR_INTEL || hw_mds_disable == 0 ||
((cpu_ia32_arch_caps & IA32_ARCH_CAP_MDS_NO) != 0 &&
hw_mds_disable == 3)) {
mds_handler = mds_handler_void;

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 17, 7:53 PM (23 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41806482
Default Alt Text
D61643.1794945183.diff (7 KB)

Event Timeline