All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 00/39] Shadow stacks for userspace
@ 2022-12-03  0:35 Rick Edgecombe
  2022-12-03  0:35 ` [PATCH v4 01/39] Documentation/x86: Add CET shadow stack description Rick Edgecombe
                   ` (38 more replies)
  0 siblings, 39 replies; 107+ messages in thread
From: Rick Edgecombe @ 2022-12-03  0:35 UTC (permalink / raw)
  To: x86, H . Peter Anvin, Thomas Gleixner, Ingo Molnar, linux-kernel,
	linux-doc, linux-mm, linux-arch, linux-api, Arnd Bergmann,
	Andy Lutomirski, Balbir Singh, Borislav Petkov, Cyrill Gorcunov,
	Dave Hansen, Eugene Syromiatnikov, Florian Weimer, H . J . Lu,
	Jann Horn, Jonathan Corbet, Kees Cook, Mike Kravetz, Nadav Amit,
	Oleg Nesterov, Pavel Machek, Peter Zijlstra, Randy Dunlap,
	Weijiang Yang, Kirill A . Shutemov, John Allen, kcc, eranian,
	rppt, jamorris, dethoma, akpm, Andrew.Cooper3, christina.schimpe
  Cc: rick.p.edgecombe

Hi,

This series implements Shadow Stacks for userspace using x86's Control-flow 
Enforcement Technology (CET). CET consists of two related security features: 
Shadow Stacks and Indirect Branch Tracking. This series implements just the 
Shadow Stack part of this feature, and just for userspace.

The main use case for shadow stack is providing protection against return 
oriented programming attacks. It works by maintaining a secondary (shadow) 
stack using a special memory type that has protections against modification. 
When executing a CALL instruction, the processor pushes the return address to 
both the normal stack and to the special permissioned shadow stack. Upon RET, 
the processor pops the shadow stack copy and compares it to the normal stack 
copy. For more details, see the coverletter from v1 [0].


I humbly think this is looking decent at this point, please consider applying.

Again there were some smaller changes (logged in the patches). The more
noteworthy changes were:
 - Separate Shadow stack from IBT in kernel APIs. This involves renaming the
   arch_prctl()s. And changing the ptrace cet regset interface to only expose
   the SSP, and not any IBT bits.
 - Handle 32 bit case more completely. (see commit log of “x86: Prevent 32 bit
   operations for 64 bit shstk tasks” for the details)
 - Drop elf header bit filtering compatibility patch for now, per Linus. [1]
 - Break apart _PAGE_COW patch for bisectability reasons.

I left the Tested-by tags that were already in place, testers please re-test.

Previous version [2].

Thanks,

Rick

[0] https://lore.kernel.org/lkml/20220130211838.8382-1-rick.p.edgecombe@intel.com/
[1] https://lore.kernel.org/lkml/CAHk-=wgP5mk3poVeejw16Asbid0ghDt4okHnWaWKLBkRhQntRA@mail.gmail.com/
[2] https://lore.kernel.org/lkml/20221104223604.29615-1-rick.p.edgecombe@intel.com/

Kirill A. Shutemov (1):
  x86: Introduce userspace API for shadow stack

Mike Rapoport (1):
  x86/shstk: Add ARCH_SHSTK_UNLOCK

Rick Edgecombe (13):
  x86/fpu: Add helper for modifying xstate
  x86/mm: Introduce _PAGE_COW
  x86/mm: Start actually marking _PAGE_COW
  mm: Don't allow write GUPs to shadow stack memory
  mm: Warn on shadow stack memory in wrong vma
  x86/shstk: Introduce map_shadow_stack syscall
  x86/shstk: Support wrss for userspace
  x86: Expose thread features in /proc/$PID/status
  x86: Prevent 32 bit operations for 64 bit shstk tasks
  x86/shstk: Wire in shadow stack interface
  selftests/x86: Add shadow stack test
  x86/fpu: Add helper for initing features
  x86/shstk: Add ARCH_SHSTK_STATUS

