[patch 00/16] x86/ldt: Use a VMA based read only mapping

From: Thomas Gleixner
Date: Tue Dec 12 2017 - 12:37:08 EST


Peter and myself spent quite some time to figure out how to make CPUs cope
with a RO mapped LDT.

While the initial trick of writing the ACCESS bit in a special fault
handler covers most cases, the tricky problem of CS/SS in return to user
space (IRET ...) was giving us quite some headache.

Peter finally found a way to do so. Touching the CS/SS selectors with LAR
on the way out to user space makes it work w/o trouble.

Contrary to the approach Andy was taking with storing the LDT in a special
map area, the following series uses a special mapping which is mapped
without the user bit and read only. This just ties the LDT to the process
which is the most natural way to do it, removes the requirement for special
pagetable code and works independent of pagetable isolation.

This was tested on quite a range of Intel and AMD machines, but the test
coverage on 32bit is quite meager. I'll resurrect a few dust bricks
tomorrow.

The patch series also includes an updated version of the: do not inherit
LDT on exec changes.

There are some extensions to the VMA code, which need scrunity of the mm
folks.

Thanks,

tglx
---
arch/powerpc/include/asm/mmu_context.h | 5
arch/powerpc/platforms/Kconfig.cputype | 1
arch/s390/Kconfig | 1
arch/x86/entry/common.c | 8
arch/x86/include/asm/desc.h | 2
arch/x86/include/asm/mmu.h | 7
arch/x86/include/asm/thread_info.h | 4
arch/x86/include/uapi/asm/mman.h | 4
arch/x86/kernel/cpu/common.c | 4
arch/x86/kernel/ldt.c | 573 ++++++++++++++++++++++-------
arch/x86/mm/fault.c | 19
arch/x86/mm/tlb.c | 2
arch/x86/power/cpu.c | 2
b/arch/um/include/asm/mmu_context.h | 3
b/arch/unicore32/include/asm/mmu_context.h | 5
b/arch/x86/include/asm/mmu_context.h | 93 +++-
b/include/linux/mman.h | 4
include/asm-generic/mm_hooks.h | 5
include/linux/mm.h | 21 -
include/linux/mm_types.h | 3
kernel/fork.c | 3
mm/internal.h | 2
mm/mmap.c | 16
tools/testing/selftests/x86/ldt_gdt.c | 83 +++-
24 files changed, 673 insertions(+), 197 deletions(-)