[PATCH v25 28/30] mm: Move arch_calc_vm_prot_bits() to arch/x86/include/asm/mman.h

2021-04-15 Thread Yu-cheng Yu
To prepare the introduction of PROT_SHSTK and be consistent with other architectures, move arch_vm_get_page_prot() and arch_calc_vm_prot_bits() to arch/x86/include/asm/mman.h. Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook Cc: Kirill A. Shutemov --- arch/x86/include/asm/mman.h | 30

[PATCH v25 9/9] x86/vdso: Add ENDBR to __vdso_sgx_enter_enclave

2021-04-15 Thread Yu-cheng Yu
. ENDBR is a noop when IBT is unsupported or disabled. Most ENDBR instructions are inserted automatically by the compiler, but branch targets written in assembly must have ENDBR added manually. Add ENDBR to __vdso_sgx_enter_enclave() branch targets. Signed-off-by: Yu-cheng Yu Cc: Andy Lutomirski

[PATCH v25 8/9] x86/vdso/32: Add ENDBR to __kernel_vsyscall entry point

2021-04-15 Thread Yu-cheng Yu
off-by: Yu-cheng Yu Cc: Andy Lutomirski Cc: Kees Cook --- arch/x86/entry/vdso/vdso32/system_call.S | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/entry/vdso/vdso32/system_call.S b/arch/x86/entry/vdso/vdso32/system_call.S index de1fff7188aa..7793dc221726 100644 --- a/arch/x86/entry/v

[PATCH v25 7/9] x86/vdso: Introduce ENDBR macro

2021-04-15 Thread Yu-cheng Yu
for the proper one. Introduce ENDBR macro, which equals the compiler macro when enabled, otherwise nothing. Signed-off-by: Yu-cheng Yu Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Dave Hansen Cc: Jarkko Sakkinen Cc: Peter Zijlstra --- v25: - Change from using the compiler's cet.h back to just

[PATCH v25 6/9] x86/vdso: Insert endbr32/endbr64 to vDSO

2021-04-15 Thread Yu-cheng Yu
off-by: Yu-cheng Yu Cc: Andy Lutomirski Cc: Kees Cook --- v24: - Replace CONFIG_X86_CET with CONFIG_X86_IBT to reflect splitting of shadow stack and ibt. arch/x86/entry/vdso/Makefile | 4 1 file changed, 4 insertions(+) diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vds

[PATCH v25 4/9] x86/cet/ibt: Update ELF header parsing for Indirect Branch Tracking

2021-04-15 Thread Yu-cheng Yu
An ELF file's .note.gnu.property indicates features the file supports. The property is parsed at loading time and passed to arch_setup_elf_ property(). Update it for Indirect Branch Tracking. Signed-off-by: Yu-cheng Yu Cc: Kees Cook --- v24: - Update for splitting shadow stack and ibt. arch

[PATCH v25 5/9] x86/cet/ibt: Update arch_prctl functions for Indirect Branch Tracking

2021-04-15 Thread Yu-cheng Yu
From: "H.J. Lu" Update ARCH_X86_CET_STATUS and ARCH_X86_CET_DISABLE for Indirect Branch Tracking. Signed-off-by: H.J. Lu Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook --- v24: - Update for function name changes from splitting shadow stack and ibt. arch/x86/kernel/cet_p

[PATCH v25 3/9] x86/cet/ibt: Handle signals for Indirect Branch Tracking

2021-04-15 Thread Yu-cheng Yu
machine is described in Intel SDM Vol. 1, Sec. 18.3. Signed-off-by: Yu-cheng Yu Cc: Kees Cook --- v25: - Move the addition of sc_ext.wait_endbr from an earlier shadow stack patch to here. - Change X86_FEATURE_CET to X86_FEATURE_SHSTK. - Change wrmsrl() to wrmsrl_safe() and handle error. v24

[PATCH v25 30/30] mm: Introduce PROT_SHSTK for shadow stack

2021-04-15 Thread Yu-cheng Yu
would be using this as a bypass to shadow stack protection. However, the attacker would have to get to the syscall first. [1] https://lore.kernel.org/lkml/20200828121624.108243-1-hjl.to...@gmail.com/ Signed-off-by: Yu-cheng Yu Cc: Kees Cook Cc: Kirill A. Shutemov --- v24: - Update

[PATCH v25 29/30] mm: Update arch_validate_flags() to include vma anonymous

2021-04-15 Thread Yu-cheng Yu
("arm64: mte: Add PROT_MTE support to mmap() and mprotect()"), Signed-off-by: Yu-cheng Yu Cc: Catalin Marinas Cc: Kees Cook Cc: Kirill A. Shutemov Cc: Vincenzo Frascino Cc: Will Deacon --- arch/arm64/include/asm/mman.h | 4 ++-- arch/sparc/include/asm/mman.h | 4 ++-- include/li

[PATCH v25 1/9] x86/cet/ibt: Add Kconfig option for Indirect Branch Tracking

2021-04-15 Thread Yu-cheng Yu
protection. Signed-off-by: Yu-cheng Yu Cc: Kees Cook --- v25: - Make CONFIG_X86_IBT depend on CONFIG_X86_SHADOW_STACK. arch/x86/Kconfig | 19 +++ arch/x86/include/asm/disabled-features.h | 8 +++- 2 files changed, 26 insertions(+), 1 deletion

[PATCH v25 27/30] x86/cet/shstk: Add arch_prctl functions for shadow stack

2021-04-15 Thread Yu-cheng Yu
do_arch_prctl_common()'s parameter 'cpuid_enabled' to 'arg2', as it is now also passed to prctl_cet(). Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook --- v25: - Change CONFIG_X86_CET to CONFIG_X86_SHADOW_STACK. - Change X86_FEATURE_CET to X86_FEATURE_SHSTK. v24: - Update #ifdef placement

[PATCH v25 2/9] x86/cet/ibt: Add user-mode Indirect Branch Tracking support

