Re: um: PTRACE_SETREGSET failure with XSTATE on Kabylake CPU

2017-06-20 Thread Yu-cheng Yu
fpu_user_xstate_size" was introduced by commit: > > > > commit 91c3dba7dbc199191272f4a9863f86ea3bfd679f > > Author: Yu-cheng Yu > > Date: Fri Jun 17 13:07:17 2016 -0700 > > > > x86/fpu/xstate: Fix PTRACE frames for XSAVES > > > > XSAVES us

Re: um: PTRACE_SETREGSET failure with XSTATE on Kabylake CPU

2017-06-20 Thread Yu-cheng Yu
On Tue, 2017-06-20 at 20:59 +0200, Richard Weinberger wrote: > Yu-cheng, > > Am 20.06.2017 um 20:17 schrieb Richard Weinberger: > > Yu-cheng, > > > > Am 20.06.2017 um 20:04 schrieb Yu-cheng Yu: > >>>> So to summarize: > >>>> > >&g

[RFC PATCH v3 08/24] mm: Introduce VM_SHSTK for shadow stack memory

2018-08-30 Thread Yu-cheng Yu
VM_SHSTK indicates a shadow stack memory area. The shadow stack is implemented only for the 64-bit kernel. Signed-off-by: Yu-cheng Yu --- include/linux/mm.h | 8 mm/internal.h | 8 2 files changed, 16 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h

[RFC PATCH v3 18/24] x86/cet/shstk: User-mode shadow stack support

2018-08-30 Thread Yu-cheng Yu
This patch adds basic shadow stack enabling/disabling routines. A task's shadow stack is allocated from memory with VM_SHSTK flag set and read-only protection. The shadow stack is allocated to a fixed size of RLIMIT_STACK. Signed-off-by: Yu-cheng Yu --- arch/x86/include/asm/

Re: [RFC PATCH v2 05/27] Documentation/x86: Add CET description

2018-07-11 Thread Yu-cheng Yu
On Wed, 2018-07-11 at 06:47 -0700, H.J. Lu wrote: > On Wed, Jul 11, 2018 at 2:57 AM, Florian Weimer > wrote: > > > > On 07/11/2018 12:26 AM, Yu-cheng Yu wrote: > > > > > > > > +To build a CET-enabled kernel, Binutils v2.30 and GCC v8.1 or > &

Re: [RFC PATCH v2 18/27] x86/cet/shstk: Introduce WRUSS instruction

2018-07-11 Thread Yu-cheng Yu
On Wed, 2018-07-11 at 11:45 +0200, Peter Zijlstra wrote: > On Tue, Jul 10, 2018 at 03:26:30PM -0700, Yu-cheng Yu wrote: > > > > diff --git a/arch/x86/lib/x86-opcode-map.txt b/arch/x86/lib/x86- > > opcode-map.txt > > index e0b85930dd77..72bb7c48a7df 100644 > > ---

Re: [RFC PATCH v2 18/27] x86/cet/shstk: Introduce WRUSS instruction

2018-07-11 Thread Yu-cheng Yu
On Wed, 2018-07-11 at 17:27 +0200, Peter Zijlstra wrote: > On Wed, Jul 11, 2018 at 07:58:09AM -0700, Yu-cheng Yu wrote: > > > > On Wed, 2018-07-11 at 11:45 +0200, Peter Zijlstra wrote: > > > > > > On Tue, Jul 10, 2018 at 03:26:30PM -0700, Yu-cheng Yu wrote: >

Re: [RFC PATCH v2 17/27] x86/cet/shstk: User-mode shadow stack support

2018-07-11 Thread Yu-cheng Yu
On Wed, 2018-07-11 at 11:34 +0200, Peter Zijlstra wrote: > On Tue, Jul 10, 2018 at 03:26:29PM -0700, Yu-cheng Yu wrote: > > > > +/* MSR_IA32_U_CET and MSR_IA32_S_CET bits */ > > +#define MSR_IA32_CET_SHSTK_EN 0x0001 > > +#

