Skip to contentSkip to conversation

Documentation: Add section about CPU vulnerabilities for Spectre

PATCH Superseded Tim Chen 4 participants 9 messages Jun 17, 2019 – Jun 18, 2019

Subsystems (3)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Tim Chen

author
#0 lore raw

PATCH v3 1/1 Documentation: Add section about CPU vulnerabilities for Spectre

Add documentation for Spectre vulnerability and the mitigation mechanisms:

- Explain the problem and risks
- Document the mitigation mechanisms
- Document the command line controls
- Document the sysfs files

---
 Documentation/admin-guide/hw-vuln/index.rst   |   1 +
 Documentation/admin-guide/hw-vuln/spectre.rst | 651 ++++++++++++++++++
 Documentation/userspace-api/spec_ctrl.rst     |   2 +
 3 files changed, 654 insertions(+)
 create mode 100644 Documentation/admin-guide/hw-vuln/spectre.rst
Documentation/admin-guide/hw-vuln/index.rst +1 -0
index ffc064c1ec68..49311f3da6f2 100644
@@ -9,5 +9,6 @@ are configurable at compile, boot or run time.
 .. toctree::
    :maxdepth: 1
 
+   spectre
    l1tf
    mds
Documentation/admin-guide/hw-vuln/spectre.rst new file +651 -0

651 lines not on this page · raw message

Documentation/userspace-api/spec_ctrl.rst +2 -0
index 1129c7550a48..7ddd8f667459 100644
@@ -49,6 +49,8 @@ If PR_SPEC_PRCTL is set, then the per-task control of the mitigation is
 available. If not set, prctl(PR_SET_SPECULATION_CTRL) for the speculation
 misfeature will fail.
 
+.. _set_spec_ctrl:
+
 PR_SET_SPECULATION_CTRL
 -----------------------
 
Signature · 1 line
2.20.1
#1 lore raw

Hi Tim,

Nice writeup. A few suggestions inline.

Documentation/admin-guide/hw-vuln/spectre.rst line 100

Quoted 8 lines · Tim Chen
Documentation/admin-guide/hw-vuln/spectre.rst new file +8 -0
+In Spectre variant 2 attacks, the attacker can steer speculative indirect
+branches in the victim to gadget code by poisoning the branch target
+buffer of a CPU used for predicting indirect branch addresses. Such
+poisoning could be done by indirect branching into existing code, with the
+address offset of the indirect branch under the attacker's control. Since
+the branch prediction hardware does not fully disambiguate branch address
+and uses the offset for prediction, this could cause privileged code's
+indirect branch to jump to a gadget code with the same offset.

Maybe mention "on impacted hardware" (implied).

Documentation/admin-guide/hw-vuln/spectre.rst line 113

Quoted 6 lines
Documentation/admin-guide/hw-vuln/spectre.rst new file +6 -0
+One other variant 2 attack vector is for the attacker to poison the
+return stack buffer (RSB) [13] to cause speculative RET execution to go
+to an gadget.  An attacker's imbalanced CALL instructions might "poison"
+entries in the return stack buffer which are later consumed by a victim's
+RET instruction.  This attack can be mitigated by flushing the return
+stack buffer on context switch, or VM exit.

Maybe replace CALL and RET with generic equivalents or label as x86 examples.

Documentation/admin-guide/hw-vuln/spectre.rst line 142

Quoted 3 lines
Documentation/admin-guide/hw-vuln/spectre.rst new file +3 -0
+   For kernel code that has been identified where data pointers could
+   potentially be influenced for Spectre attacks, new "nospec" accessor
+   macros are used to prevent speculative loading of data.

Maybe explain that nospec (speculative clamping) relies on the absence of value prediction in the masking (in current hardware). It may NOT always be a safe approach in future hardware, where Spectre-v1 attacks are likely to persist but hardware may speculate about the mask value.

Documentation/admin-guide/hw-vuln/spectre.rst

Quoted 3 lines
Documentation/admin-guide/hw-vuln/spectre.rst new file +3 -0
+   On x86, a user process can protect itself against Spectre variant
+   2 attacks by using the prctl() syscall to disable indirect branch
+   speculation for itself.

This is not x86 specific. The same prctl is wired up elsewhere also.

Jon.

Signature · 1 line
Computer Architect | Sent with my Fedora powered laptop
#2 lore raw
Quoted 8 lines · Jon Masters

Documentation/admin-guide/hw-vuln/spectre.rst line 142

Quoted 3 lines
Documentation/admin-guide/hw-vuln/spectre.rst new file +3 -0
+   For kernel code that has been identified where data pointers could
+   potentially be influenced for Spectre attacks, new "nospec" accessor
+   macros are used to prevent speculative loading of data.

Maybe explain that nospec (speculative clamping) relies on the absence of value prediction in the masking (in current hardware). It may NOT always be a safe approach in future hardware, where Spectre-v1 attacks are likely to persist but hardware may speculate about the mask value.

Something like the Arm CSDB barrier would seem to be potentially useful for $FUTURE_X86 as a fence with lighter-weight semantics than an *fence.

Jon.