2021-04-15 Thread Yu-cheng Yu
Introduce user-mode Indirect Branch Tracking (IBT) support. Add routines for the setup/disable of IBT. Signed-off-by: Yu-cheng Yu Cc: Kees Cook --- v24: - Move IBT routines to a separate ibt.c, update related areas accordingly. arch/x86/include/asm/cet.h | 9 ++ arch/x86/kernel/Makefile

[PATCH v25 0/9] Control-flow Enforcement: Indirect Branch Tracking

2021-04-15 Thread Yu-cheng Yu
arch_prctl functions for Indirect Branch Tracking x86/vdso: Insert endbr32/endbr64 to vDSO x86/vdso/32: Add ENDBR to __kernel_vsyscall entry point Yu-cheng Yu (6): x86/cet/ibt: Add Kconfig option for Indirect Branch Tracking x86/cet/ibt: Add user-mode Indirect Branch Tracking support x

[PATCH v25 26/30] ELF: Introduce arch_setup_elf_property()

2021-04-15 Thread Yu-cheng Yu
of this function is Shadow Stack. ARM64 is the other arch that has ARCH_USE_GNU_PROPERTY and arch_parse_elf_ property(). Add arch_setup_elf_property() for it. Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook Cc: Mark Brown Cc: Catalin Marinas Cc: Dave Martin --- v24: - Change cet_setup_shstk

[PATCH v25 25/30] x86/cet/shstk: Handle signals for shadow stack

2021-04-15 Thread Yu-cheng Yu
(), - restore_extra_state_to_xregs(). Signed-off-by: Yu-cheng Yu Cc: Kees Cook --- v25: - Update commit log/comments for the sc_ext struct. - Use restorer address already calculated. - Change CONFIG_X86_CET to CONFIG_X86_SHADOW_STACK. - Change X86_FEATURE_CET to X86_FEATURE_SHSTK. - Eliminate writing to MSR_IA32_U_CET

[PATCH v25 24/30] x86/cet/shstk: Introduce shadow stack token setup/verify routines

2021-04-15 Thread Yu-cheng Yu
setup and verify routines. Also introduce WRUSS, which is a kernel-mode instruction but writes directly to user shadow stack. It is used to construct user signal stack as described above. Signed-off-by: Yu-cheng Yu Cc: Kees Cook --- v25: - Update inline assembly syntax, use %[]. - Change token

[PATCH v25 23/30] x86/cet/shstk: Handle thread shadow stack

2021-04-15 Thread Yu-cheng Yu
). A compat-mode thread shadow stack size is further reduced to 1/4. This allows more threads to run in a 32- bit address space. Signed-off-by: Yu-cheng Yu --- arch/x86/include/asm/cet.h | 5 +++ arch/x86/include/asm/mmu_context.h | 3 ++ arch/x86/kernel/process.c | 15

[PATCH v25 21/30] mm: Re-introduce vm_flags to do_mmap()

2021-04-15 Thread Yu-cheng Yu
Thus, re-introduce vm_flags to do_mmap(). Signed-off-by: Yu-cheng Yu Reviewed-by: Peter Collingbourne Reviewed-by: Kees Cook Cc: Andrew Morton Cc: Oleg Nesterov Cc: linux...@kvack.org --- v24: - Change VM_SHSTK to VM_SHADOW_STACK. - Update commit log. fs/aio.c | 2 +- include/linux

[PATCH v25 22/30] x86/cet/shstk: Add user-mode shadow stack support

2021-04-15 Thread Yu-cheng Yu
Introduce basic shadow stack enabling/disabling/allocation routines. A task's shadow stack is allocated from memory with VM_SHADOW_STACK flag and has a fixed size of min(RLIMIT_STACK, 4GB). Signed-off-by: Yu-cheng Yu Cc: Kees Cook --- v25: - Change CONFIG_X86_CET to CONFIG_X86_SHADOW_STACK

[PATCH v25 20/30] mm/mprotect: Exclude shadow stack from preserve_write

2021-04-15 Thread Yu-cheng Yu
to preserve it. Exclude shadow stack from preserve_write test, and apply the same change to change_huge_pmd(). Signed-off-by: Yu-cheng Yu Cc: Kirill A. Shutemov --- v25: - Move is_shadow_stack_mapping() to a separate line. v24: - Change arch_shadow_stack_mapping() to is_shadow_stack_mapping

[PATCH v25 19/30] mm: Update can_follow_write_pte() for shadow stack

2021-04-15 Thread Yu-cheng Yu
, in the can_follow_write_pte() check, it belongs to the writable page case and should be excluded from the read-only page pte_dirty() check. Apply the same changes to can_follow_write_pmd(). While at it, also split the long line into smaller ones. Signed-off-by: Yu-cheng Yu Cc: Kees Cook Cc: Kirill A. Shutemov

[PATCH v25 18/30] mm/mmap: Add shadow stack pages to memory accounting

2021-04-15 Thread Yu-cheng Yu
Account shadow stack pages to stack memory. Signed-off-by: Yu-cheng Yu Cc: Kees Cook Cc: Kirill A. Shutemov --- v25: - Remove #ifdef CONFIG_ARCH_HAS_SHADOW_STACK for is_shadow_stack_mapping(). v24: - Change arch_shadow_stack_mapping() to is_shadow_stack_mapping(). - Change VM_SHSTK

[PATCH v25 17/30] mm: Add guard pages around a shadow stack.

2021-04-15 Thread Yu-cheng Yu
, putting a gap page on both ends of a shadow stack prevents INCSSP, CALL, and RET from going beyond. Signed-off-by: Yu-cheng Yu Reviewed-by: Kirill A. Shutemov Cc: Kees Cook --- v25: - Move SHADOW_STACK_GUARD_GAP to arch/x86/mm/mmap.c. v24: - Instead changing vm_*_gap(), create x86-specific

[PATCH v25 16/30] mm: Fixup places that call pte_mkwrite() directly

