Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ names it, after its microcode loads and before the clocksource's
`RDTSCP; LFENCE` relies on it, and stops the machine if the bit does not
hold. Both benches' words, as each one's boot logged them, are pinned in the
harness, and `checks::the_benches_words_decide_as_their_vendors_rows` holds
what they decide to each vendor's row for that CPU. No other mitigation the decision
names is applied: each is its own record's.
what they decide to each vendor's row for that CPU. Applying every other
mitigation the decision names is its own record's.

**Left**:
- Under the policy, an AMD CPU affected by Branch Type Confusion leaves the
Expand Down
22 changes: 22 additions & 0 deletions issues/automatic-ibrs-stays-off-on-an-amd-cpu-that-has-it.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
status: open
kind: defect
severity: [security]
opened: 2026-11-12
---

# Automatic IBRS stays off on an AMD CPU that has it

On an AMD CPU that enumerates automatic IBRS (APM Vol. 3
`CPUID Fn8000_0021_EAX[AutomaticIBRS]`, bit 8), `kernel::mitigation::decide`
names it for spectre_v2 and nothing sets `EFER.AIBRSE`:
`arch::x86_64::control_regs` declares `IA32_EFER` whole and constant. Such a
CPU runs the kernel's indirect branches unrestricted, and its spectre_v2
line says so. No proving machine enumerates it.

**Exit**: `control_regs`' declaration sets `AIBRSE` on each CPU whose
decision names automatic IBRS and asserts it there as it does the rest of
`IA32_EFER`; the words line gives `IA32_EFER`, and a boot on a machine that
enumerates it shows the bit on every CPU and its spectre_v2 line with
automatic IBRS in force. **Mutation**: the bit dropped from the declaration.
**Oracle**: the CPU's own register.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
status: open
kind: defect
severity: [security]
opened: 2026-11-12
---

# No entry sets IBRS on a CPU with RSBA and no enhanced IBRS

On an Intel CPU with RSBA behavior and no enhanced IBRS,
`kernel::mitigation::decide` names "IBRS on entry" for spectre_v2 and
retbleed: Intel's "Return Stack Buffer Underflow" has IBRS, not retpoline,
hold a return that underflows the RSB there. Nothing sets it, so every entry
from Ring 3 runs with `IA32_SPEC_CTRL.IBRS` as the CPU's bring-up left it,
clear. The guest runner's CPU is one such: it enumerates IBRS
(CPUID.(07H,0):EDX[26]) and no `IBRS_ALL`, and its signature is in
"Retpoline"'s Table 5. No proving machine is.

**Exit**: each entry from Ring 3 sets `IBRS` in `IA32_SPEC_CTRL` before its
first indirect branch, and each return to Ring 3 writes back the value the
thread runs with; a CPU whose decision does not name it runs no added
instruction, chosen per CPU as the branch-history clear is; and idle holds
what Intel's "Speculative Execution Side Channel Mitigations" asks of `IBRS`
before a sleep state on such a CPU. On the guest runner a probe reads `IBRS`
set inside a syscall and the thread's own value after its return.
**Mutation**: the return's write deleted. **Oracle**: the CPU's own register.
42 changes: 34 additions & 8 deletions issues/spec-ctrl-and-gds-stay-as-firmware-left-them.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,41 @@ opened: 2026-09-29

# SPEC_CTRL and GDS stay as firmware left them

Nothing in `kernel/src` reads or writes `IA32_SPEC_CTRL` (0x48) or
`IA32_MCU_OPT_CTRL` (0x123), so every CPU runs under the speculation controls
firmware left, and an Intel part affected by Gather Data Sampling runs
unmitigated if firmware left `GDS_MITG_DIS` set. Linux at
`Ubuntu-6.8.0-142.142` writes both as its decision selects
(`arch/x86/kernel/cpu/bugs.c:89,777`).

**Exit**: on every proving machine each CPU's 0x48 holds what
**Built**: each CPU's bring-up writes `IA32_SPEC_CTRL` (0x48) whole with
what
`issues/a-pure-function-decides-a-cpus-speculation-mitigations-from-its-vendors-guidance.md`
names for it while no program that asked runs: `IBRS` for enhanced IBRS or
AMD's always-on IBRS, `BHI_DIS_S` where it is named, every other bit clear.
It clears each `IA32_MCU_OPT_CTRL` (0x123) opt-out, `RNGDS_MITG_DIS` and
`GDS_MITG_DIS`, whose microcode mitigation the decision names
(`kernel::mitigation::Decision::spec_ctrl`, `mcu_opt_ctrl_clears`). Each
boot's words line gives both registers as each CPU found them and as it left
them, and its lines take what is in force from what it read back.
`checks::the_benches_words_decide_as_their_vendors_rows` holds the T14's
lines with `IBRS` set, and the `mitigations` row refuses a boot whose
registers leave off anything the kernel sets
(`Decision::unapplied`). The `gds-found-disabled` arm sets `GDS_MITG_DIS`
before the kernel's write, as firmware that opted out would leave it, and the
`gds_found_disabled` row holds that every CPU read it set and left it clear.