Yu-cheng Yu (24):
  Documentation/x86: Add CET shadow stack description
  x86/shstk: Add Kconfig option for Shadow Stack
  x86/cpufeatures: Add CPU feature flags for shadow stacks
  x86/cpufeatures: Enable CET CR4 bit for shadow stack
  x86/fpu/xstate: Introduce CET MSR and XSAVES supervisor states
  x86: Add user control-protection fault handler
  x86/mm: Remove _PAGE_DIRTY from kernel RO pages
  x86/mm: Move pmd_write(), pud_write() up in the file
  x86/mm: Update pte_modify for _PAGE_COW
  x86/mm: Update ptep_set_wrprotect() and pmdp_set_wrprotect() for
    transition from _PAGE_DIRTY to _PAGE_COW
  mm: Move VM_UFFD_MINOR_BIT from 37 to 38
  mm: Introduce VM_SHADOW_STACK for shadow stack memory
  x86/mm: Check Shadow Stack page fault errors
  x86/mm: Update maybe_mkwrite() for shadow stack
  mm: Fixup places that call pte_mkwrite() directly
  mm: Add guard pages around a shadow stack.
  mm/mmap: Add shadow stack pages to memory accounting
  mm/mprotect: Exclude shadow stack from preserve_write
  mm: Re-introduce vm_flags to do_mmap()
  x86/shstk: Add user-mode shadow stack support
  x86/shstk: Handle thread shadow stack
  x86/shstk: Introduce routines modifying shstk
  x86/shstk: Handle signals for shadow stack
  x86: Add PTRACE interface for shadow stack

 Documentation/filesystems/proc.rst            |   1 +
 Documentation/x86/index.rst                   |   1 +
 Documentation/x86/shstk.rst                   | 172 +++++
 arch/arm/kernel/signal.c                      |   2 +-
 arch/arm64/kernel/signal.c                    |   2 +-
 arch/arm64/kernel/signal32.c                  |   2 +-
 arch/sparc/kernel/signal32.c                  |   2 +-
 arch/sparc/kernel/signal_64.c                 |   2 +-
 arch/x86/Kconfig                              |  24 +
 arch/x86/Kconfig.assembler                    |   5 +
 arch/x86/entry/syscalls/syscall_64.tbl        |   1 +
 arch/x86/include/asm/cpufeatures.h            |   2 +
 arch/x86/include/asm/disabled-features.h      |  16 +-
 arch/x86/include/asm/fpu/api.h                |   9 +
 arch/x86/include/asm/fpu/regset.h             |   7 +-
 arch/x86/include/asm/fpu/sched.h              |   3 +-
 arch/x86/include/asm/fpu/types.h              |  14 +-
 arch/x86/include/asm/fpu/xstate.h             |   6 +-
 arch/x86/include/asm/idtentry.h               |   2 +-
 arch/x86/include/asm/mmu_context.h            |   2 +
 arch/x86/include/asm/msr.h                    |  11 +
 arch/x86/include/asm/pgtable.h                | 320 +++++++-
 arch/x86/include/asm/pgtable_types.h          |  65 +-
 arch/x86/include/asm/processor.h              |   8 +
 arch/x86/include/asm/shstk.h                  |  52 ++
 arch/x86/include/asm/sighandling.h            |   1 +
 arch/x86/include/asm/special_insns.h          |  13 +
 arch/x86/include/asm/tlbflush.h               |   3 +-
 arch/x86/include/asm/trap_pf.h                |   2 +
 arch/x86/include/uapi/asm/mman.h              |   3 +
 arch/x86/include/uapi/asm/prctl.h             |  12 +
 arch/x86/kernel/Makefile                      |   2 +
 arch/x86/kernel/cpu/common.c                  |  37 +-
 arch/x86/kernel/cpu/cpuid-deps.c              |   1 +
 arch/x86/kernel/cpu/proc.c                    |  23 +
 arch/x86/kernel/fpu/core.c                    |  60 +-
 arch/x86/kernel/fpu/regset.c                  |  87 +++
 arch/x86/kernel/fpu/xstate.c                  | 148 ++--
 arch/x86/kernel/fpu/xstate.h                  |   6 +
 arch/x86/kernel/idt.c                         |   2 +-
 arch/x86/kernel/process.c                     |  18 +-
 arch/x86/kernel/process_64.c                  |   8 +
 arch/x86/kernel/ptrace.c                      |  12 +
 arch/x86/kernel/shstk.c                       | 495 +++++++++++++
 arch/x86/kernel/signal.c                      |  21 +
 arch/x86/kernel/signal_64.c                   |   6 +
 arch/x86/kernel/signal_compat.c               |   7 +-
 arch/x86/kernel/traps.c                       | 107 ++-
 arch/x86/mm/fault.c                           |  38 +
 arch/x86/mm/pat/set_memory.c                  |   2 +-
 arch/x86/mm/pgtable.c                         |   6 +
 arch/x86/xen/enlighten_pv.c                   |   2 +-
 arch/x86/xen/xen-asm.S                        |   2 +-
 fs/aio.c                                      |   2 +-
 fs/proc/array.c                               |   6 +
 fs/proc/task_mmu.c                            |   3 +
 include/linux/mm.h                            |  57 +-
 include/linux/pgtable.h                       |  35 +
 include/linux/proc_fs.h                       |   2 +
 include/linux/ptrace.h                        |   1 +
 include/linux/syscalls.h                      |   1 +
 include/uapi/asm-generic/siginfo.h            |   3 +-
 include/uapi/asm-generic/unistd.h             |   2 +-
 include/uapi/linux/elf.h                      |   2 +
 ipc/shm.c                                     |   2 +-
 kernel/signal.c                               |   8 +
 kernel/sys_ni.c                               |   1 +
 mm/gup.c                                      |   2 +-
 mm/huge_memory.c                              |  20 +-
 mm/memory.c                                   |   7 +-
 mm/migrate_device.c                           |   4 +-
 mm/mmap.c                                     |  12 +-
 mm/mprotect.c                                 |   8 +
 mm/nommu.c                                    |   4 +-
 mm/userfaultfd.c                              |  10 +-
 mm/util.c                                     |   2 +-
 tools/testing/selftests/x86/Makefile          |   4 +-
 .../testing/selftests/x86/test_shadow_stack.c | 685 ++++++++++++++++++
 78 files changed, 2560 insertions(+), 178 deletions(-)
 create mode 100644 Documentation/x86/shstk.rst
 create mode 100644 arch/x86/include/asm/shstk.h
 create mode 100644 arch/x86/kernel/shstk.c
 create mode 100644 tools/testing/selftests/x86/test_shadow_stack.c