2021-04-15 Thread Yu-cheng Yu
(). Signed-off-by: Yu-cheng Yu Cc: Kees Cook Cc: Kirill A. Shutemov --- v25: - Apply same changes to do_huge_pmd_numa_page() as to do_numa_page(). mm/huge_memory.c | 2 +- mm/memory.c | 5 ++--- mm/migrate.c | 3 +-- mm/mprotect.c| 2 +- 4 files changed, 5 insertions(+), 7 deletions

[PATCH v25 15/30] x86/mm: Update maybe_mkwrite() for shadow stack

2021-04-15 Thread Yu-cheng Yu
and the shadow stack page is writable again. Introduce an x86 version of maybe_mkwrite(), which sets proper PTE bits according to VM flags. Apply the same changes to maybe_pmd_mkwrite(). Signed-off-by: Yu-cheng Yu Reviewed-by: Kirill A. Shutemov Cc: Kees Cook --- v24: - Instead of doing

[PATCH v25 14/30] x86/mm: Shadow Stack page fault error checking

2021-04-15 Thread Yu-cheng Yu
clearing _PAGE_DIRTY (vs. _PAGE_RW) is used to trigger the fault, shadow stack read fault and shadow stack write fault are not differentiated and both are handled as a write access. Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook Reviewed-by: Kirill A. Shutemov --- v24: - Change VM_SHSTK

[PATCH v25 13/30] mm: Introduce VM_SHADOW_STACK for shadow stack memory

2021-04-15 Thread Yu-cheng Yu
A shadow stack PTE must be read-only and have _PAGE_DIRTY set. However, read-only and Dirty PTEs also exist for copy-on-write (COW) pages. These two cases are handled differently for page faults. Introduce VM_SHADOW_STACK to track shadow stack VMAs. Signed-off-by: Yu-cheng Yu Reviewed

[PATCH v25 12/30] x86/mm: Update ptep_set_wrprotect() and pmdp_set_wrprotect() for transition from _PAGE_DIRTY to _PAGE_COW

2021-04-15 Thread Yu-cheng Yu
non- atomically, a transient shadow stack PTE can be created as a result. Thus, prevent that with cmpxchg. Dave Hansen, Jann Horn, Andy Lutomirski, and Peter Zijlstra provided many insights to the issue. Jann Horn provided the cmpxchg solution. Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook

[PATCH v25 11/30] x86/mm: Update pte_modify for _PAGE_COW

2021-04-15 Thread Yu-cheng Yu
, and pte_*() are updated. Pte_modify() changes a PTE to 'newprot', but it doesn't use the pte_*(). Introduce fixup_dirty_pte(), which sets a dirty PTE, based on _PAGE_RW, to either _PAGE_DIRTY or _PAGE_COW. Apply the same changes to pmd_modify(). Signed-off-by: Yu-cheng Yu Reviewed-by: Kirill

[PATCH v25 09/30] x86/mm: Introduce _PAGE_COW

2021-04-15 Thread Yu-cheng Yu
. Signed-off-by: Yu-cheng Yu Reviewed-by: Kirill A. Shutemov --- v24: - Replace CONFIG_X86_CET with CONFIG_X86_SHADOW_STACK. arch/x86/include/asm/pgtable.h | 195 --- arch/x86/include/asm/pgtable_types.h | 42 +- 2 files changed, 216 insertions(+), 21

[PATCH v25 10/30] drm/i915/gvt: Change _PAGE_DIRTY to _PAGE_DIRTY_BITS

2021-04-15 Thread Yu-cheng Yu
After the introduction of _PAGE_COW, a modified page's PTE can have either _PAGE_DIRTY or _PAGE_COW. Change _PAGE_DIRTY to _PAGE_DIRTY_BITS. Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook Reviewed-by: Kirill A. Shutemov Cc: David Airlie Cc: Joonas Lahtinen Cc: Jani Nikula Cc: Daniel

[PATCH v25 08/30] x86/mm: Move pmd_write(), pud_write() up in the file

2021-04-15 Thread Yu-cheng Yu
To prepare the introduction of _PAGE_COW, move pmd_write() and pud_write() up in the file, so that they can be used by other helpers below. Signed-off-by: Yu-cheng Yu Reviewed-by: Kirill A. Shutemov --- arch/x86/include/asm/pgtable.h | 24 1 file changed, 12 insertions

[PATCH v25 07/30] x86/mm: Remove _PAGE_DIRTY from kernel RO pages

2021-04-15 Thread Yu-cheng Yu
. This results in ambiguity between shadow stack and kernel read-only pages. To resolve this, removed Dirty from kernel read- only pages. Signed-off-by: Yu-cheng Yu Reviewed-by: Kirill A. Shutemov Cc: "H. Peter Anvin" Cc: Kees Cook Cc: Thomas Gleixner Cc: Dave Hansen Cc: Christoph Hellwig

[PATCH v25 06/30] x86/cet: Add control-protection fault handler

2021-04-15 Thread Yu-cheng Yu
, arrives at a non-ENDBR opcode. The control-protection fault handler works in a similar way as the general protection fault handler. It provides the si_code SEGV_CPERR to the signal handler. Signed-off-by: Yu-cheng Yu Cc: Kees Cook Cc: Michael Kerrisk --- v25: - Change CONFIG_X86_CET

[PATCH v25 04/30] x86/cpufeatures: Introduce CPU setup and option parsing for CET

2021-04-15 Thread Yu-cheng Yu
Introduce CPU setup and boot option parsing for CET features. Signed-off-by: Yu-cheng Yu Cc: Kees Cook --- v25: - Remove software-defined X86_FEATURE_CET. v24: - Update #ifdef placement to reflect Kconfig changes of splitting shadow stack and ibt. arch/x86/include/uapi/asm/processor-flags.h

[PATCH v25 00/30] Control-flow Enforcement: Shadow Stack