Signature · 1 line
Computer Architect | Sent with my Fedora powered laptop
author
#3 lore raw
Quoted 6 lines · Jon Masters
Quoted 4 lines · Jon Masters
Quoted 3 lines
Documentation/admin-guide/hw-vuln/spectre.rst new file +3 -0
+   For kernel code that has been identified where data pointers could
+   potentially be influenced for Spectre attacks, new "nospec" accessor
+   macros are used to prevent speculative loading of data.
Quoted 8 lines
Quoted 4 lines

Maybe explain that nospec (speculative clamping) relies on the absence of value prediction in the masking (in current hardware). It may NOT always be a safe approach in future hardware, where Spectre-v1 attacks are likely to persist but hardware may speculate about the mask value.

Something like the Arm CSDB barrier would seem to be potentially useful for $FUTURE_X86 as a fence with lighter-weight semantics than an *fence.

Is it necessary to go into such level of implementation details on nospec? These seem to be appropriate as code comments in nospec for kernel developer. But for an admin-guide doc, it may confuse sys admin to think that nospec could not be ineffective.

When new hardware appears that need new implementations of nospec, we should tweak nospec and not need the admin to worry about such implementation details.

Tim

#4 lore raw
Quoted 16 lines · Tim Chen
Quoted 6 lines · Jon Masters
Quoted 4 lines · Jon Masters
Quoted 3 lines
Documentation/admin-guide/hw-vuln/spectre.rst new file +3 -0
+   For kernel code that has been identified where data pointers could
+   potentially be influenced for Spectre attacks, new "nospec" accessor
+   macros are used to prevent speculative loading of data.
Quoted 8 lines
Quoted 4 lines

Maybe explain that nospec (speculative clamping) relies on the absence of value prediction in the masking (in current hardware). It may NOT always be a safe approach in future hardware, where Spectre-v1 attacks are likely to persist but hardware may speculate about the mask value.

Something like the Arm CSDB barrier would seem to be potentially useful for $FUTURE_X86 as a fence with lighter-weight semantics than an *fence.

Quoted 7 lines

Is it necessary to go into such level of implementation details on nospec? These seem to be appropriate as code comments in nospec for kernel developer. But for an admin-guide doc, it may confuse sys admin to think that nospec could not be ineffective.

When new hardware appears that need new implementations of nospec, we should tweak nospec and not need the admin to worry about such implementation details.

Correct. Those details are architecture level details. See the split of the MDS documentation...

Thanks,

tglx

#5 lore raw
In reply to Tim Chen

Tim,

Documentation/admin-guide/hw-vuln/spectre.rst line 62

Quoted 4 lines · Tim Chen
Documentation/admin-guide/hw-vuln/spectre.rst new file +4 -0
+Spectre variant 1 attacks take advantage of speculative execution of
+conditional branches, while Spectre variant 2 attacks use speculative
+execution of indirect branches to leak privileged memory. See [1] [5]
+[7] [10] [11].

It would be great to actually link these [N] to the actual http link at the bottom. No idea what's the best way to do that.

Jonathan?

Documentation/admin-guide/hw-vuln/spectre.rst line 469

Quoted 5 lines
Documentation/admin-guide/hw-vuln/spectre.rst new file +5 -0
+Mitigation control on the kernel command line
+---------------------------------------------
+
+Spectre variant 2 mitigation can be disabled or force enabled at the
+kernel command line.

The below renders horribly when converted to HTML

You probably want to wrap these into a table

Documentation/admin-guide/hw-vuln/spectre.rst line 480

Quoted 10 lines
Documentation/admin-guide/hw-vuln/spectre.rst new file +10 -0
+	nospectre_v2	[X86] Disable all mitigations for the Spectre variant 2
+			(indirect branch prediction) vulnerability. System may
+			allow data leaks with this option, which is equivalent
+			to spectre_v2=off.
+
+
+        spectre_v2=     [X86] Control mitigation of Spectre variant 2
+			(indirect branch speculation) vulnerability.
+			The default operation protects the kernel from
+			user space attacks.

Maybe Jonathan has a better idea.

Other than those formatting detail, this looks really good. Well done!

Thanks,

tglx

#6 lore raw

Tim,

Quoted 24 lines · Thomas Gleixner

Tim,

Documentation/admin-guide/hw-vuln/spectre.rst line 62

Quoted 4 lines · Tim Chen
Documentation/admin-guide/hw-vuln/spectre.rst new file +4 -0
+Spectre variant 1 attacks take advantage of speculative execution of
+conditional branches, while Spectre variant 2 attacks use speculative
+execution of indirect branches to leak privileged memory. See [1] [5]
+[7] [10] [11].

It would be great to actually link these [N] to the actual http link at the bottom. No idea what's the best way to do that.

Jonathan?

Documentation/admin-guide/hw-vuln/spectre.rst line 469

Quoted 5 lines
Documentation/admin-guide/hw-vuln/spectre.rst new file +5 -0
+Mitigation control on the kernel command line
+---------------------------------------------
+
+Spectre variant 2 mitigation can be disabled or force enabled at the
+kernel command line.