[PATCH] x86/ptrace: Add comments to x86_regset about empty slots

2018-07-13 Thread Yu-cheng Yu
find_regset() goes through regsets sequentially. Empty slots in regset arrays causes mismatch. Add comments to x86_regset enum. Signed-off-by: Yu-cheng Yu --- arch/x86/kernel/ptrace.c | 5 + 1 file changed, 5 insertions(+) diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c

[RFC PATCH v6 08/11] x86: Insert endbr32/endbr64 to vDSO

2018-11-19 Thread Yu-cheng Yu
From: "H.J. Lu" When Intel indirect branch tracking is enabled, functions in vDSO which may be called indirectly must have endbr32 or endbr64 as the first instruction. Compiler must support -fcf-protection=branch so that it can be used to compile vDSO. Signed-off-by: H.J. Lu --- arch/x86/entr

[RFC PATCH v6 06/11] x86/cet/ibt: Add arch_prctl functions for IBT

2018-11-19 Thread Yu-cheng Yu
uffer that has: *addr = IBT bitmap base address *(addr + 1) = IBT bitmap size Signed-off-by: H.J. Lu Signed-off-by: Yu-cheng Yu --- arch/x86/include/uapi/asm/prctl.h | 2 ++ arch/x86/kernel/cet_prctl.c | 21 + 2 files changed, 23 insertions(+) diff --git

[RFC PATCH v6 10/11] x86/vsyscall/64: Add ENDBR64 to vsyscall entry points

2018-11-19 Thread Yu-cheng Yu
From: "H.J. Lu" Add ENDBR64 to vsyscall entry points. Signed-off-by: H.J. Lu --- arch/x86/entry/vsyscall/vsyscall_emu_64.S | 9 + 1 file changed, 9 insertions(+) diff --git a/arch/x86/entry/vsyscall/vsyscall_emu_64.S b/arch/x86/entry/vsyscall/vsyscall_emu_64.S index c9596a9af159..085

[RFC PATCH v6 00/11] Control-flow Enforcement: Branch Tracking, PTRACE

2018-11-19 Thread Yu-cheng Yu
. H.J. Lu (3): x86: Insert endbr32/endbr64 to vDSO x86/vsyscall/32: Add ENDBR32 to vsyscall entry point x86/vsyscall/64: Add ENDBR64 to vsyscall entry points Yu-cheng Yu (8): x86/cet/ibt: Add Kconfig option for user-mode Indirect Branch Tracking x86/cet/ibt: User-mode indirect branch tracking

[RFC PATCH v6 05/11] x86/cet/ibt: ELF header parsing for IBT

2018-11-19 Thread Yu-cheng Yu
Look in .note.gnu.property of an ELF file and check if Indirect Branch Tracking needs to be enabled for the task. Signed-off-by: H.J. Lu Signed-off-by: Yu-cheng Yu --- arch/x86/include/uapi/asm/elf_property.h | 1 + arch/x86/kernel/elf.c| 5 + 2 files changed, 6

Re: [RFC PATCH v6 08/11] x86: Insert endbr32/endbr64 to vDSO

2018-11-19 Thread Yu-cheng Yu
On Mon, 2018-11-19 at 14:17 -0800, Andy Lutomirski wrote: > On Mon, Nov 19, 2018 at 1:55 PM Yu-cheng Yu wrote: > > > > From: "H.J. Lu" > > > > When Intel indirect branch tracking is enabled, functions in vDSO which > > may be called indirectl

[PATCH] binfmt_elf: Fix core dump memory corruption

2018-07-17 Thread Yu-cheng Yu
In fill_note_info(), we kzalloc elf_thread_core_info.notes[] only for (core_note_type != 0) regsets. However, in fill_thread_core_info(), we still leave empty notes and go beyond the allocated size. Fix it. Signed-off-by: Yu-cheng Yu --- fs/binfmt_elf.c | 14 -- 1 file changed, 8

[PATCH] x86/selftests/xsave: Introduce XSAVE tests