2021-04-15 Thread Yu-cheng Yu
20236-1-yu-cheng...@intel.com/ [5] The kernel ptrace patch is tested with an Intel-internal updated GDB. I am holding off the kernel ptrace patch to re-test it with my earlier patch for fixing regset holes. Yu-cheng Yu (30): Documentation/x86: Add CET description x86/cet/shstk: A

[PATCH v25 05/30] x86/fpu/xstate: Introduce CET MSR and XSAVES supervisor states

2021-04-15 Thread Yu-cheng Yu
-by: Yu-cheng Yu Cc: Kees Cook --- v25: - Update xsave_cpuid_features[]. Now CET XSAVES features depend on X86_FEATURE_SHSTK (vs. the software-defined X86_FEATURE_CET). arch/x86/include/asm/fpu/types.h | 23 +-- arch/x86/include/asm/fpu/xstate.h | 6 -- arch/x86/include

[PATCH v25 03/30] x86/cpufeatures: Add CET CPU feature flags for Control-flow Enforcement Technology (CET)

2021-04-15 Thread Yu-cheng Yu
Add CPU feature flags for Control-flow Enforcement Technology (CET). CPUID.(EAX=7,ECX=0):ECX[bit 7] Shadow stack CPUID.(EAX=7,ECX=0):EDX[bit 20] Indirect Branch Tracking Signed-off-by: Yu-cheng Yu Cc: Kees Cook --- v25: - Make X86_FEATURE_IBT depend on X86_FEATURE_SHSTK. v24: - Update

[PATCH v25 02/30] x86/cet/shstk: Add Kconfig option for Shadow Stack

2021-04-15 Thread Yu-cheng Yu
-Shadow Stack applications continue to work, but without protection. Signed-off-by: Yu-cheng Yu Cc: Kees Cook --- v25: - Remove X86_CET and use X86_SHADOW_STACK directly. v24: - Update for the splitting X86_CET to X86_SHADOW_STACK and X86_IBT. arch/x86/Kconfig | 22

[PATCH v25 01/30] Documentation/x86: Add CET description

2021-04-15 Thread Yu-cheng Yu
Explain no_user_shstk/no_user_ibt kernel parameters, and introduce a new document on Control-flow Enforcement Technology (CET). Signed-off-by: Yu-cheng Yu Cc: Kees Cook --- v24: - Update for Kconfig changes from X86_CET to X86_SHADOW_STACK, X86_IBT. - Update for the change of VM_SHSTK

[PATCH v24 7/9] x86/vdso: Introduce ENDBR macro

2021-04-01 Thread Yu-cheng Yu
for the proper one. Introduce ENDBR macro, which equals the compiler macro when enabled, otherwise nothing. Signed-off-by: Yu-cheng Yu Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Dave Hansen Cc: Jarkko Sakkinen Cc: Peter Zijlstra --- arch/x86/entry/vdso/Makefile | 1 + arch/x86/include/asm

[PATCH v24 6/9] x86/vdso: Insert endbr32/endbr64 to vDSO

2021-04-01 Thread Yu-cheng Yu
off-by: Yu-cheng Yu Cc: Andy Lutomirski Cc: Kees Cook --- v24: - Replace CONFIG_X86_CET with CONFIG_X86_IBT to reflect splitting of shadow stack and ibt. arch/x86/entry/vdso/Makefile | 4 1 file changed, 4 insertions(+) diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vds

[PATCH v24 9/9] x86/vdso: Add ENDBR to __vdso_sgx_enter_enclave

2021-04-01 Thread Yu-cheng Yu
. ENDBR is a noop when IBT is unsupported or disabled. Most ENDBR instructions are inserted automatically by the compiler, but branch targets written in assembly must have ENDBR added manually. Add ENDBR to __vdso_sgx_enter_enclave() branch targets. Signed-off-by: Yu-cheng Yu Cc: Andy Lutomirski

[PATCH v24 5/9] x86/cet/ibt: Update arch_prctl functions for Indirect Branch Tracking

2021-04-01 Thread Yu-cheng Yu
From: "H.J. Lu" Update ARCH_X86_CET_STATUS and ARCH_X86_CET_DISABLE for Indirect Branch Tracking. Signed-off-by: H.J. Lu Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook --- v24: - Update for function name changes introduced from splitting shadow stack and ibt. arch/

[PATCH v24 4/9] x86/cet/ibt: Update ELF header parsing for Indirect Branch Tracking

2021-04-01 Thread Yu-cheng Yu
An ELF file's .note.gnu.property indicates features the file supports. The property is parsed at loading time and passed to arch_setup_elf_ property(). Update it for Indirect Branch Tracking. Signed-off-by: Yu-cheng Yu Cc: Kees Cook --- v24: - Update for changes introduced from splitting

[PATCH v24 8/9] x86/vdso/32: Add ENDBR to __kernel_vsyscall entry point

2021-04-01 Thread Yu-cheng Yu
off-by: Yu-cheng Yu Cc: Andy Lutomirski Cc: Kees Cook --- arch/x86/entry/vdso/vdso32/system_call.S | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/entry/vdso/vdso32/system_call.S b/arch/x86/entry/vdso/vdso32/system_call.S index de1fff7188aa..c962e7e4f7e3 100644 --- a/arch/x86/entry/v

[PATCH v24 3/9] x86/cet/ibt: Handle signals for Indirect Branch Tracking

2021-04-01 Thread Yu-cheng Yu
machine is described in Intel SDM Vol. 1, Sec. 18.3. Signed-off-by: Yu-cheng Yu Cc: Kees Cook --- v24: - Update for changes from splitting shadow stack and ibt. arch/x86/kernel/fpu/signal.c | 30 +++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/arch/x86

[PATCH v24 1/9] x86/cet/ibt: Add Kconfig option for Indirect Branch Tracking

2021-04-01 Thread Yu-cheng Yu
protection. Signed-off-by: Yu-cheng Yu Cc: Kees Cook --- arch/x86/Kconfig | 20 arch/x86/include/asm/disabled-features.h | 8 +++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index