The below renders horribly when converted to HTML

You probably want to wrap these into a table

Quoted 12 lines

Documentation/admin-guide/hw-vuln/spectre.rst line 480

Quoted 10 lines
Documentation/admin-guide/hw-vuln/spectre.rst new file +10 -0
+	nospectre_v2	[X86] Disable all mitigations for the Spectre variant 2
+			(indirect branch prediction) vulnerability. System may
+			allow data leaks with this option, which is equivalent
+			to spectre_v2=off.
+
+
+        spectre_v2=     [X86] Control mitigation of Spectre variant 2
+			(indirect branch speculation) vulnerability.
+			The default operation protects the kernel from
+			user space attacks.

Maybe Jonathan has a better idea.

But ideally you follow the table style which is used for the L1TF and MDS command line options.

Thanks,

tglx

maintainer
#7 lore raw
In reply to Thomas Gleixner
Quoted 9 lines · On Mon, 17 Jun 2019 22:21:51 +0200 (CEST) Thomas Gleixner <[email protected]>…

Documentation/admin-guide/hw-vuln/spectre.rst line 62

Quoted 4 lines
Documentation/admin-guide/hw-vuln/spectre.rst new file +4 -0
+Spectre variant 1 attacks take advantage of speculative execution of
+conditional branches, while Spectre variant 2 attacks use speculative
+execution of indirect branches to leak privileged memory. See [1] [5]
+[7] [10] [11].  

It would be great to actually link these [N] to the actual http link at the bottom. No idea what's the best way to do that.

Jonathan?

Append an underscore to the link text, so:

	See [1_] [5_] ...

Then, when adding the links:

	.. _1: https://.../

There are other ways; see

http://docutils.sourceforge.net/docs/user/rst/quickref.html#external-hyperlink-targets

for the list.

Quoted 4 lines

The below renders horribly when converted to HTML

You probably want to wrap these into a table

Quoted 12 lines

Documentation/admin-guide/hw-vuln/spectre.rst line 480

Quoted 10 lines
Documentation/admin-guide/hw-vuln/spectre.rst new file +10 -0
+	nospectre_v2	[X86] Disable all mitigations for the Spectre variant 2
+			(indirect branch prediction) vulnerability. System may
+			allow data leaks with this option, which is equivalent
+			to spectre_v2=off.
+
+
+        spectre_v2=     [X86] Control mitigation of Spectre variant 2
+			(indirect branch speculation) vulnerability.
+			The default operation protects the kernel from
+			user space attacks.  

Maybe Jonathan has a better idea.

The easiest thing is probably a definition list:

nospectre_v2
[X86] Disable all mitigations for the Spectre variant 2 (indirect branch prediction) ...

spectrev2=
...

i.e. just move the descriptive text into an indented block below the term of interest.

jon

author
#8 lore raw
Quoted 19 lines · Jonathan Corbet
Quoted 9 lines · On Mon, 17 Jun 2019 22:21:51 +0200 (CEST) Thomas Gleixner <[email protected]>…

Documentation/admin-guide/hw-vuln/spectre.rst line 62

Quoted 4 lines
Documentation/admin-guide/hw-vuln/spectre.rst new file +4 -0
+Spectre variant 1 attacks take advantage of speculative execution of
+conditional branches, while Spectre variant 2 attacks use speculative
+execution of indirect branches to leak privileged memory. See [1] [5]
+[7] [10] [11].  

It would be great to actually link these [N] to the actual http link at the bottom. No idea what's the best way to do that.

Jonathan?

Append an underscore to the link text, so:

	See [1_] [5_] ...

Then, when adding the links:

Quoted 7 lines
	.. _1: https://.../

There are other ways; see

http://docutils.sourceforge.net/docs/user/rst/quickref.html#external-hyperlink-targets

for the list.

Jonathan,

I want to actually have a generated reference section. The method you suggested will generate the reference link as a footer on the same page that refers to the link. I haven't quite figured out how to generate a proper bibliography like reference section with hyperlink after googling for quite a while.

Quoted 24 lines
Quoted 5 lines

The below renders horribly when converted to HTML

You probably want to wrap these into a table

Quoted 12 lines

Documentation/admin-guide/hw-vuln/spectre.rst line 480

Quoted 10 lines
Documentation/admin-guide/hw-vuln/spectre.rst new file +10 -0
+	nospectre_v2	[X86] Disable all mitigations for the Spectre variant 2
+			(indirect branch prediction) vulnerability. System may
+			allow data leaks with this option, which is equivalent
+			to spectre_v2=off.
+
+
+        spectre_v2=     [X86] Control mitigation of Spectre variant 2
+			(indirect branch speculation) vulnerability.
+			The default operation protects the kernel from
+			user space attacks.  

Maybe Jonathan has a better idea.

The easiest thing is probably a definition list:

nospectre_v2
[X86] Disable all mitigations for the Spectre variant 2 (indirect branch prediction) ...

Quoted 6 lines

spectrev2=
...

i.e. just move the descriptive text into an indented block below the term of interest.

Thanks for this suggestion.

Tim