Skip to content

Commit 54007f8

Browse files
yyu-intel-comrpedgeco
authored andcommitted
mm: Introduce VM_SHADOW_STACK for shadow stack memory
New hardware extensions implement support for shadow stack memory, such as x86 Control-flow Enforcement Technology (CET). Add a new VM flag to identify these areas, for example, to be used to properly indicate shadow stack PTEs to the hardware. Shadow stack VMA creation will be tightly controlled and limited to anonymous memory to make the implementation simpler and since that is all that is required. The solution will rely on pte_mkwrite() to create the shadow stack PTEs, so it will not be required for vm_get_page_prot() to learn how to create shadow stack memory. For this reason document that VM_SHADOW_STACK should not be mixed with VM_SHARED. Co-developed-by: Rick Edgecombe <[email protected]> Signed-off-by: Yu-cheng Yu <[email protected]> Signed-off-by: Rick Edgecombe <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Reviewed-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Kees Cook <[email protected]> Reviewed-by: Kirill A. Shutemov <[email protected]> Reviewed-by: Mark Brown <[email protected]> Acked-by: Mike Rapoport (IBM) <[email protected]> Acked-by: David Hildenbrand <[email protected]> Tested-by: Mark Brown <[email protected]> Tested-by: Pengfei Xu <[email protected]> Tested-by: John Allen <[email protected]> Tested-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/all/20230613001108.3040476-15-rick.p.edgecombe%40intel.com
1 parent f788b71 commit 54007f8

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

Documentation/filesystems/proc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ encoded manner. The codes are the following:
566566
mt arm64 MTE allocation tags are enabled
567567
um userfaultfd missing tracking
568568
uw userfaultfd wr-protect tracking
569+
ss shadow stack page
569570
== =======================================
570571

571572
Note that there is no guarantee that every flag and associated mnemonic will

fs/proc/task_mmu.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,9 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma)
709709
#ifdef CONFIG_HAVE_ARCH_USERFAULTFD_MINOR
710710
[ilog2(VM_UFFD_MINOR)] = "ui",
711711
#endif /* CONFIG_HAVE_ARCH_USERFAULTFD_MINOR */
712+
#ifdef CONFIG_X86_USER_SHADOW_STACK
713+
[ilog2(VM_SHADOW_STACK)] = "ss",
714+
#endif
712715
};
713716
size_t i;
714717

include/linux/mm.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,13 @@ extern unsigned int kobjsize(const void *objp);
319319
#define VM_HIGH_ARCH_BIT_2 34 /* bit only usable on 64-bit architectures */
320320
#define VM_HIGH_ARCH_BIT_3 35 /* bit only usable on 64-bit architectures */
321321
#define VM_HIGH_ARCH_BIT_4 36 /* bit only usable on 64-bit architectures */
322+
#define VM_HIGH_ARCH_BIT_5 37 /* bit only usable on 64-bit architectures */
322323
#define VM_HIGH_ARCH_0 BIT(VM_HIGH_ARCH_BIT_0)
323324
#define VM_HIGH_ARCH_1 BIT(VM_HIGH_ARCH_BIT_1)
324325
#define VM_HIGH_ARCH_2 BIT(VM_HIGH_ARCH_BIT_2)
325326
#define VM_HIGH_ARCH_3 BIT(VM_HIGH_ARCH_BIT_3)
326327
#define VM_HIGH_ARCH_4 BIT(VM_HIGH_ARCH_BIT_4)
328+
#define VM_HIGH_ARCH_5 BIT(VM_HIGH_ARCH_BIT_5)
327329
#endif /* CONFIG_ARCH_USES_HIGH_VMA_FLAGS */
328330

329331
#ifdef CONFIG_ARCH_HAS_PKEYS
@@ -339,6 +341,12 @@ extern unsigned int kobjsize(const void *objp);
339341
#endif
340342
#endif /* CONFIG_ARCH_HAS_PKEYS */
341343

344+
#ifdef CONFIG_X86_USER_SHADOW_STACK
345+
# define VM_SHADOW_STACK VM_HIGH_ARCH_5 /* Should not be set with VM_SHARED */
346+
#else
347+
# define VM_SHADOW_STACK VM_NONE
348+
#endif
349+
342350
#if defined(CONFIG_X86)
343351
# define VM_PAT VM_ARCH_1 /* PAT reserves whole VMA at once (x86) */
344352
#elif defined(CONFIG_PPC)

0 commit comments

Comments
 (0)