Skip to content

Commit dee435b

Browse files
author
James Morse
committed
arm64: proton-pack: Report Spectre-BHB vulnerabilities as part of Spectre-v2
Speculation attacks against some high-performance processors can make use of branch history to influence future speculation as part of a spectre-v2 attack. This is not mitigated by CSV2, meaning CPUs that previously reported 'Not affected' are now moderately mitigated by CSV2. Update the value in /sys/devices/system/cpu/vulnerabilities/spectre_v2 to also show the state of the BHB mitigation. Reviewed-by: Catalin Marinas <[email protected]> Signed-off-by: James Morse <[email protected]>
1 parent bd09128 commit dee435b

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

arch/arm64/include/asm/spectre.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,7 @@ void spectre_v4_enable_task_mitigation(struct task_struct *tsk);
9393

9494
enum mitigation_state arm64_get_meltdown_state(void);
9595

96+
enum mitigation_state arm64_get_spectre_bhb_state(void);
97+
9698
#endif /* __ASSEMBLY__ */
9799
#endif /* __ASM_SPECTRE_H */

arch/arm64/kernel/proton-pack.c

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,39 @@ static bool spectre_v2_mitigations_off(void)
9696
return ret;
9797
}
9898

99+
static const char *get_bhb_affected_string(enum mitigation_state bhb_state)
100+
{
101+
switch (bhb_state) {
102+
case SPECTRE_UNAFFECTED:
103+
return "";
104+
default:
105+
case SPECTRE_VULNERABLE:
106+
return ", but not BHB";
107+
case SPECTRE_MITIGATED:
108+
return ", BHB";
109+
}
110+
}
111+
99112
ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr,
100113
char *buf)
101114
{
115+
enum mitigation_state bhb_state = arm64_get_spectre_bhb_state();
116+
const char *bhb_str = get_bhb_affected_string(bhb_state);
117+
const char *v2_str = "Branch predictor hardening";
118+
102119
switch (spectre_v2_state) {
103120
case SPECTRE_UNAFFECTED:
104-
return sprintf(buf, "Not affected\n");
121+
if (bhb_state == SPECTRE_UNAFFECTED)
122+
return sprintf(buf, "Not affected\n");
123+
124+
/*
125+
* Platforms affected by Spectre-BHB can't report
126+
* "Not affected" for Spectre-v2.
127+
*/
128+
v2_str = "CSV2";
129+
fallthrough;
105130
case SPECTRE_MITIGATED:
106-
return sprintf(buf, "Mitigation: Branch predictor hardening\n");
131+
return sprintf(buf, "Mitigation: %s%s\n", v2_str, bhb_str);
107132
case SPECTRE_VULNERABLE:
108133
fallthrough;
109134
default:
@@ -771,6 +796,13 @@ int arch_prctl_spec_ctrl_get(struct task_struct *task, unsigned long which)
771796
}
772797
}
773798

799+
static enum mitigation_state spectre_bhb_state;
800+
801+
enum mitigation_state arm64_get_spectre_bhb_state(void)
802+
{
803+
return spectre_bhb_state;
804+
}
805+
774806
/* Patched to NOP when enabled */
775807
void noinstr spectre_bhb_patch_loop_mitigation_enable(struct alt_instr *alt,
776808
__le32 *origptr,

0 commit comments

Comments
 (0)