**Left**:
- **Owed on metal:** the `mitigations` row, the `metalcase` boot of main.
- Benches: the T14 and the AMD bench.
- Main must show the row green: on the T14 every CPU's words line with
`spec_ctrl=0x1` and `mcu_opt_ctrl` with bits 0 and 4 clear, and on the
AMD bench `spec_ctrl=0x0`.
- **Owed on metal:** `gds_found_disabled`, the `shared-debug` boot of main.
- Bench: the T14.
- Main must show the row green: every CPU's words line with
`mcu_opt_ctrl_found` holding bit 4 and `mcu_opt_ctrl` without it. The
same boot of main with the clear deleted from `arch::mitigation::apply`
must red it, the mutation below. A red saying the arm's write did not
take means firmware set `GDS_MITG_LOCK` (bit 5), and the row has no
premise there rather than a defect.
- **Owed on metal:** Linux's reads of 0x48 and 0x123 on each bench, beside
ToyOS's, compared in evidence.

**Exit**: on every proving machine each CPU's 0x48 holds what the decision
selects for it; on the T14, the one proving machine with GDS, a probe sets
`GDS_MITG_DIS` and reads it clear after the kernel's write. **Mutation**: the
clear deleted. **Oracle**: the vendor's guidance through that function, and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ work needs.

- `issues/a-pure-function-decides-a-cpus-speculation-mitigations-from-its-vendors-guidance.md`
- `issues/spec-ctrl-and-gds-stay-as-firmware-left-them.md`
- `issues/automatic-ibrs-stays-off-on-an-amd-cpu-that-has-it.md`
- `issues/no-entry-sets-ibrs-on-a-cpu-with-rsba-and-no-enhanced-ibrs.md`
- `issues/no-program-runs-with-speculative-store-bypass-disabled.md`
- `issues/no-gate-decodes-kernel-elfs-instructions.md`
- `issues/no-entry-or-switch-clears-the-bhb-fills-the-rsb-or-issues-an-ibpb.md`
Expand Down
152 changes: 143 additions & 9 deletions kernel/pure/mitigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ const IBRS_IBPB: u32 = 1 << 26;
const STIBP: u32 = 1 << 27;
const L1D_FLUSH: u32 = 1 << 28;
const SSBD: u32 = 1 << 31;
const PSFD: u32 = 1 << 0;
const IPRED_CTRL: u32 = 1 << 1;
const RRSBA_CTRL: u32 = 1 << 2;
const DDPD_U: u32 = 1 << 3;
const BHI_CTRL: u32 = 1 << 4;

/// `IA32_ARCH_CAPABILITIES`, the same article's Table 2.
Expand Down Expand Up @@ -102,6 +105,7 @@ mod amd {
pub const SSBD: u32 = 1 << 24;
pub const SSBD_VIRT_SPEC_CTRL: u32 = 1 << 25;
pub const SSBD_NOT_REQUIRED: u32 = 1 << 26;
pub const PSFD: u32 = 1 << 28;
pub const BTC_NO: u32 = 1 << 29;
pub const LFENCE_ALWAYS_SERIALIZING: u32 = 1 << 2;
pub const VERW_CLEAR: u32 = 1 << 5;
Expand Down Expand Up @@ -292,6 +296,13 @@ impl Mitigations {
}
}

/// Each one's name, as a line gives it.
impl fmt::Display for Mitigations {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Named { set: *self, by_policy: Self::NONE }.fmt(f)
}
}

/// The vulnerabilities decided, each named as its line names it.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(u8)]
Expand Down Expand Up @@ -412,11 +423,66 @@ impl Decision {
Line { verdict: self.verdict(of), applied }
}