[PATCH v24 2/9] x86/cet/ibt: Add user-mode Indirect Branch Tracking support

2021-04-01 Thread Yu-cheng Yu
Introduce user-mode Indirect Branch Tracking (IBT) support. Add routines for the setup/disable of IBT. Signed-off-by: Yu-cheng Yu Cc: Kees Cook --- v24: - Move IBT routines to a separate ibt.c, update related areas accordingly. arch/x86/include/asm/cet.h | 9 ++ arch/x86/kernel/Makefile

[PATCH v24 0/9] Control-flow Enforcement: Indirect Branch Tracking

2021-04-01 Thread Yu-cheng Yu
1-yu-cheng...@intel.com/ H.J. Lu (3): x86/cet/ibt: Update arch_prctl functions for Indirect Branch Tracking x86/vdso: Insert endbr32/endbr64 to vDSO x86/vdso/32: Add ENDBR to __kernel_vsyscall entry point Yu-cheng Yu (6): x86/cet/ibt: Add Kconfig option for Indirect Branch Tracking x86/cet/ibt: Add

[PATCH v24 28/30] mm: Move arch_calc_vm_prot_bits() to arch/x86/include/asm/mman.h

2021-04-01 Thread Yu-cheng Yu
To prepare the introduction of PROT_SHSTK and be consistent with other architectures, move arch_vm_get_page_prot() and arch_calc_vm_prot_bits() to arch/x86/include/asm/mman.h. Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook Cc: Kirill A. Shutemov --- arch/x86/include/asm/mman.h | 30

[PATCH v24 30/30] mm: Introduce PROT_SHSTK for shadow stack

2021-04-01 Thread Yu-cheng Yu
would be using this as a bypass to shadow stack protection. However, the attacker would have to get to the syscall first. [1] https://lore.kernel.org/lkml/20200828121624.108243-1-hjl.to...@gmail.com/ Signed-off-by: Yu-cheng Yu Cc: Kees Cook Cc: Kirill A. Shutemov --- v24: - Update

[PATCH v24 29/30] mm: Update arch_validate_flags() to include vma anonymous

2021-04-01 Thread Yu-cheng Yu
("arm64: mte: Add PROT_MTE support to mmap() and mprotect()"), Signed-off-by: Yu-cheng Yu Cc: Catalin Marinas Cc: Kees Cook Cc: Kirill A. Shutemov Cc: Vincenzo Frascino Cc: Will Deacon --- arch/arm64/include/asm/mman.h | 4 ++-- arch/sparc/include/asm/mman.h | 4 ++-- include/li

[PATCH v24 27/30] x86/cet/shstk: Add arch_prctl functions for shadow stack

2021-04-01 Thread Yu-cheng Yu
do_arch_prctl_common()'s parameter 'cpuid_enabled' to 'arg2', as it is now also passed to prctl_cet(). Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook --- v24: - Update #ifdef placement relating to shadow stack and ibt split. - Update function names. arch/x86/include/asm/cet.h| 7

[PATCH v24 26/30] ELF: Introduce arch_setup_elf_property()

2021-04-01 Thread Yu-cheng Yu
of this function is Shadow Stack. ARM64 is the other arch that has ARCH_USE_GNU_PROPERTY and arch_parse_elf_ property(). Add arch_setup_elf_property() for it. Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook Cc: Mark Brown Cc: Catalin Marinas Cc: Dave Martin --- v24: - Change cet_setup_shstk

[PATCH v24 25/30] x86/cet/shstk: Handle signals for shadow stack

2021-04-01 Thread Yu-cheng Yu
(), - restore_extra_state(). [1] WAIT_ENDBR will be introduced later in the Indirect Branch Tracking series, but add that into sc_ext now to keep the struct stable in case the IBT series is applied later. Signed-off-by: Yu-cheng Yu Cc: Kees Cook --- v24: - Split out shadow stack token routines

[PATCH v24 24/30] x86/cet/shstk: Introduce shadow stack token setup/verify routines

2021-04-01 Thread Yu-cheng Yu
setup and verify routines. Also introduce WRUSS, which is a kernel-mode instruction but writes directly to user shadow stack. It is used to construct user signal stack as described above. Signed-off-by: Yu-cheng Yu Cc: Kees Cook --- arch/x86/include/asm/cet.h | 9 ++ arch/x86

[PATCH v24 23/30] x86/cet/shstk: Handle thread shadow stack

2021-04-01 Thread Yu-cheng Yu
). A compat-mode thread shadow stack size is further reduced to 1/4. This allows more threads to run in a 32- bit address space. Signed-off-by: Yu-cheng Yu --- arch/x86/include/asm/cet.h | 5 +++ arch/x86/include/asm/mmu_context.h | 3 ++ arch/x86/kernel/process.c | 15 ++-- arch

[PATCH v24 22/30] x86/cet/shstk: Add user-mode shadow stack support

2021-04-01 Thread Yu-cheng Yu
Introduce basic shadow stack enabling/disabling/allocation routines. A task's shadow stack is allocated from memory with VM_SHADOW_STACK flag and has a fixed size of min(RLIMIT_STACK, 4GB). Signed-off-by: Yu-cheng Yu Cc: Kees Cook --- v24: - Rename cet.c to shstk.c, update related areas

[PATCH v24 21/30] mm: Re-introduce vm_flags to do_mmap()

2021-04-01 Thread Yu-cheng Yu
Thus, re-introduce vm_flags to do_mmap(). Signed-off-by: Yu-cheng Yu Reviewed-by: Peter Collingbourne Reviewed-by: Kees Cook Cc: Andrew Morton Cc: Oleg Nesterov Cc: linux...@kvack.org --- v24: - Change VM_SHSTK to VM_SHADOW_STACK. - Update commit log. fs/aio.c | 2 +- include/linux

[PATCH v24 11/30] x86/mm: Update pte_modify for _PAGE_COW

