All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/31 v2] PTI support for x86_32
@ 2018-02-09  9:25 ` Joerg Roedel
  0 siblings, 0 replies; 181+ messages in thread
From: Joerg Roedel @ 2018-02-09  9:25 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H . Peter Anvin
  Cc: x86, linux-kernel, linux-mm, Linus Torvalds, Andy Lutomirski,
	Dave Hansen, Josh Poimboeuf, Juergen Gross, Peter Zijlstra,
	Borislav Petkov, Jiri Kosina, Boris Ostrovsky, Brian Gerst,
	David Laight, Denys Vlasenko, Eduardo Valentin, Greg KH,
	Will Deacon, aliguori, daniel.gruss, hughd, keescook,
	Andrea Arcangeli, Waiman Long, Pavel Machek, jroedel, joro

Hi,

here is the second version of my PTI implementation for
x86_32, based on tip/x86-pti-for-linus. It took a lot longer
than I had hoped, but there have been a number of obstacles
on the way. It also isn't the small patch-set anymore that v1
was, but compared to it this one actually works :)

The biggest changes were necessary in the entry code, a lot
of it is moving code around, but there are also significant
changes to get all cases covered. This includes NMIs and
exceptions on the kernel exit-path where we are already on
the entry-stack. To make this work I decided to mostly split
up the common kernel-exit path into a return-to-kernel,
return-to-user and return-from-nmi part.

On the page-table side I had to do a lot of special cases
for PAE because PAE paging is so, well, special. The biggest
example here is the LDT mapping code, which needs to work on
the PMD level instead of PGD when PAE is enabled.

During development I also experimented with unshared PMDs
between the kernel and the user page-tables for PAE. It
worked by allocating 8k PMDs and using the lower half for
the kernel and the upper half for the user page-table. While
this worked and allowed me to NX-protect the user-space
address-range in the kernel page-table, it also required 5
order-1 allocations in low-mem for each process. In my
testing I got this to fail pretty quickly and trigger OOM,
so I abandoned the approach for now.

Here is how I tested these patches:

	* Booted on a real machine (4C/8T, 16GB RAM) and run
	  an overnight load-test with 'perf top' running
	  (for the NMIs), the ldt_gdt selftest running in a
	  loop (for more stress on the entry/exit path) and
	  a -j16 kernel compile also running in a loop. The
	  box survived the test, which ran for more than 18
	  hours.

	* Tested most x86 selftests in the kernel on the
	  real machine. This showed no regressions. I did
	  not run the mpx and protection-key tests, as the
	  machine does not support these features, and I
	  also skipped the check_initial_reg_state test, as
	  it made problems while compiling and it didn't
	  seem relevant enough to fix that for this
	  patch-set.

	* Boot tested all valid combinations of [NO]HIGHMEM* vs.
	  VMSPLIT* vs. PAE in KVM. All booted fine.

	* Did compile-tests with various configs (allyes,
	  allmod, defconfig, ..., basically what I usually
	  use to test the iommu-tree as well). All compiled
	  fine.

	* Some basic compile, boot and runtime testing of
	  64 bit to make sure I didn't break anything there.

I did not explicitly test wine and dosemu, but since the
vm86 and the ldt_gdt self-tests all passed fine I am
confident that those will also still work.

XENPV is also untested from my side, but I added checks to
not do the stack switches in the entry-code when XENPV is
enabled, so hopefully it works. But someone should test it,
of course.

I also pushed these patches to

	git://git.kernel.org/pub/scm/linux/kernel/git/joro/linux.git pti-x32-v2

for easier testing.

I do not claim that I've found the best solution for every
problem I encountered, so please review and give me feedback
on what I should change or solve differently. Of course I am
also interested in all bugs that may still be in there.

Thanks a lot,

       Joerg


Joerg Roedel (31):
  x86/asm-offsets: Move TSS_sp0 and TSS_sp1 to asm-offsets.c
  x86/entry/32: Rename TSS_sysenter_sp0 to TSS_entry_stack
  x86/entry/32: Load task stack from x86_tss.sp1 in SYSENTER handler
  x86/entry/32: Put ESPFIX code into a macro
  x86/entry/32: Unshare NMI return path
  x86/entry/32: Split off return-to-kernel path
  x86/entry/32: Restore segments before int registers
  x86/entry/32: Enter the kernel via trampoline stack
  x86/entry/32: Leave the kernel via trampoline stack
  x86/entry/32: Introduce SAVE_ALL_NMI and RESTORE_ALL_NMI
  x86/entry/32: Add PTI cr3 switches to NMI handler code
  x86/entry/32: Add PTI cr3 switch to non-NMI entry/exit points
  x86/entry/32: Handle Entry from Kernel-Mode on Entry-Stack
  x86/pgtable/pae: Unshare kernel PMDs when PTI is enabled
  x86/pgtable/32: Allocate 8k page-tables when PTI is enabled
  x86/pgtable: Move pgdp kernel/user conversion functions to pgtable.h
  x86/pgtable: Move pti_set_user_pgd() to pgtable.h
  x86/pgtable: Move two more functions from pgtable_64.h to pgtable.h
  x86/mm/pae: Populate valid user PGD entries
  x86/mm/pae: Populate the user page-table with user pgd's
  x86/mm/legacy: Populate the user page-table with user pgd's
  x86/mm/pti: Add an overflow check to pti_clone_pmds()
  x86/mm/pti: Define X86_CR3_PTI_PCID_USER_BIT on x86_32
  x86/mm/pti: Clone CPU_ENTRY_AREA on PMD level on x86_32
  x86/mm/dump_pagetables: Define INIT_PGD
  x86/pgtable/pae: Use separate kernel PMDs for user page-table
  x86/ldt: Reserve address-space range on 32 bit for the LDT
  x86/ldt: Define LDT_END_ADDR
  x86/ldt: Split out sanity check in map_ldt_struct()
  x86/ldt: Enable LDT user-mapping for PAE
  x86/pti: Allow CONFIG_PAGE_TABLE_ISOLATION for x86_32

 arch/x86/entry/entry_32.S                   | 581 ++++++++++++++++++++++------
 arch/x86/include/asm/mmu_context.h          |   4 -
 arch/x86/include/asm/pgtable-2level.h       |   9 +
 arch/x86/include/asm/pgtable-2level_types.h |   3 +
 arch/x86/include/asm/pgtable-3level.h       |   7 +
 arch/x86/include/asm/pgtable-3level_types.h |   6 +-
 arch/x86/include/asm/pgtable.h              |  88 +++++
 arch/x86/include/asm/pgtable_32_types.h     |   9 +-
 arch/x86/include/asm/pgtable_64.h           |  85 ----
 arch/x86/include/asm/pgtable_64_types.h     |   4 +
 arch/x86/include/asm/pgtable_types.h        |  26 +-
 arch/x86/include/asm/processor-flags.h      |   8 +-
 arch/x86/include/asm/switch_to.h            |   6 +-
 arch/x86/kernel/asm-offsets.c               |   5 +
 arch/x86/kernel/asm-offsets_32.c            |   2 +-
 arch/x86/kernel/asm-offsets_64.c            |   2 -
 arch/x86/kernel/cpu/common.c                |   5 +-
 arch/x86/kernel/head_32.S                   |  20 +-
 arch/x86/kernel/ldt.c                       | 137 +++++--
 arch/x86/kernel/process.c                   |   2 -
 arch/x86/kernel/process_32.c                |  10 +-
 arch/x86/mm/dump_pagetables.c               |  21 +-
 arch/x86/mm/pgtable.c                       | 105 ++++-
 arch/x86/mm/pti.c                           |  24 ++
 security/Kconfig                            |   2 +-
 25 files changed, 888 insertions(+), 283 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 181+ messages in thread

end of thread, other threads:[~2018-03-16 20:55 UTC | newest]

Thread overview: 181+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-09  9:25 [PATCH 00/31 v2] PTI support for x86_32 Joerg Roedel
2018-02-09  9:25 ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 01/31] x86/asm-offsets: Move TSS_sp0 and TSS_sp1 to asm-offsets.c Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 02/31] x86/entry/32: Rename TSS_sysenter_sp0 to TSS_entry_stack Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 03/31] x86/entry/32: Load task stack from x86_tss.sp1 in SYSENTER handler Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 04/31] x86/entry/32: Put ESPFIX code into a macro Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 05/31] x86/entry/32: Unshare NMI return path Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 06/31] x86/entry/32: Split off return-to-kernel path Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 07/31] x86/entry/32: Restore segments before int registers Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 08/31] x86/entry/32: Enter the kernel via trampoline stack Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 09/31] x86/entry/32: Leave " Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09 17:05   ` Linus Torvalds
2018-02-09 17:05     ` Linus Torvalds
2018-02-09 17:17     ` Denys Vlasenko
2018-02-09 17:17       ` Denys Vlasenko
2018-02-10 15:26       ` David Laight
2018-02-10 15:26         ` David Laight
2018-02-10 20:18         ` Linus Torvalds
2018-02-10 20:18           ` Linus Torvalds
2018-02-09 17:43     ` Andy Lutomirski
2018-02-09 17:43       ` Andy Lutomirski
2018-02-09 19:06       ` Joerg Roedel
2018-02-09 19:06         ` Joerg Roedel
2018-02-09 19:02     ` Joerg Roedel
2018-02-09 19:02       ` Joerg Roedel
2018-02-09 19:17       ` Linus Torvalds
2018-02-09 19:17         ` Linus Torvalds
2018-02-09 19:25         ` Joerg Roedel
2018-02-09 19:25           ` Joerg Roedel
2018-02-09 19:48           ` Linus Torvalds
2018-02-09 19:48             ` Linus Torvalds
2018-02-10 15:41             ` David Laight
2018-02-10 15:41               ` David Laight
2018-02-09 19:30       ` Denys Vlasenko
2018-02-09 19:30         ` Denys Vlasenko
2018-02-09  9:25 ` [PATCH 10/31] x86/entry/32: Introduce SAVE_ALL_NMI and RESTORE_ALL_NMI Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 11/31] x86/entry/32: Add PTI cr3 switches to NMI handler code Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 12/31] x86/entry/32: Add PTI cr3 switch to non-NMI entry/exit points Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-27 19:18   ` Waiman Long
2018-02-27 19:18     ` Waiman Long
2018-03-01 12:03     ` Joerg Roedel
2018-03-01 12:03       ` Joerg Roedel
2018-03-01 13:34     ` Joerg Roedel
2018-03-01 13:34       ` Joerg Roedel
2018-03-01 14:33       ` Waiman Long
2018-03-01 14:33         ` Waiman Long
2018-03-01 16:50         ` Joerg Roedel
2018-03-01 16:50           ` Joerg Roedel
2018-03-01 18:24           ` Brian Gerst
2018-03-01 18:24             ` Brian Gerst
2018-03-01 18:36             ` Dave Hansen
2018-03-01 18:36               ` Dave Hansen
2018-03-01 18:38             ` Linus Torvalds
2018-03-01 18:38               ` Linus Torvalds
2018-03-02  9:10               ` Joerg Roedel
2018-03-02  9:10                 ` Joerg Roedel
2018-03-16 20:55                 ` Andy Lutomirski
2018-03-02  9:07             ` Joerg Roedel
2018-03-02  9:07               ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 13/31] x86/entry/32: Handle Entry from Kernel-Mode on Entry-Stack Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 14/31] x86/pgtable/pae: Unshare kernel PMDs when PTI is enabled Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 15/31] x86/pgtable/32: Allocate 8k page-tables " Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 16/31] x86/pgtable: Move pgdp kernel/user conversion functions to pgtable.h Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 17/31] x86/pgtable: Move pti_set_user_pgd() " Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 18/31] x86/pgtable: Move two more functions from pgtable_64.h " Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 19/31] x86/mm/pae: Populate valid user PGD entries Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-14  9:45   ` Juergen Gross
2018-02-14  9:45     ` Juergen Gross
2018-02-14 10:00     ` Joerg Roedel
2018-02-14 10:00       ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 20/31] x86/mm/pae: Populate the user page-table with user pgd's Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09 17:48   ` Andy Lutomirski
2018-02-09 17:48     ` Andy Lutomirski
2018-02-09 19:09     ` Joerg Roedel
2018-02-09 19:09       ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 21/31] x86/mm/legacy: " Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 22/31] x86/mm/pti: Add an overflow check to pti_clone_pmds() Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 23/31] x86/mm/pti: Define X86_CR3_PTI_PCID_USER_BIT on x86_32 Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09 17:42   ` Andy Lutomirski
2018-02-09 17:42     ` Andy Lutomirski
2018-02-09  9:25 ` [PATCH 24/31] x86/mm/pti: Clone CPU_ENTRY_AREA on PMD level " Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 25/31] x86/mm/dump_pagetables: Define INIT_PGD Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 26/31] x86/pgtable/pae: Use separate kernel PMDs for user page-table Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 27/31] x86/ldt: Reserve address-space range on 32 bit for the LDT Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 28/31] x86/ldt: Define LDT_END_ADDR Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 29/31] x86/ldt: Split out sanity check in map_ldt_struct() Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 30/31] x86/ldt: Enable LDT user-mapping for PAE Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09  9:25 ` [PATCH 31/31] x86/pti: Allow CONFIG_PAGE_TABLE_ISOLATION for x86_32 Joerg Roedel
2018-02-09  9:25   ` Joerg Roedel
2018-02-09 12:11 ` [PATCH 00/31 v2] PTI support " Juergen Gross
2018-02-09 12:11   ` Juergen Gross
2018-02-09 13:35   ` Joerg Roedel
2018-02-09 13:35     ` Joerg Roedel
2018-02-09 13:54     ` Andrew Cooper
2018-02-09 13:54       ` Andrew Cooper
2018-02-09 17:47 ` Andy Lutomirski
2018-02-09 17:47   ` Andy Lutomirski
2018-02-09 19:11   ` Joerg Roedel
2018-02-09 19:11     ` Joerg Roedel
2018-02-10  9:15     ` Adam Borowski
2018-02-10  9:15       ` Adam Borowski
2018-02-10 20:22       ` Linus Torvalds
2018-02-10 20:22         ` Linus Torvalds
2018-02-11 10:59         ` Adam Borowski
2018-02-11 10:59           ` Adam Borowski
2018-02-11 17:40           ` Mark D Rustad
2018-02-11 19:42             ` Andy Lutomirski
2018-02-11 19:42               ` Andy Lutomirski
2018-02-11 20:14               ` Linus Torvalds
2018-02-11 20:14                 ` Linus Torvalds
2018-02-11 22:12               ` James Bottomley
2018-02-11 22:12                 ` James Bottomley
2018-02-11 22:30                 ` Andy Lutomirski
2018-02-11 22:30                   ` Andy Lutomirski
2018-02-11 23:47                   ` James Bottomley
2018-02-11 23:47                     ` James Bottomley
2018-02-11 22:34               ` Pavel Machek
2018-02-11 22:34                 ` Pavel Machek
2018-02-11 23:25               ` Alan Cox
2018-02-11 23:25                 ` Alan Cox
2018-02-12 10:16                 ` Anders Larsen
2018-02-12 10:16                   ` Anders Larsen
2018-02-14 10:43               ` Pavel Machek
2018-02-15  3:44                 ` joe.korty
2018-02-16 14:34                   ` Pavel Machek
2018-02-13  8:54             ` Greg KH
2018-02-13  8:54               ` Greg KH
2018-02-13 17:25               ` Linus Torvalds
2018-02-13 17:25                 ` Linus Torvalds
2018-02-14  8:54                 ` Greg KH
2018-02-14  8:54                   ` Greg KH
2018-02-21 10:26                   ` Lorenzo Colitti
2018-02-21 10:26                     ` Lorenzo Colitti
2018-02-21 16:59                     ` Arnd Bergmann
2018-02-21 16:59                       ` Arnd Bergmann
2018-02-22 11:10                       ` Greg KH
2018-02-22 11:10                         ` Greg KH
2018-02-22 11:18                         ` Arnd Bergmann
2018-02-22 11:18                           ` Arnd Bergmann
2018-03-06 15:39                 ` Jason A. Donenfeld
2018-03-06 15:39                   ` Jason A. Donenfeld
2018-03-06 15:39                   ` Jason A. Donenfeld
2018-02-11 19:13     ` Ingo Molnar
2018-02-11 19:13       ` Ingo Molnar
2018-02-12 14:51       ` Joerg Roedel
2018-02-12 14:51         ` Joerg Roedel
2018-02-09 21:09   ` Pavel Machek
2018-02-09 21:11     ` Linus Torvalds
2018-02-09 21:11       ` Linus Torvalds
2018-02-09 21:28     ` Andrew Cooper
2018-02-09 21:28       ` Andrew Cooper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.