/// `IA32_SPEC_CTRL` (48H) on this CPU while no program that asked runs:
/// `IBRS` set once where enhanced IBRS or AMD's IBRS-always-on is named,
/// and `BHI_DIS_S` where it is. Every other bit is clear.
pub fn spec_ctrl(&self) -> u64 {
let mut value = 0;
if self.enumerates(Mitigation::EnhancedIbrs) || self.enumerates(Mitigation::IbrsAlwaysOn) {
value |= msr::IBRS;
}
if self.enumerates(Mitigation::BhiDisS) {
value |= msr::BHI_DIS_S;
}
value
}

/// The `IA32_MCU_OPT_CTRL` (123H) opt-outs the kernel clears: each where
/// the microcode mitigation it disables is named.
pub fn mcu_opt_ctrl_clears(&self) -> u64 {
let mut clears = 0;
if self.enumerates(Mitigation::SrbdsMicrocode) {
clears |= msr::RNGDS_MITG_DIS;
}
if self.enumerates(Mitigation::GdsMicrocode) {
clears |= msr::GDS_MITG_DIS;
}
clears
}

/// What the kernel sets at a CPU's bring-up, this decision names and the
/// CPU enumerates, and `registers` do not show in force.
pub fn unapplied(&self, registers: &Registers) -> Mitigations {
let set = Mitigations::of(&[
Mitigation::LfenceDispatchSerializing,
Mitigation::EnhancedIbrs,
Mitigation::IbrsAlwaysOn,
Mitigation::BhiDisS,
Mitigation::SrbdsMicrocode,
Mitigation::GdsMicrocode,
]);
let named = Mitigation::ALL.into_iter().filter(|&one| set.has(one) && self.enumerates(one));
let in_force = self.in_force(registers);
named.filter(|&one| !in_force.has(one)).fold(Mitigations::NONE, Mitigations::with)
}

