Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 60d1e2d4 authored by James Morse's avatar James Morse Committed by Gerrit - the friendly Code Review server
Browse files

arm64: proton-pack: Report Spectre-BHB vulnerabilities as part of Spectre-v2



commit dee435be76f4117410bbd90573a881fd33488f37 upstream.

Speculation effect against some high-performance processors can
make use of branch history to influence future speculation as part of
a spectre-v2. 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 show the state of the BHB mitigation.

Reviewed-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
[ code move to cpu_errata.c for backport ]
Signed-off-by: default avatarJames Morse <james.morse@arm.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 7b012f65
Git-repo: https://android.googlesource.com/kernel/common/


Change-Id: I7dc0fc8e5d198c1d9d7b3d8227a93b43d746c97a
Signed-off-by: default avatarKishor Krishna Bhat <quic_kishkris@quicinc.com>
parent c52fc1f4
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -532,6 +532,15 @@ static inline int arm64_get_ssbd_state(void)

void arm64_set_ssbd_mitigation(bool state);

/* Watch out, ordering is important here. */
enum mitigation_state {
	SPECTRE_UNAFFECTED,
	SPECTRE_MITIGATED,
	SPECTRE_VULNERABLE,
};

enum mitigation_state arm64_get_spectre_bhb_state(void);

#endif /* __ASSEMBLY__ */

#endif
+36 −3
Original line number Diff line number Diff line
@@ -937,18 +937,51 @@ ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr,
	return sprintf(buf, "Mitigation: __user pointer sanitization\n");
}

static const char *get_bhb_affected_string(enum mitigation_state bhb_state)

{
	switch (bhb_state) {
	case SPECTRE_UNAFFECTED:
		return "";
	default:
	case SPECTRE_VULNERABLE:
		return ", but not BHB";
	case SPECTRE_MITIGATED:
		return ", BHB";
	}
}

ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr,
		char *buf)
{
	if (__spectrev2_safe)
	enum mitigation_state bhb_state = arm64_get_spectre_bhb_state();
	const char *bhb_str = get_bhb_affected_string(bhb_state);
	const char *v2_str = "Branch predictor hardening";

	if (__spectrev2_safe) {
		if (bhb_state == SPECTRE_UNAFFECTED)
			return sprintf(buf, "Not affected\n");

		/*
		 * Platforms affected by Spectre-BHB can't report
		 * "Not affected" for Spectre-v2.
		 */
		v2_str = "CSV2";
	}

	if (__hardenbp_enab)
		return sprintf(buf, "Mitigation: Branch predictor hardening\n");
		return sprintf(buf, "Mitigation: %s%s\n", v2_str, bhb_str);

	return sprintf(buf, "Vulnerable\n");
}

static enum mitigation_state spectre_bhb_state;

enum mitigation_state arm64_get_spectre_bhb_state(void)
{
	return spectre_bhb_state;
}

ssize_t cpu_show_spec_store_bypass(struct device *dev,
		struct device_attribute *attr, char *buf)
{