2021-04-01 Thread Yu-cheng Yu
, and pte_*() are updated. Pte_modify() changes a PTE to 'newprot', but it doesn't use the pte_*(). Introduce fixup_dirty_pte(), which sets a dirty PTE, based on _PAGE_RW, to either _PAGE_DIRTY or _PAGE_COW. Apply the same changes to pmd_modify(). Signed-off-by: Yu-cheng Yu Reviewed-by: Kirill

[PATCH v24 16/30] mm: Fixup places that call pte_mkwrite() directly

2021-04-01 Thread Yu-cheng Yu
flags, and handled accordingly in maybe_mkwrite(). Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook Cc: Kirill A. Shutemov --- mm/memory.c | 5 ++--- mm/migrate.c | 3 +-- mm/mprotect.c | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index

[PATCH v24 20/30] mm/mprotect: Exclude shadow stack from preserve_write

2021-04-01 Thread Yu-cheng Yu
to preserve it. Exclude shadow stack from preserve_write test, and apply the same change to change_huge_pmd(). Signed-off-by: Yu-cheng Yu Cc: Kirill A. Shutemov --- v24: - Change arch_shadow_stack_mapping() to is_shadow_stack_mapping(). mm/huge_memory.c | 7 ++- mm/mprotect.c| 9

[PATCH v24 18/30] mm/mmap: Add shadow stack pages to memory accounting

2021-04-01 Thread Yu-cheng Yu
Account shadow stack pages to stack memory. Signed-off-by: Yu-cheng Yu Cc: Kees Cook Cc: Kirill A. Shutemov --- v24: - Change arch_shadow_stack_mapping() to is_shadow_stack_mapping(). - Change VM_SHSTK to VM_SHADOW_STACK. arch/x86/mm/pgtable.c | 7 +++ include/linux/pgtable.h | 11

[PATCH v24 15/30] x86/mm: Update maybe_mkwrite() for shadow stack

2021-04-01 Thread Yu-cheng Yu
and the shadow stack page is writable again. Introduce an x86 version of maybe_mkwrite(), which sets proper PTE bits according to VM flags. Apply the same changes to maybe_pmd_mkwrite(). Signed-off-by: Yu-cheng Yu Cc: Kees Cook Cc: Kirill A. Shutemov --- v24: - Instead of doing arch_maybe_mkwrite

[PATCH v24 19/30] mm: Update can_follow_write_pte() for shadow stack

2021-04-01 Thread Yu-cheng Yu
, in the can_follow_write_pte() check, it belongs to the writable page case and should be excluded from the read-only page pte_dirty() check. Apply the same changes to can_follow_write_pmd(). Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook Cc: Kirill A. Shutemov --- v24: - Change arch_shadow_stack_mapping

[PATCH v24 17/30] mm: Add guard pages around a shadow stack.

2021-04-01 Thread Yu-cheng Yu
, putting a gap page on both ends of a shadow stack prevents INCSSP, CALL, and RET from going beyond. Signed-off-by: Yu-cheng Yu Cc: Kees Cook Cc: Kirill A. Shutemov --- v24: - Instead changing vm_*_gap(), create x86-specific versions. arch/x86/include/asm/page_types.h | 17 +++ arch

[PATCH v24 12/30] x86/mm: Update ptep_set_wrprotect() and pmdp_set_wrprotect() for transition from _PAGE_DIRTY to _PAGE_COW

2021-04-01 Thread Yu-cheng Yu
non- atomically, a transient shadow stack PTE can be created as a result. Thus, prevent that with cmpxchg. Dave Hansen, Jann Horn, Andy Lutomirski, and Peter Zijlstra provided many insights to the issue. Jann Horn provided the cmpxchg solution. Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook Cc

[PATCH v24 10/30] drm/i915/gvt: Change _PAGE_DIRTY to _PAGE_DIRTY_BITS

2021-04-01 Thread Yu-cheng Yu
After the introduction of _PAGE_COW, a modified page's PTE can have either _PAGE_DIRTY or _PAGE_COW. Change _PAGE_DIRTY to _PAGE_DIRTY_BITS. Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook Reviewed-by: Kirill A. Shutemov Cc: David Airlie Cc: Joonas Lahtinen Cc: Jani Nikula Cc: Daniel

[PATCH v24 13/30] mm: Introduce VM_SHADOW_STACK for shadow stack memory

2021-04-01 Thread Yu-cheng Yu
A shadow stack PTE must be read-only and have _PAGE_DIRTY set. However, read-only and Dirty PTEs also exist for copy-on-write (COW) pages. These two cases are handled differently for page faults. Introduce VM_SHADOW_STACK to track shadow stack VMAs. Signed-off-by: Yu-cheng Yu Cc: Kees Cook

[PATCH v24 08/30] x86/mm: Move pmd_write(), pud_write() up in the file

2021-04-01 Thread Yu-cheng Yu
To prepare the introduction of _PAGE_COW, move pmd_write() and pud_write() up in the file, so that they can be used by other helpers below. Signed-off-by: Yu-cheng Yu Reviewed-by: Kirill A. Shutemov --- arch/x86/include/asm/pgtable.h | 24 1 file changed, 12 insertions

[PATCH v24 09/30] x86/mm: Introduce _PAGE_COW

2021-04-01 Thread Yu-cheng Yu
. Signed-off-by: Yu-cheng Yu Reviewed-by: Kirill A. Shutemov --- v24: - Replace CONFIG_X86_CET with CONFIG_X86_SHADOW_STACK to reflect the Kconfig changes. arch/x86/include/asm/pgtable.h | 195 --- arch/x86/include/asm/pgtable_types.h | 42 +- 2 files

[PATCH v24 07/30] x86/mm: Remove _PAGE_DIRTY from kernel RO pages

2021-04-01 Thread Yu-cheng Yu
. This results in ambiguity between shadow stack and kernel read-only pages. To resolve this, removed Dirty from kernel read- only pages. Signed-off-by: Yu-cheng Yu Reviewed-by: Kirill A. Shutemov Cc: "H. Peter Anvin" Cc: Kees Cook Cc: Thomas Gleixner Cc: Dave Hansen Cc: Christoph Hellwig