-- 
2.17.1


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

end of thread, other threads:[~2023-01-05  1:29 UTC | newest]

Thread overview: 107+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-03  0:35 [PATCH v4 00/39] Shadow stacks for userspace Rick Edgecombe
2022-12-03  0:35 ` [PATCH v4 01/39] Documentation/x86: Add CET shadow stack description Rick Edgecombe
2022-12-03  2:20   ` Kees Cook
2022-12-03  8:58   ` Bagas Sanjaya
2022-12-05 21:20     ` Edgecombe, Rick P
2022-12-03  0:35 ` [PATCH v4 02/39] x86/shstk: Add Kconfig option for Shadow Stack Rick Edgecombe
2022-12-03  2:20   ` Kees Cook
2022-12-03  0:35 ` [PATCH v4 03/39] x86/cpufeatures: Add CPU feature flags for shadow stacks Rick Edgecombe
2022-12-03  2:22   ` Kees Cook
2022-12-07 11:00   ` Borislav Petkov
2022-12-07 22:35     ` Edgecombe, Rick P
2022-12-08 11:10       ` Borislav Petkov
2022-12-03  0:35 ` [PATCH v4 04/39] x86/cpufeatures: Enable CET CR4 bit for shadow stack Rick Edgecombe
2022-12-03  2:23   ` Kees Cook
2022-12-07 12:49   ` Borislav Petkov
2022-12-07 18:35     ` Edgecombe, Rick P
2022-12-03  0:35 ` [PATCH v4 05/39] x86/fpu/xstate: Introduce CET MSR and XSAVES supervisor states Rick Edgecombe
2022-12-03  2:24   ` Kees Cook
2022-12-20 11:32   ` Borislav Petkov
2022-12-21  0:45     ` Edgecombe, Rick P
2022-12-03  0:35 ` [PATCH v4 06/39] x86/fpu: Add helper for modifying xstate Rick Edgecombe
2022-12-03  2:25   ` Kees Cook
2022-12-20 12:04   ` Borislav Petkov
2022-12-21  0:03     ` Edgecombe, Rick P
2022-12-21 10:31       ` Borislav Petkov
2022-12-03  0:35 ` [PATCH v4 07/39] x86: Add user control-protection fault handler Rick Edgecombe
2022-12-03  2:28   ` Kees Cook
2022-12-20 16:19   ` Borislav Petkov
2022-12-21  0:37     ` Edgecombe, Rick P
2022-12-21 10:41       ` Borislav Petkov
2022-12-21 21:42         ` Edgecombe, Rick P
2023-01-04 12:50           ` Borislav Petkov
2022-12-20 21:21   ` Borislav Petkov
2022-12-21  0:38     ` Edgecombe, Rick P
2022-12-03  0:35 ` [PATCH v4 08/39] x86/mm: Remove _PAGE_DIRTY from kernel RO pages Rick Edgecombe
2022-12-03  2:29   ` Kees Cook
2022-12-20 19:11   ` Borislav Petkov
2022-12-03  0:35 ` [PATCH v4 09/39] x86/mm: Move pmd_write(), pud_write() up in the file Rick Edgecombe
2022-12-03  0:35 ` [PATCH v4 10/39] x86/mm: Introduce _PAGE_COW Rick Edgecombe
2022-12-03  2:31   ` Kees Cook
2022-12-20 21:29   ` Borislav Petkov
2022-12-21  0:45     ` Edgecombe, Rick P
2022-12-03  0:35 ` [PATCH v4 11/39] x86/mm: Update pte_modify for _PAGE_COW Rick Edgecombe
2022-12-03  2:31   ` Kees Cook
2022-12-27 11:42   ` Borislav Petkov
2022-12-27 23:31     ` Edgecombe, Rick P
2023-01-04 13:25       ` Borislav Petkov
2023-01-05  1:06         ` Edgecombe, Rick P
2022-12-03  0:35 ` [PATCH v4 12/39] x86/mm: Update ptep_set_wrprotect() and pmdp_set_wrprotect() for transition from _PAGE_DIRTY to _PAGE_COW Rick Edgecombe
2022-12-03  2:32   ` Kees Cook
2022-12-27 13:26   ` Borislav Petkov
2022-12-27 22:26     ` Edgecombe, Rick P
2023-01-04 13:28       ` Borislav Petkov
2022-12-03  0:35 ` [PATCH v4 13/39] x86/mm: Start actually marking _PAGE_COW Rick Edgecombe
2022-12-03  2:33   ` Kees Cook
2022-12-03  0:35 ` [PATCH v4 14/39] mm: Move VM_UFFD_MINOR_BIT from 37 to 38 Rick Edgecombe
2022-12-03  0:35 ` [PATCH v4 15/39] mm: Introduce VM_SHADOW_STACK for shadow stack memory Rick Edgecombe
2022-12-03  2:34   ` Kees Cook
2022-12-03  0:35 ` [PATCH v4 16/39] x86/mm: Check Shadow Stack page fault errors Rick Edgecombe
2023-01-04 14:32   ` Borislav Petkov
2023-01-05  1:29     ` Edgecombe, Rick P
2022-12-03  0:35 ` [PATCH v4 17/39] x86/mm: Update maybe_mkwrite() for shadow stack Rick Edgecombe
2022-12-03  2:34   ` Kees Cook
2022-12-03  0:35 ` [PATCH v4 18/39] mm: Fixup places that call pte_mkwrite() directly Rick Edgecombe
2022-12-03  2:37   ` Kees Cook
2022-12-03  0:35 ` [PATCH v4 19/39] mm: Add guard pages around a shadow stack Rick Edgecombe
2022-12-03  0:35 ` [PATCH v4 20/39] mm/mmap: Add shadow stack pages to memory accounting Rick Edgecombe
2022-12-03  2:38   ` Kees Cook
2022-12-03  0:35 ` [PATCH v4 21/39] mm/mprotect: Exclude shadow stack from preserve_write Rick Edgecombe
2022-12-03  2:38   ` Kees Cook
2022-12-03  0:35 ` [PATCH v4 22/39] mm: Re-introduce vm_flags to do_mmap() Rick Edgecombe
2022-12-03  0:35 ` [PATCH v4 23/39] mm: Don't allow write GUPs to shadow stack memory Rick Edgecombe
2022-12-03  2:39   ` Kees Cook
2022-12-03  0:35 ` [PATCH v4 24/39] mm: Warn on shadow stack memory in wrong vma Rick Edgecombe
2022-12-03  2:40   ` Kees Cook
2022-12-03  0:35 ` [PATCH v4 25/39] x86: Introduce userspace API for shadow stack Rick Edgecombe
2022-12-03  2:42   ` Kees Cook
2022-12-03  0:35 ` [PATCH v4 26/39] x86/shstk: Add user-mode shadow stack support Rick Edgecombe
2022-12-03  2:43   ` Kees Cook
2022-12-03  0:35 ` [PATCH v4 27/39] x86/shstk: Handle thread shadow stack Rick Edgecombe
2022-12-03  2:44   ` Kees Cook
2022-12-03  0:35 ` [PATCH v4 28/39] x86/shstk: Introduce routines modifying shstk Rick Edgecombe
2022-12-03  2:45   ` Kees Cook
2022-12-03  0:35 ` [PATCH v4 29/39] x86/shstk: Handle signals for shadow stack Rick Edgecombe
2022-12-03  2:46   ` Kees Cook
2022-12-03  0:35 ` [PATCH v4 30/39] x86/shstk: Introduce map_shadow_stack syscall Rick Edgecombe
2022-12-03  2:51   ` Kees Cook
2022-12-05 22:19     ` Edgecombe, Rick P
2022-12-03  0:35 ` [PATCH v4 31/39] x86/shstk: Support wrss for userspace Rick Edgecombe
2022-12-03  2:52   ` Kees Cook
2022-12-03  0:35 ` [PATCH v4 32/39] x86: Expose thread features in /proc/$PID/status Rick Edgecombe
2022-12-03  2:52   ` Kees Cook
2022-12-03  0:36 ` [PATCH v4 33/39] x86: Prevent 32 bit operations for 64 bit shstk tasks Rick Edgecombe
2022-12-03 22:49   ` Andy Lutomirski
2022-12-04 20:51     ` Edgecombe, Rick P
2022-12-15  0:25       ` Edgecombe, Rick P
2022-12-03  0:36 ` [PATCH v4 34/39] x86/shstk: Wire in shadow stack interface Rick Edgecombe
2022-12-03  0:36 ` [PATCH v4 35/39] selftests/x86: Add shadow stack test Rick Edgecombe
2022-12-03  0:36 ` [PATCH v4 36/39] x86/fpu: Add helper for initing features Rick Edgecombe
2022-12-03  0:36 ` [PATCH v4 37/39] x86: Add PTRACE interface for shadow stack Rick Edgecombe
2022-12-03  2:55   ` Kees Cook
2022-12-09 17:04   ` Mike Rapoport
2022-12-09 17:08     ` Edgecombe, Rick P
2022-12-03  0:36 ` [PATCH v4 38/39] x86/shstk: Add ARCH_SHSTK_UNLOCK Rick Edgecombe
2022-12-03  2:56   ` Kees Cook
2022-12-03  0:36 ` [PATCH v4 39/39] x86/shstk: Add ARCH_SHSTK_STATUS Rick Edgecombe
2022-12-03  2:57   ` Kees Cook

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.