Skip to contentSkip to conversation

x86/doc: add PTI description

PATCH Superseded Dave Hansen 3 participants 4 messages Jan 4, 2018 – Jan 5, 2018 Documentation

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/doc: add PTI description

This got kicked out of the PTI set as the implementation diverged from its contents. I've updated it so it can hopefully rejoin the set.

---

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'.

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 Kees Cook <[email protected]>
Cc Hugh Dickins <[email protected]>

---

 b/Documentation/admin-guide/kernel-parameters.txt |   11 +
 b/Documentation/x86/pti.txt                       |  174 ++++++++++++++++++++++
 2 files changed, 182 insertions(+), 3 deletions(-)
Documentation/admin-guide/kernel-parameters.txt renamed from Documentation/admin-guide/kernel-parameters.txt~kpti-doc +8 -3
diff -puN Documentation/admin-guide/kernel-parameters.txt~kpti-doc Documentation/admin-guide/kernel-parameters.txt
@@ -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,12 +3286,19 @@
 	pt.		[PARIDE]
 			See Documentation/blockdev/paride.txt.
 
-	pti=		[X86_64]
+	pti=		[X86_64] Disable Page Table Isolation of user and
+			kernel address spaces.  Disabling this feature
+			removes hardening, but improves performance of
+			system calls and interrupts.
+
 			Control user/kernel address space isolation:
 			on - enable
 			off - disable
 			auto - default setting
 
+	nopti		[X86_64]
+			Equivalent to pti=off
+
 	pty.legacy_count=
 			[KNL] Number of legacy pty's. Overwrites compiled-in
 			default number.
Documentation/x86/pti.txt new file +174 -0

174 lines not on this page · raw message

_

#1 lore raw

Documentation/admin-guide/kernel-parameters.txt line 3289

Quoted 3 lines · Dave Hansen
Documentation/admin-guide/kernel-parameters.txt renamed from Documentation/admin-guide/kernel-parameters.txt~kpti-doc +1 -1
-	pti=		[X86_64]
+	pti=		[X86_64] Disable Page Table Isolation of user and

That description is definitely wrong....

Quoted 5 lines
Documentation/admin-guide/kernel-parameters.txt renamed from Documentation/admin-guide/kernel-parameters.txt~kpti-doc +4 -0
+			kernel address spaces.  Disabling this feature
+			removes hardening, but improves performance of
+			system calls and interrupts.
+
 			Control user/kernel address space isolation:

Documentation/admin-guide/kernel-parameters.txt line 3304

Quoted 10 lines
Documentation/admin-guide/kernel-parameters.txt renamed from Documentation/admin-guide/kernel-parameters.txt~kpti-doc +3 -0
 			on - enable
 			off - disable
 			auto - default setting
 
+	nopti		[X86_64]
+			Equivalent to pti=off
+
 	pty.legacy_count=
 			[KNL] Number of legacy pty's. Overwrites compiled-in
 			default number.

Thanks,

tglx

Reviewed-by on v1 1/1
#2 lore raw
In reply to Dave Hansen

Documentation/x86/pti.txt line 46

Quoted 6 lines · Dave Hansen

[...]

Documentation/x86/pti.txt new file +5 -0
+For new userspace mappings, the kernel makes the entries in its
+page tables like normal.  The only difference is when the kernel
+makes entries in the top (PGD) level.  In addition to setting the
+entry in the main kernel PGD, a copy of the entry is made in the
+userspace page tables' PGD.

It might be worth noting that NX is set in the kernel's view of the userspace page tables.

Documentation/x86/pti.txt line 61

Quoted 4 lines

[...]
+1. Increased Memory Use

Documentation/x86/pti.txt new file +2 -0
+  a. Each process now needs an order-1 PGD instead of order-0.
+     (Consumes 4k per process).

"Consumes an additional 4k per process" ?

Documentation/x86/pti.txt line 90

Quoted 8 lines

[...]

Documentation/x86/pti.txt new file +7 -0
+  d. Process Context IDentifiers (PCID) is a CPU feature that
+     allows us to skip flushing the entire TLB when switching page
+     tables.  This makes switching the page tables (at context
+     switch, or kernel entry/exit) cheaper.  But, on systems with
+     PCID support, the context switch code must flush both the user
+     and kernel entries out of the TLB.  The user PCID TLB flush is
+     deferred until the exit to userspace, minimizing the cost.

Does this mean it's possible to bypass the NX on userspace pages?

Documentation/x86/pti.txt line 105

Quoted 4 lines

[...]

Documentation/x86/pti.txt new file +3 -0
+  g. On systems without PCID support, each CR3 write flushes
+     the entire TLB.  That means that each syscall, interrupt
+     or exception flushes the TLB.

Is it worth clarifying this for hardware support of PCID vs INVPCID?

Otherwise, looks good!

-Kees

Signature · 2 lines
Kees Cook
Pixel Security
#3 lore raw
Quoted 9 lines · Kees Cook

Documentation/x86/pti.txt line 90

Quoted 7 lines
Documentation/x86/pti.txt new file +7 -0
+  d. Process Context IDentifiers (PCID) is a CPU feature that
+     allows us to skip flushing the entire TLB when switching page
+     tables.  This makes switching the page tables (at context
+     switch, or kernel entry/exit) cheaper.  But, on systems with
+     PCID support, the context switch code must flush both the user
+     and kernel entries out of the TLB.  The user PCID TLB flush is
+     deferred until the exit to userspace, minimizing the cost.

Does this mean it's possible to bypass the NX on userspace pages?

I'll clarify this. The write to CR3 happens, but bit 63 gets set to tell the CPU not to flush the TLB on the CR3 write.

Quoted 6 lines

Documentation/x86/pti.txt line 105

Quoted 4 lines

[...]

Documentation/x86/pti.txt new file +3 -0
+  g. On systems without PCID support, each CR3 write flushes
+     the entire TLB.  That means that each syscall, interrupt
+     or exception flushes the TLB.

Is it worth clarifying this for hardware support of PCID vs INVPCID?

I'll make changes based on the rest of your comments. Thanks for taking a look!