2019-02-27 Thread Yu-cheng Yu
In the past there were some issues resulting from additions to XSAVE/XSAVES. Introduce a few tests to help detect issues early. Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Dave Hansen Cc: Ingo Molnar Cc: Shuah Khan Signed-off-by: Yu-cheng Yu --- tools/testing/selftests/x86/Makefile

Re: [PATCH] x86/selftests/xsave: Introduce XSAVE tests

2019-02-27 Thread Yu-cheng Yu
On Wed, 2019-02-27 at 13:45 -0800, Dave Hansen wrote: > I wonder, though, if you can spend a little more time on these. They > look a little "raw". They're virtually free of comments and there is no > explanation of what the tests do or why they do them. I honestly forget > things like what XSAV

[PATCH v20 01/25] Documentation/x86: Add CET description

2021-02-10 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 Reviewed-by: Kees Cook --- .../admin-guide/kernel-parameters.txt | 6 + Documentation/x86/index.rst | 1

[PATCH v20 09/25] drm/i915/gvt: Change _PAGE_DIRTY to _PAGE_DIRTY_BITS

2021-02-10 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 Cc: David Airlie Cc: Joonas Lahtinen Cc: Jani Nikula Cc: Daniel Vetter Cc: Rodrigo Vivi Cc: Z

[PATCH v20 08/25] x86/mm: Introduce _PAGE_COW

2021-02-10 Thread Yu-cheng Yu
ted for the 32-bit kernel. Signed-off-by: Yu-cheng Yu --- arch/x86/include/asm/pgtable.h | 136 --- arch/x86/include/asm/pgtable_types.h | 42 - 2 files changed, 165 insertions(+), 13 deletions(-) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/in

[PATCH v20 10/25] x86/mm: Update pte_modify for _PAGE_COW

2021-02-10 Thread Yu-cheng Yu
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 Reviewe

[PATCH v20 07/25] x86/mm: Remove _PAGE_DIRTY from kernel RO pages

2021-02-10 Thread Yu-cheng Yu
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 Cc: "H. Peter Anvin" Cc: Kees Cook Cc: Thomas Gleixner Cc: Dave Hansen Cc: Christoph Hellwig Cc: Andy Lutomirski Cc: Ingo

[PATCH v20 00/25] Control-flow Enforcement: Shadow Stack

2021-02-10 Thread Yu-cheng Yu
https://lkml.kernel.org/r/20200521211720.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 (25): Documentation/x86: Add CET descrip

[PATCH v20 02/25] x86/cet/shstk: Add Kconfig option for user-mode control-flow protection

2021-02-10 Thread Yu-cheng Yu
Stack applications continue to work, but without protection. Signed-off-by: Yu-cheng Yu --- arch/x86/Kconfig | 23 +++ arch/x86/Kconfig.assembler | 5 + 2 files changed, 28 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 21f851179ff0

[PATCH v20 12/25] mm: Introduce VM_SHSTK for shadow stack memory

2021-02-10 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 v20 13/25] x86/mm: Shadow Stack page fault error checking

2021-02-10 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 --- arch/x86/include/asm/trap_pf.h | 2 ++ arch/x86/mm/fault.c

[PATCH v20 04/25] x86/cpufeatures: Introduce X86_FEATURE_CET and setup functions

2021-02-10 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 Reviewed-by: Kees Cook --- arch/x86/include/asm/cpufeatures.h | 2 +- arch

[PATCH v20 11/25] x86/mm: Update ptep_set_wrprotect() and pmdp_set_wrprotect() for transition from _PAGE_DIRTY to _PAGE_COW

2021-02-10 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 --- arch/x86/include/asm

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

2021-02-10 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 Reviewed-by: Kees Cook --- arch/x86/include/asm/cpufeatures.h | 2 ++ arch/x86/include

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

2021-02-10 Thread Yu-cheng Yu
: 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 v20 15/25] mm: Fixup places that call pte_mkwrite() directly

2021-02-10 Thread Yu-cheng Yu
different vma flags, and handled accordingly in maybe_mkwrite(). Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook --- 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 fe

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