[PATCH v24 05/30] x86/fpu/xstate: Introduce CET MSR and XSAVES supervisor states

2021-04-01 Thread Yu-cheng Yu
-by: Yu-cheng Yu Reviewed-by: Kees Cook --- arch/x86/include/asm/fpu/types.h | 23 +-- arch/x86/include/asm/fpu/xstate.h | 6 -- arch/x86/include/asm/msr-index.h | 19 +++ arch/x86/kernel/fpu/xstate.c | 10 +- 4 files changed, 53 insertions(+), 5

[PATCH v24 14/30] x86/mm: Shadow Stack page fault error checking

2021-04-01 Thread Yu-cheng Yu
clearing _PAGE_DIRTY (vs. _PAGE_RW) is used to trigger the fault, shadow stack read fault and shadow stack write fault are not differentiated and both are handled as a write access. Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook Cc: Kirill A. Shutemov --- v24: - Change VM_SHSTK

[PATCH v24 06/30] x86/cet: Add control-protection fault handler

2021-04-01 Thread Yu-cheng Yu
, arrives at a non-ENDBR opcode. The control-protection fault handler works in a similar way as the general protection fault handler. It provides the si_code SEGV_CPERR to the signal handler. Signed-off-by: Yu-cheng Yu Cc: Kees Cook Cc: Michael Kerrisk --- arch/x86/include/asm/idtentry.h| 4

[PATCH v24 03/30] x86/cpufeatures: Add CET CPU feature flags for Control-flow Enforcement Technology (CET)

2021-04-01 Thread Yu-cheng Yu
Add CPU feature flags for Control-flow Enforcement Technology (CET). CPUID.(EAX=7,ECX=0):ECX[bit 7] Shadow stack CPUID.(EAX=7,ECX=0):EDX[bit 20] Indirect Branch Tracking Signed-off-by: Yu-cheng Yu Cc: Kees Cook --- v24: - Update for splitting CONFIG_X86_CET to CONFIG_X86_SHADOW_STACK

[PATCH v24 02/30] x86/cet/shstk: Add Kconfig option for Shadow Stack

2021-04-01 Thread Yu-cheng Yu
-Shadow Stack applications continue to work, but without protection. Signed-off-by: Yu-cheng Yu Cc: Kees Cook --- v24: - Update for the splitting X86_CET to X86_SHADOW_STACK and X86_IBT. arch/x86/Kconfig | 26 ++ arch/x86/Kconfig.assembler | 5 + 2 files

[PATCH v24 04/30] x86/cpufeatures: Introduce X86_FEATURE_CET and setup functions

2021-04-01 Thread Yu-cheng Yu
Introduce a software-defined X86_FEATURE_CET, which indicates either Shadow Stack or Indirect Branch Tracking (or both) is present. Also introduce related cpu init/setup functions. Signed-off-by: Yu-cheng Yu Cc: Kees Cook --- v24: - Update #ifdef placement to reflect Kconfig changes

[PATCH v24 01/30] Documentation/x86: Add CET description

2021-04-01 Thread Yu-cheng Yu
Explain no_user_shstk/no_user_ibt kernel parameters, and introduce a new document on Control-flow Enforcement Technology (CET). Signed-off-by: Yu-cheng Yu Cc: Kees Cook --- v24: - Update for Kconfig changes from X86_CET to X86_SHADOW_STACK, X86_IBT. - Update for the change of VM_SHSTK

[PATCH v24 00/30] Control-flow Enforcement: Shadow Stack

2021-04-01 Thread Yu-cheng Yu
ing regset holes. Yu-cheng Yu (30): Documentation/x86: Add CET description x86/cet/shstk: Add Kconfig option for Shadow Stack x86/cpufeatures: Add CET CPU feature flags for Control-flow Enforcement Technology (CET) x86/cpufeatures: Introduce X86_FEATURE_CET and setup functions x86/

[PATCH v23 9/9] x86/vdso: Add ENDBR to __vdso_sgx_enter_enclave

2021-03-16 Thread Yu-cheng Yu
. ENDBR is a noop when IBT is unsupported or disabled. Most ENDBR instructions are inserted automatically by the compiler, but branch targets written in assembly must have ENDBR added manually. Add ENDBR to __vdso_sgx_enter_enclave() branch targets. Signed-off-by: Yu-cheng Yu Cc: Andy Lutomirski

[PATCH v23 8/9] x86/vdso: Insert endbr32/endbr64 to vDSO

2021-03-16 Thread Yu-cheng Yu
off-by: Yu-cheng Yu Acked-by: Andy Lutomirski Reviewed-by: Kees Cook --- arch/x86/entry/vdso/Makefile | 4 1 file changed, 4 insertions(+) diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile index 05c4abc2fdfd..c9eccbc06e8c 100644 --- a/arch/x86/entry/vdso/Makefile

[PATCH v23 7/9] x86/vdso/32: Add ENDBR to __kernel_vsyscall entry point

2021-03-16 Thread Yu-cheng Yu
off-by: Yu-cheng Yu Cc: Andy Lutomirski Cc: Kees Cook --- arch/x86/entry/vdso/vdso32/system_call.S | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/entry/vdso/vdso32/system_call.S b/arch/x86/entry/vdso/vdso32/system_call.S index de1fff7188aa..adbe948c1a81 100644 --- a/arch/x86/entry/v

[PATCH v23 6/9] x86/entry: Introduce ENDBR macro

2021-03-16 Thread Yu-cheng Yu
at call sites. Signed-off-by: Yu-cheng Yu Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Dave Hansen Cc: Jarkko Sakkinen Cc: Peter Zijlstra --- arch/x86/entry/calling.h | 18 ++ 1 file changed, 18 insertions(+) diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h

[PATCH v23 3/9] x86/cet/ibt: Handle signals for Indirect Branch Tracking

