x86/doc: add PTI description
PATCH v2 1/1 x86/doc: add PTI description
Changes from v1:
* update kernel-parameters.txt to clarify that the pti= option is not just for disabling. Also describe what 'pti=auto' does and why
* Add a note about the presence of NX in the user portion of the kernel page tables
* Clarify _additional_ 4k of PGD space
* Add a note about the runtime overhead of PCID without INVPCID
---
From: Dave Hansen <[email protected]>
Add some details about how PTI works, what some of the downsides are, and how to debug it when things go wrong.
Also document the kernel parameter: 'nopti'.
---
b/Documentation/admin-guide/kernel-parameters.txt | 22 +- b/Documentation/x86/pti.txt | 185 ++++++++++++++++++++++ 2 files changed, 200 insertions(+), 7 deletions(-)
Documentation/admin-guide/kernel-parameters.txt renamed from Documentation/admin-guide/kernel-parameters.txt~kpti-doc +15 -7
@@ -2712,8 +2712,6 @@ steal time is computed, but won't influence scheduler behaviour - nopti [X86-64] Disable kernel page table isolation - nolapic [X86-32,APIC] Do not enable or use the local APIC. nolapic_timer [X86-32,APIC] Do not use the local APIC timer.
@@ -3288,11 +3286,21 @@ pt. [PARIDE] See Documentation/blockdev/paride.txt. - pti= [X86_64] - Control user/kernel address space isolation: - on - enable - off - disable - auto - default setting + pti= [X86_64] Control Page Table Isolation of user and + kernel address spaces. Disabling this feature + removes hardening, but improves performance of + system calls and interrupts. + + on - unconditionally enable + off - unconditionally disable + auto - kernel detects whether your CPU model is + vulnerable to issues that PTI mitigates + + Not specifying this option nothing is equivalent to + pti=auto. + + nopti [X86_64] + Equivalent to pti=off pty.legacy_count= [KNL] Number of legacy pty's. Overwrites compiled-in
Documentation/x86/pti.txt new file +185 -0
185 lines not on this page · raw message
_
Documentation/admin-guide/kernel-parameters.txt line 3300
Quoted 2 lines · Dave Hansen
Documentation/admin-guide/kernel-parameters.txt renamed from Documentation/admin-guide/kernel-parameters.txt~kpti-doc +2
-0+ Not specifying this option nothing is equivalent to + pti=auto.
-nothing
Documentation/x86/pti.txt line 6
Quoted 3 lines
Documentation/x86/pti.txt new file +3
-0+Page Table Isolation (pti, previously known as KAISER[1]) is a +countermeasure against attacks on kernel address information such +as the "Meltdown" approach[2].
It's not really just address information, but any data. Maybe "attacks that leak kernel memory"?
Quoted 1 line
+To avoid leaking address information, we create an new, independent
Same issue here. Also an -> a.
Quoted 1 line
+copy of the page tables which are used only when running userspace
are -> is. The copy is singular.
Documentation/x86/pti.txt line 11
Quoted 2 lines
Documentation/x86/pti.txt new file +2
-0+applications. When the kernel is entered via syscalls, interrupts or +exceptions, page tables are switched to the full "kernel" copy. When
"the page tables".
Documentation/x86/pti.txt line 38
Quoted 3 lines
Documentation/x86/pti.txt new file +3
-0+crippled by setting the NX bit in the top level. This ensures +that if a kernel->user CR3 switch is missed that userspace will +crash immediately upon executing its first instruction.
"that userspace" -> "then userspace"
Signature · 2 lines
Hector Martin "marcan" ([email protected]) Public Key: https://mrcn.st/pub
Quoted 5 lines · Hector Martin 'marcan
Documentation/admin-guide/kernel-parameters.txt line 3300
Quoted 2 lines · Dave Hansen
Documentation/admin-guide/kernel-parameters.txt renamed from Documentation/admin-guide/kernel-parameters.txt~kpti-doc +2
-0+ Not specifying this option nothing is equivalent to + pti=auto.-nothing
Sure, will fix.
Quoted 6 lines
Documentation/x86/pti.txt line 6
Quoted 3 lines
Documentation/x86/pti.txt new file +3
-0+Page Table Isolation (pti, previously known as KAISER[1]) is a +countermeasure against attacks on kernel address information such +as the "Meltdown" approach[2].It's not really just address information, but any data. Maybe "attacks that leak kernel memory"?
It's not just kernel leaks either, though.
Quoted 3 lines
Quoted 1 line
+To avoid leaking address information, we create an new, independent
Same issue here. Also an -> a.
Will fix.
Quoted 3 lines
Quoted 1 line
+copy of the page tables which are used only when running userspace
are -> is. The copy is singular.
I've reworded the sentence to remove the ambiguity.
Quoted 4 lines
Documentation/x86/pti.txt line 11
Quoted 2 lines
Documentation/x86/pti.txt new file +2
-0+applications. When the kernel is entered via syscalls, interrupts or +exceptions, page tables are switched to the full "kernel" copy. When"the page tables".
No thanks. It's fine the way it is.
Quoted 5 lines
Documentation/x86/pti.txt line 38
Quoted 3 lines
Documentation/x86/pti.txt new file +3
-0+crippled by setting the NX bit in the top level. This ensures +that if a kernel->user CR3 switch is missed that userspace will +crash immediately upon executing its first instruction."that userspace" -> "then userspace"
Randy Dunlap
reviewerQuoted 38 lines · Dave Hansen
Changes from v1:
* update kernel-parameters.txt to clarify that the pti= option is not just for disabling. Also describe what 'pti=auto' does and why
* Add a note about the presence of NX in the user portion of the kernel page tables
* Clarify _additional_ 4k of PGD space
* Add a note about the runtime overhead of PCID without INVPCID---
From: Dave Hansen <[email protected]>
Add some details about how PTI works, what some of the downsides are, and how to debug it when things go wrong.
Also document the kernel parameter: 'nopti'.
Signed-off-by Dave Hansen <[email protected]>Reviewed-by Kees Cook <[email protected]>Cc Moritz Lipp <[email protected]>Cc Daniel Gruss <[email protected]>Cc Michael Schwarz <[email protected]>Cc Richard Fellner <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Linus Torvalds <[email protected]>Cc Hugh Dickins <[email protected]>---
b/Documentation/admin-guide/kernel-parameters.txt | 22 +- b/Documentation/x86/pti.txt | 185 ++++++++++++++++++++++ 2 files changed, 200 insertions(+), 7 deletions(-)diff -puN
/dev/nullDocumentation/x86/pti.txt
Documentation/x86/pti.txt line 41
Quoted 3 lines
Documentation/x86/pti.txt new file +2
-0@@ -0,0 +1,185 @@ +The userspace copy is used when running userspace and mirrors the +mapping of userspace present in the kernel copy. It maps a only
drop: a
Documentation/x86/pti.txt line 77
Quoted 12 lines
Documentation/x86/pti.txt new file +11
-0+the kernel data needed to enter and exit the kernel. This data +is entirely contained in the 'struct cpu_entry_area' structure +which is placed in the fixmap and thus each CPU's copy of the +area has a compile-time-fixed virtual address. + +2. Runtime Cost + a. CR3 manipulation to switch between the page table copies + must be done at interrupt, syscall, and exception entry + and exit (it can be skipped when the kernel is interrupted, + though.) Moves to CR3 are on the order of a hundred + cycles, and are required every at entry and every at exit.
at every entry and at every exit.
Documentation/x86/pti.txt line 84
Quoted 2 lines
Documentation/x86/pti.txt new file +2
-0+ d. Global pages are disabled for all kernel structures not + mapped in both to kernel and userspace page tables. This
into both kernel and userspace page tables.
Quoted 4 lines
Documentation/x86/pti.txt new file +4
-0+ feature of the MMU allows different processes to share TLB + entries mapping the kernel. Losing the feature means more + TLB misses after a context switch. The actual loss of + performance is very small, however, never exceeding 1%.
Documentation/x86/pti.txt line 112
Quoted 10 lines
Documentation/x86/pti.txt new file +9
-0+ f. In addition to the fork()-time copying, there must also + be an update to the userspace PGD any time a set_pgd() is done + on a PGD used to map userspace. This ensures that the kernel + and userspace copies always map the same userspace + memory. + g. On systems without PCID support, each CR3 write flushes + the entire TLB. That means that each syscall, interrupt + or exception flushes the TLB. + h. On systems without INVPCID support, addresses can only be
This is the first mention of INVPCID. Probably needs more info about what it is.
Documentation/x86/pti.txt line 122
Quoted 10 lines
Documentation/x86/pti.txt new file +10
-0+ flushed from the TLB for the current PCID. When flushing + a kernel address, we need to flush all PCIDs, so a single + kernel address flush will require a TLB-flushing CR3 write + upon the next use of every PCID. + +Possible Future Work +==================== +1. We can be more careful about not actually writing to CR3 + unless its value is actually changed. +2. Allow PTI to enabled/disabled at runtime in addition to the
to be
Quoted 4 lines
Documentation/x86/pti.txt new file +4
-0+ boot-time switching. + +Testing +========
Signature · 1 line
~Randy