2021-02-10 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 v20 2/7] x86/cet/ibt: User-mode Indirect Branch Tracking support

2021-02-10 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 v20 0/7] Control-flow Enforcement: Indirect Branch Tracking

2021-02-10 Thread Yu-cheng Yu
t x86/vdso: Insert endbr32/endbr64 to vDSO Yu-cheng Yu (4): x86/cet/ibt: Update Kconfig for user-mode Indirect Branch Tracking x86/cet/ibt: User-mode Indirect Branch Tracking support x86/cet/ibt: Handle signals for Indirect Branch Tracking x86/cet/ibt: Update ELF header parsing for Indirect Br

[PATCH v20 06/25] x86/cet: Add control-protection fault handler

2021-02-10 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: Michael Kerrisk --- arch/x86/include/asm/idtentry.h| 4 ++ arch/x86

[PATCH v20 16/25] mm: Add guard pages around a shadow stack.

2021-02-10 Thread Yu-cheng Yu
SIZE. Thus, 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: Kees Cook --- arch/x86/include/asm/page_64_types.h | 10 ++ include/linux/mm.h | 24 2 files c

[PATCH v20 14/25] x86/mm: Update maybe_mkwrite() for shadow stack

2021-02-10 Thread Yu-cheng Yu
page is writable again. Update maybe_mkwrite() by introducing arch_maybe_mkwrite(), which sets _PAGE_DIRTY for a shadow stack PTE. Apply the same changes to maybe_pmd_mkwrite(). Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook --- arch/x86/Kconfig| 4 arch/x86/mm/pgtable.c | 18

[PATCH v20 20/25] x86/cet/shstk: User-mode shadow stack support

2021-02-10 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 ++ arc

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

2021-02-10 Thread Yu-cheng Yu
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 816830e3f062..f462ef9d3305 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1964,6

[PATCH v20 3/7] x86/cet/ibt: Handle signals for Indirect Branch Tracking

2021-02-10 Thread Yu-cheng Yu
urn. IBT state 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/x

[PATCH v20 7/7] x86/vdso: Insert endbr32/endbr64 to vDSO

2021-02-10 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 02e3e42f380b..ff7b56feb5c3 100644 --- a/arch/x86/entry/vdso/Makefile

[PATCH v20 19/25] mm: Re-introduce vm_flags to do_mmap()

2021-02-10 Thread Yu-cheng Yu
. Re-introduce vm_flags to do_mmap(), but without the old wrapper do_mmap_pgoff(). Instead, make all callers of the wrapper pass a zero 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...@kv

[PATCH v20 17/25] mm/mmap: Add shadow stack pages to memory accounting

2021-02-10 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 v20 4/7] x86/cet/ibt: Update ELF header parsing for Indirect Branch Tracking

2021-02-10 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 ++

[PATCH v20 6/7] x86/vdso/32: Add ENDBR32 to __kernel_vsyscall entry point

2021-02-10 Thread Yu-cheng Yu
From: "H.J. Lu" Add ENDBR32 to __kernel_vsyscall entry point. Signed-off-by: H.J. Lu Signed-off-by: Yu-cheng Yu Acked-by: Andy Lutomirski Reviewed-by: Kees Cook --- arch/x86/entry/vdso/vdso32/system_call.S | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/entry/v

[PATCH v20 22/25] ELF: Introduce arch_setup_elf_property()

2021-02-10 Thread Yu-cheng Yu
se-case 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

[PATCH v20 23/25] x86/cet/shstk: Handle thread shadow stack

2021-02-10 Thread Yu-cheng Yu
4 min(RLIMIT_STACK, 4 GB). This allows more threads to run in a 32-bit address space. Signed-off-by: Yu-cheng Yu --- arch/x86/include/asm/cet.h | 3 ++ arch/x86/include/asm/mmu_context.h | 3 ++ arch/x86/kernel/cet.c | 44 ++ arch/x86/kernel/proc

[PATCH v20 18/25] mm: Update can_follow_write_pte() for shadow stack

2021-02-10 Thread Yu-cheng Yu
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 --- mm/gup.c | 8 +--- mm/huge_memory.c | 8 +--- 2