2021-03-16 Thread Yu-cheng Yu
machine is described in Intel SDM Vol. 1, Sec. 18.3. Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook --- arch/x86/kernel/cet.c| 26 -- arch/x86/kernel/fpu/signal.c | 8 +--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/cet.c

[PATCH v23 5/9] x86/cet/ibt: Update arch_prctl functions for Indirect Branch Tracking

2021-03-16 Thread Yu-cheng Yu
From: "H.J. Lu" Update ARCH_X86_CET_STATUS and ARCH_X86_CET_DISABLE for Indirect Branch Tracking. Signed-off-by: H.J. Lu Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook --- arch/x86/kernel/cet_prctl.c | 5 + 1 file changed, 5 insertions(+) diff --git a/arch/x86/kernel/cet

[PATCH v23 0/9] Control-flow Enforcement: Indirect Branch Tracking

2021-03-16 Thread Yu-cheng Yu
bt: Update arch_prctl functions for Indirect Branch Tracking x86/vdso/32: Add ENDBR to __kernel_vsyscall entry point x86/vdso: Insert endbr32/endbr64 to vDSO Yu-cheng Yu (6): x86/cet/ibt: Update Kconfig for user-mode Indirect Branch Tracking x86/cet/ibt: User-mode Indirect Branch Tracki

[PATCH v23 2/9] x86/cet/ibt: User-mode Indirect Branch Tracking support

2021-03-16 Thread Yu-cheng Yu
Introduce user-mode Indirect Branch Tracking (IBT) support. Add routines for the setup/disable of IBT. Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook --- arch/x86/include/asm/cet.h | 3 +++ arch/x86/kernel/cet.c | 33 + 2 files changed, 36 insertions

[PATCH v23 4/9] x86/cet/ibt: Update ELF header parsing for Indirect Branch Tracking

2021-03-16 Thread Yu-cheng Yu
An ELF file's .note.gnu.property indicates features the file supports. The property is parsed at loading time and passed to arch_setup_elf_ property(). Update it for Indirect Branch Tracking. Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook --- arch/x86/kernel/process_64.c | 8 1

[PATCH v23 1/9] x86/cet/ibt: Update Kconfig for user-mode Indirect Branch Tracking

2021-03-16 Thread Yu-cheng Yu
the compiler is up-to-date at config time. Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook --- arch/x86/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 2c93178262f5..96000ed48469 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1953,6

[PATCH v23 28/28] mm: Introduce PROT_SHSTK for shadow stack

2021-03-16 Thread Yu-cheng Yu
be using this as a bypass to shadow stack protection. However, the attacker would have to get to the syscall first. [1] https://lore.kernel.org/lkml/20200828121624.108243-1-hjl.to...@gmail.com/ Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook --- arch/x86/include/asm/mman.h | 57

[PATCH v23 26/28] x86/cet/shstk: Add arch_prctl functions for shadow stack

2021-03-16 Thread Yu-cheng Yu
do_arch_prctl_common()'s parameter 'cpuid_enabled' to 'arg2', as it is now also passed to prctl_cet(). Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook --- arch/x86/include/asm/cet.h| 3 ++ arch/x86/include/uapi/asm/prctl.h | 4 +++ arch/x86/kernel/Makefile | 2 +- arch/x86

[PATCH v23 13/28] mm: Introduce VM_SHSTK for shadow stack memory

2021-03-16 Thread Yu-cheng Yu
A shadow stack PTE must be read-only and have _PAGE_DIRTY set. However, read-only and Dirty PTEs also exist for copy-on-write (COW) pages. These two cases are handled differently for page faults. Introduce VM_SHSTK to track shadow stack VMAs. Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook

[PATCH v23 27/28] mm: Move arch_calc_vm_prot_bits() to arch/x86/include/asm/mman.h

2021-03-16 Thread Yu-cheng Yu
To prepare changes to arch_calc_vm_prot_bits() in the next patch, and be consistent with other architectures, move arch_vm_get_page_prot() and arch_calc_vm_prot_bits() to arch/x86/include/asm/mman.h. Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook --- arch/x86/include/asm/mman.h | 30

[PATCH v23 25/28] x86/cet/shstk: Handle thread shadow stack

2021-03-16 Thread Yu-cheng Yu
). A compat-mode thread shadow stack size is further reduced to 1/4. This allows more threads to run in a 32- bit address space. Signed-off-by: Yu-cheng Yu --- arch/x86/include/asm/cet.h | 5 +++ arch/x86/include/asm/mmu_context.h | 3 ++ arch/x86/kernel/cet.c | 49

[PATCH v23 24/28] ELF: Introduce arch_setup_elf_property()

2021-03-16 Thread Yu-cheng Yu
of this function is Shadow Stack. ARM64 is the other arch that has ARCH_USE_GNU_PROPERTY and arch_parse_elf_ property(). Add arch_setup_elf_property() for it. Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook Cc: Mark Brown Cc: Catalin Marinas Cc: Dave Martin --- arch/arm64/include/asm/elf.h | 5

[PATCH v23 18/28] mm/mmap: Add shadow stack pages to memory accounting

2021-03-16 Thread Yu-cheng Yu
Account shadow stack pages to stack memory. Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook --- arch/x86/mm/pgtable.c | 7 +++ include/linux/pgtable.h | 11 +++ mm/mmap.c | 5 + 3 files changed, 23 insertions(+) diff --git a/arch/x86/mm/pgtable.c b/arch/x86

[PATCH v23 22/28] x86/cet/shstk: User-mode shadow stack support

2021-03-16 Thread Yu-cheng Yu
Introduce basic shadow stack enabling/disabling/allocation routines. A task's shadow stack is allocated from memory with VM_SHSTK flag and has a fixed size of min(RLIMIT_STACK, 4GB). Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook --- arch/x86/include/asm/cet.h | 28 ++ arch/x86

  1   2   3   4   5   6   7   8   9   10   >