/// What is in force on a CPU whose registers read `registers`: [`ALWAYS`]
/// and each control a register shows on. Intel's two bits opt out of a
/// mitigation its microcode turns on; AMD's two turn one on.
/// and each control a register shows on. Intel's two `IA32_MCU_OPT_CTRL`
/// bits opt out of a mitigation its microcode turns on; the others turn
/// one on.
pub fn in_force(&self, registers: &Registers) -> Mitigations {
let mut on = ALWAYS;
if let Some(spec_ctrl) = registers.spec_ctrl {
for (one, bit) in [
(Mitigation::EnhancedIbrs, msr::IBRS),
(Mitigation::IbrsAlwaysOn, msr::IBRS),
(Mitigation::BhiDisS, msr::BHI_DIS_S),
] {
if self.enumerates(one) && spec_ctrl & bit != 0 {
on = on.with(one);
}
}
}
if let Some(opt) = registers.mcu_opt_ctrl {
if self.enumerates(Mitigation::SrbdsMicrocode) && opt & msr::RNGDS_MITG_DIS == 0 {
on = on.with(Mitigation::SrbdsMicrocode);
Expand Down Expand Up @@ -444,6 +510,8 @@ pub const ALWAYS: Mitigations = Mitigations::of(&[Mitigation::UserPointerClamp,
/// and `None` elsewhere.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Registers {
/// `IA32_SPEC_CTRL` (48H), wherever the CPU has it ([`Facts::has_spec_ctrl`]).
pub spec_ctrl: Option<u64>,
/// `IA32_MCU_OPT_CTRL` (123H).
pub mcu_opt_ctrl: Option<u64>,
/// AMD's `DE_CFG2` (C001_10E3H).
Expand All @@ -455,11 +523,14 @@ pub struct Registers {
/// MSR C001_1029[1]: LFENCE is dispatch serializing (AMD 70586 G-2).
pub const C001_1029_LFENCE_SERIALIZES_DISPATCH: u64 = 1 << 1;

/// The bits [`Decision::in_force`] reads: `IA32_MCU_OPT_CTRL`'s two
/// opt-outs ("CPUID Enumeration and Architectural MSRs", Table 6) and
/// `DE_CFG2[SuppressBPOnNonBr]` ("Technical Guidance for Mitigating Branch
/// Type Confusion" §6.2.1).
/// The register bits the decision sets and reads: `IA32_SPEC_CTRL`'s
/// ("CPUID Enumeration and Architectural MSRs", Table 3, which AMD's
/// `SPEC_CTRL` shares: APM Vol. 3 Fn8000_0008_EBX), `IA32_MCU_OPT_CTRL`'s two
/// opt-outs (the same, Table 6) and `DE_CFG2[SuppressBPOnNonBr]` ("Technical
/// Guidance for Mitigating Branch Type Confusion" §6.2.1).
mod msr {
pub const IBRS: u64 = 1 << 0;
pub const BHI_DIS_S: u64 = 1 << 10;
pub const RNGDS_MITG_DIS: u64 = 1 << 0;
pub const GDS_MITG_DIS: u64 = 1 << 4;
pub const SUPPRESS_BP_ON_NON_BR: u64 = 1 << 1;
Expand Down Expand Up @@ -609,6 +680,22 @@ pub fn decide(facts: &Facts) -> Decision {
}

impl Facts {
/// Whether the CPU has `IA32_SPEC_CTRL` (48H), which an absent MSR's
/// `#GP` makes a question to ask first: on Intel wherever it enumerates
/// any of its bits ("CPUID Enumeration and Architectural MSRs", Table 3),
/// on AMD wherever it enumerates IBRS, STIBP, SSBD or PSFD (APM Vol. 3
/// Fn8000_0008_EBX).
pub fn has_spec_ctrl(&self) -> bool {
match self.vendor {
Vendor::Intel => {
self.cpuid_7_0_edx & (IBRS_IBPB | STIBP | SSBD) != 0
|| self.cpuid_7_2_edx & (PSFD | IPRED_CTRL | RRSBA_CTRL | DDPD_U | BHI_CTRL) != 0
}
Vendor::Amd => self.cpuid_8000_0008_ebx & (amd::IBRS | amd::STIBP | amd::SSBD | amd::PSFD) != 0,
Vendor::Other(_) => false,
}
}

fn cap(&self, bit: u64) -> bool {
self.arch_capabilities & bit != 0
}
Expand Down Expand Up @@ -663,8 +750,10 @@ fn intel(f: &Facts, of: Vulnerability) -> Verdict {
// no need to use STIBP when IBRS is set" (§2.4.1.3).
Vulnerability::SpectreV2 => {
let enhanced = f.cap(cap::IBRS_ALL);
// The bit it sets is `IBRS`'s, which CPUID.(07H,0):EDX[26]
// enumerates ("CPUID Enumeration and Architectural MSRs", Table 3).
let branches = if enhanced {
Asks::of(Mitigation::EnhancedIbrs, true)
Asks::of(Mitigation::EnhancedIbrs, ibrs)
} else if f.intel_rsba() {
Asks::of(Mitigation::IbrsOnEntry, ibrs)
} else {
Expand Down Expand Up @@ -701,7 +790,7 @@ fn intel(f: &Facts, of: Vulnerability) -> Verdict {
Verdict::NotAffected
} else if f.cap(cap::IBRS_ALL) {
if f.cap(cap::RRSBA) || f.intel_lists(RRSBA) == Some(true) {
Asks::of(Mitigation::EnhancedIbrs, true).affected()
Asks::of(Mitigation::EnhancedIbrs, ibrs).affected()
} else {
Verdict::NotAffected
}
Expand Down Expand Up @@ -1547,9 +1636,12 @@ mod tests {
/// register the CPU was not read for shows nothing.
#[test]
fn what_is_in_force_is_what_the_registers_show() {
let unread = Registers { mcu_opt_ctrl: None, de_cfg2: None, c001_1029: None };
let unread = Registers { spec_ctrl: None, mcu_opt_ctrl: None, de_cfg2: None, c001_1029: None };
let intel = decide(&INTEL_806C1);
assert_eq!(intel.in_force(&unread), ALWAYS);
assert_eq!(intel.in_force(&Registers { spec_ctrl: Some(msr::IBRS), ..unread }), ALWAYS.with(EnhancedIbrs));
// A bit the decision does not name shows nothing.
assert_eq!(intel.in_force(&Registers { spec_ctrl: Some(msr::BHI_DIS_S), ..unread }), ALWAYS);
let both = ALWAYS.with(SrbdsMicrocode).with(GdsMicrocode);
assert_eq!(intel.in_force(&Registers { mcu_opt_ctrl: Some(0), ..unread }), both);
assert_eq!(intel.in_force(&Registers { mcu_opt_ctrl: Some(msr::GDS_MITG_DIS), ..unread }), ALWAYS.with(SrbdsMicrocode));
Expand All @@ -1561,6 +1653,48 @@ mod tests {
assert_eq!(amd.in_force(&Registers { de_cfg2: Some(0), c001_1029: Some(0), ..unread }), ALWAYS);
}

/// The registers each verdict sets at bring-up: `IBRS` for enhanced IBRS
/// and AMD's always-on IBRS, `BHI_DIS_S` where it is named, and the
/// microcode opt-outs cleared where their mitigation is; and what a
/// register that does not hold them leaves unapplied.
#[test]
fn each_verdict_sets_the_registers_its_mitigations_name() {
let t14 = decide(&INTEL_806C1);
assert_eq!(t14.spec_ctrl(), msr::IBRS);
assert_eq!(t14.mcu_opt_ctrl_clears(), msr::RNGDS_MITG_DIS | msr::GDS_MITG_DIS);
let set = Registers { spec_ctrl: Some(msr::IBRS), mcu_opt_ctrl: Some(0), de_cfg2: None, c001_1029: None };
assert_eq!(t14.unapplied(&set), Mitigations::NONE);
let firmware = Registers { spec_ctrl: Some(0), mcu_opt_ctrl: Some(msr::GDS_MITG_DIS), ..set };
assert_eq!(t14.unapplied(&firmware), Mitigations::of(&[EnhancedIbrs, GdsMicrocode]));
// Enhanced IBRS sets a bit only CPUID.(07H,0):EDX[26] enumerates.
let no_ibrs = decide(&Facts { cpuid_7_0_edx: INTEL_806C1.cpuid_7_0_edx & !IBRS_IBPB, ..INTEL_806C1 });
assert_eq!(no_ibrs.spec_ctrl(), 0);
assert_eq!(no_ibrs.verdict(SpectreV2), lacking(&[EnhancedIbrs, Smep, Ibpb], &[EnhancedIbrs, Ibpb]));

let bhi_ctrl = decide(&Facts { cpuid_7_2_edx: BHI_CTRL, ..INTEL_806C1 });
assert_eq!(bhi_ctrl.spec_ctrl(), msr::IBRS | msr::BHI_DIS_S);

let zen2 = decide(&AMD_17H_60H);
assert_eq!((zen2.spec_ctrl(), zen2.mcu_opt_ctrl_clears()), (0, 0));
let preferred = amd::IBRS | amd::IBRS_ALWAYS_ON | amd::IBRS_PREFERRED;
let always_on = decide(&Facts { cpuid_8000_0008_ebx: AMD_17H_60H.cpuid_8000_0008_ebx | preferred, ..AMD_17H_60H });
assert_eq!(always_on.spec_ctrl(), msr::IBRS);
let lfence = Registers { spec_ctrl: Some(0), mcu_opt_ctrl: None, de_cfg2: None, c001_1029: Some(0) };
assert_eq!(always_on.unapplied(&lfence), Mitigations::of(&[LfenceDispatchSerializing, IbrsAlwaysOn]));
}

/// Which CPUs have `IA32_SPEC_CTRL` at all.
#[test]
fn spec_ctrl_exists_where_a_bit_of_it_is_enumerated() {
assert!(INTEL_806C1.has_spec_ctrl());
assert!(AMD_17H_60H.has_spec_ctrl());
assert!(!NOTHING.has_spec_ctrl());
assert!(Facts { cpuid_7_2_edx: PSFD, ..NOTHING }.has_spec_ctrl());
assert!(!Facts { cpuid_7_0_edx: MD_CLEAR | L1D_FLUSH, ..NOTHING }.has_spec_ctrl());
assert!(!Facts { vendor: Vendor::Amd, cpuid_8000_0008_ebx: amd::IBPB, ..NOTHING }.has_spec_ctrl());
assert!(!Facts { vendor: Vendor::Other(*b"HygonGenuine"), ..AMD_17H_60H }.has_spec_ctrl());
}

/// The set's bits are the enum's discriminants, so a mitigation left
/// out of `ALL` would be needed and never named.
#[test]
Expand Down
5 changes: 5 additions & 0 deletions kernel/src/actuator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ actuators! {
/// `a_user_copy_highest_first_faults_or_ends_as_bad_address`.
copies_go_down = "copies-go-down";

/// Set `IA32_MCU_OPT_CTRL.GDS_MITG_DIS` on each CPU whose decision names
/// the microcode's gather mitigation, as firmware that opted out would
/// leave it, before the kernel's own write. Judged by `gds_found_disabled`.
gds_found_disabled = "gds-found-disabled";

/// Have the first syscall null SS, force a switch, and report whether it reloaded — the
/// AMD `SYSRET` SS-attributes workaround's only guest-observable proof.
sysret_ss_probe = "sysret-ss-probe";
Expand Down
Loading
Loading