[PATCH v20 24/25] x86/cet/shstk: Add arch_prctl functions for shadow stack

2021-02-10 Thread Yu-cheng Yu
atures. Also change 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/x

[PATCH v20 21/25] x86/cet/shstk: Handle signals for shadow stack

2021-02-10 Thread Yu-cheng Yu
cking (IBT) 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 --- arch/x86/ia32/ia32_signal.c| 17 +++ arch/x86/include/asm/cet.h | 8 ++ arch/x86/include/asm/fpu/internal.h| 10 ++ arch/x

[PATCH v20 25/25] mm: Introduce PROT_SHSTK for shadow stack

2021-02-10 Thread Yu-cheng Yu
architectures. [1] https://lore.kernel.org/lkml/20200828121624.108243-1-hjl.to...@gmail.com/ Signed-off-by: Yu-cheng Yu --- arch/x86/include/asm/mman.h | 85 arch/x86/include/uapi/asm/mman.h | 28 ++- include/linux/mm.h | 1 + mm/mmap.c

[PATCH v21 01/26] Documentation/x86: Add CET description

2021-02-17 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 Reviewed-by: Kees Cook --- .../admin-guide/kernel-parameters.txt | 6 + Documentation/x86/index.rst | 1

[PATCH v21 00/26] Control-flow Enforcement: Shadow Stack

2021-02-17 Thread Yu-cheng Yu
rsion of the selftests patches: https://lkml.kernel.org/r/20200521211720.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-

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

2021-02-17 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 Reviewed-by: Kees Cook --- arch/x86/include/asm/cpufeatures.h | 2 ++ arch/x86/include

[PATCH v21 02/26] x86/cet/shstk: Add Kconfig option for user-mode control-flow protection

2021-02-17 Thread Yu-cheng Yu
Stack applications continue to work, but without protection. Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook --- arch/x86/Kconfig | 22 ++ arch/x86/Kconfig.assembler | 5 + 2 files changed, 27 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index

[PATCH v21 04/26] x86/cpufeatures: Introduce X86_FEATURE_CET and setup functions

2021-02-17 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 Reviewed-by: Kees Cook --- arch/x86/include/asm/cpufeatures.h | 2 +- arch

[PATCH v21 06/26] x86/cet: Add control-protection fault handler

2021-02-17 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 Reviewed-by: Kees Cook Cc: Michael Kerrisk --- arch/x86/include/asm

[PATCH v21 08/26] x86/mm: Introduce _PAGE_COW

2021-02-17 Thread Yu-cheng Yu
ted for the 32-bit kernel. Signed-off-by: Yu-cheng Yu --- arch/x86/include/asm/pgtable.h | 185 --- arch/x86/include/asm/pgtable_types.h | 42 +- 2 files changed, 206 insertions(+), 21 deletions(-) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/in

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

2021-02-17 Thread Yu-cheng Yu
: 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 v21 09/26] drm/i915/gvt: Change _PAGE_DIRTY to _PAGE_DIRTY_BITS

2021-02-17 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 Cc: David Airlie Cc: Joonas Lahtinen Cc: Jani Nikula Cc: Daniel Vetter Cc: Rodrigo Vivi Cc: Z

[PATCH v21 11/26] x86/mm: Update ptep_set_wrprotect() and pmdp_set_wrprotect() for transition from _PAGE_DIRTY to _PAGE_COW

2021-02-17 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 v21 07/26] x86/mm: Remove _PAGE_DIRTY from kernel RO pages

2021-02-17 Thread Yu-cheng Yu
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 Cc: "H. Peter Anvin" Cc: Kees Cook Cc: Thomas Gleixner Cc: Dave Hansen Cc: Christoph Hellwig Cc: Andy Lutomirski Cc: Ingo

[PATCH v21 15/26] mm: Fixup places that call pte_mkwrite() directly

2021-02-17 Thread Yu-cheng Yu
different vma flags, and handled accordingly in maybe_mkwrite(). Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook --- 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 fe

[PATCH v21 10/26] x86/mm: Update pte_modify for _PAGE_COW

2021-02-17 Thread Yu-cheng Yu
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 Reviewe

[PATCH v21 14/26] x86/mm: Update maybe_mkwrite() for shadow stack

2021-02-17 Thread Yu-cheng Yu
page is writable again. Update maybe_mkwrite() by introducing arch_maybe_mkwrite(), which sets _PAGE_DIRTY for a shadow stack PTE. Apply the same changes to maybe_pmd_mkwrite(). Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook --- arch/x86/Kconfig| 4 arch/x86/mm/pgtable.c | 18

[PATCH v21 16/26] mm: Add guard pages around a shadow stack.

2021-02-17 Thread Yu-cheng Yu
SIZE. Thus, 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: Kees Cook --- arch/x86/include/asm/page_64_types.h | 10 ++ include/linux/mm.h | 24 2 files c

[PATCH v21 21/26] x86/cet/shstk: Handle signals for shadow stack

2021-02-17 Thread Yu-cheng Yu
c_ext', which is used to save shadow stack restore token address and WAIT_ENDBR status. WAIT_ENDBR will be introduced later in the Indirect Branch Tracking (IBT) 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 R

[PATCH v21 17/26] mm/mmap: Add shadow stack pages to memory accounting

2021-02-17 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 v21 20/26] x86/cet/shstk: User-mode shadow stack support

2021-02-17 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 ++ arc

[PATCH v21 13/26] x86/mm: Shadow Stack page fault error checking

2021-02-17 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 --- arch/x86/include/asm/trap_pf.h | 2 ++ arch/x86/mm/fault.c

[PATCH v21 12/26] mm: Introduce VM_SHSTK for shadow stack memory

2021-02-17 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 v21 19/26] mm: Re-introduce vm_flags to do_mmap()

2021-02-17 Thread Yu-cheng Yu
. Re-introduce vm_flags to do_mmap(), but without the old wrapper do_mmap_pgoff(). Instead, make all callers of the wrapper pass a zero 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...@kv

[PATCH v21 18/26] mm: Update can_follow_write_pte() for shadow stack

2021-02-17 Thread Yu-cheng Yu
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 --- mm/gup.c | 8 +--- mm/huge_memory.c | 8 +--- 2

[PATCH v21 22/26] ELF: Introduce arch_setup_elf_property()

2021-02-17 Thread Yu-cheng Yu
se-case 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

[PATCH v21 0/7] Control-flow Enforcement: Indirect Branch Tracking

2021-02-17 Thread Yu-cheng Yu
[2] Indirect Branch Tracking patches v20: https://lkml.kernel.org/r/20210210180245.13770-1-yu-cheng...@intel.com/ H.J. Lu (3): x86/cet/ibt: Update arch_prctl functions for Indirect Branch Tracking x86/vdso/32: Add ENDBR32 to __kernel_vsyscall entry point x86/vdso: Insert endbr32/endbr64

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

2021-02-17 Thread Yu-cheng Yu
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 cafa4a2c1d2d..5e157031bf82 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1963,6

[PATCH v21 24/26] x86/cet/shstk: Add arch_prctl functions for shadow stack

2021-02-17 Thread Yu-cheng Yu
atures. Also change 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/x

[PATCH v21 25/26] mm: Move arch_calc_vm_prot_bits() to arch/x86/include/asm/mman.h

2021-02-17 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 v21 2/7] x86/cet/ibt: User-mode Indirect Branch Tracking support

2021-02-17 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 v21 26/26] mm: Introduce PROT_SHSTK for shadow stack

2021-02-17 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 v21 4/7] x86/cet/ibt: Update ELF header parsing for Indirect Branch Tracking

2021-02-17 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 ++

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

2021-02-17 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 v21 3/7] x86/cet/ibt: Handle signals for Indirect Branch Tracking

2021-02-17 Thread Yu-cheng Yu
urn. IBT state 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/x

[PATCH v21 23/26] x86/cet/shstk: Handle thread shadow stack

2021-02-17 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

[PATCH v21 7/7] x86/vdso: Insert endbr32/endbr64 to vDSO

2021-02-17 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 02e3e42f380b..ff7b56feb5c3 100644 --- a/arch/x86/entry/vdso/Makefile

[PATCH v21 6/7] x86/vdso/32: Add ENDBR32 to __kernel_vsyscall entry point

2021-02-17 Thread Yu-cheng Yu
From: "H.J. Lu" Add ENDBR32 to __kernel_vsyscall entry point. Signed-off-by: H.J. Lu Signed-off-by: Yu-cheng Yu Acked-by: Andy Lutomirski Reviewed-by: Kees Cook --- arch/x86/entry/vdso/vdso32/system_call.S | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/entry/v

[PATCH v19 04/25] x86/cpufeatures: Introduce X86_FEATURE_CET and setup functions

2021-02-03 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 --- arch/x86/include/asm/cpufeatures.h | 2 +- arch/x86/include/asm/disabled

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

2021-02-03 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 --- arch/x86/include/asm/cpufeatures.h | 2 ++ arch/x86/include/asm/disabled-features.h

[PATCH v19 06/25] x86/cet: Add control-protection fault handler

2021-02-03 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: Michael Kerrisk --- arch/x86/include/asm/idtentry.h| 4 ++ arch/x86

[PATCH v19 07/25] x86/mm: Remove _PAGE_DIRTY from kernel RO pages

2021-02-03 Thread Yu-cheng Yu
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 Cc: "H. Peter Anvin" Cc: Kees Cook Cc: Thomas Gleixner Cc: Dave Hansen Cc: Christoph Hellwig Cc: Andy Lutomirski Cc: Ingo

[PATCH v19 00/25] Control-flow Enforcement: Shadow Stack

2021-02-03 Thread Yu-cheng Yu
https://lkml.kernel.org/r/20200521211720.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 (25): Documentation/x86: Add

[PATCH v19 02/25] x86/cet/shstk: Add Kconfig option for user-mode control-flow protection

2021-02-03 Thread Yu-cheng Yu
Stack applications continue to work, but without protection. Signed-off-by: Yu-cheng Yu --- arch/x86/Kconfig | 22 ++ arch/x86/Kconfig.assembler | 5 + 2 files changed, 27 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 21f851179ff0

[PATCH v19 08/25] x86/mm: Introduce _PAGE_COW

2021-02-03 Thread Yu-cheng Yu
ted for the 32-bit kernel. Signed-off-by: Yu-cheng Yu --- arch/x86/include/asm/pgtable.h | 125 --- arch/x86/include/asm/pgtable_types.h | 42 - 2 files changed, 154 insertions(+), 13 deletions(-) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/in

[PATCH v19 13/25] x86/mm: Shadow Stack page fault error checking

2021-02-03 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 --- arch/x86/include/asm/trap_pf.h | 2 ++ arch/x86/mm/fault.c

[PATCH v19 12/25] mm: Introduce VM_SHSTK for shadow stack memory

2021-02-03 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 v19 10/25] x86/mm: Update pte_modify for _PAGE_COW

2021-02-03 Thread Yu-cheng Yu
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 --- arch/

[PATCH v19 11/25] x86/mm: Update ptep_set_wrprotect() and pmdp_set_wrprotect() for transition from _PAGE_DIRTY to _PAGE_COW

2021-02-03 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 --- arch/x86/include/asm

[PATCH v19 15/25] mm: Fixup places that call pte_mkwrite() directly

2021-02-03 Thread Yu-cheng Yu
different vma flags, and handled accordingly in maybe_mkwrite(). Signed-off-by: Yu-cheng Yu --- 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 feff48e1465a..1de649c61013 10064

[PATCH v19 17/25] mm/mmap: Add shadow stack pages to memory accounting

2021-02-03 Thread Yu-cheng Yu
Account shadow stack pages to stack memory. Signed-off-by: Yu-cheng Yu --- 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/mm/pgtable.c index

  1   2   3   4   5   6   7   8   9   >