Skip to content

Commit 6497b66

Browse files
brooniectmarinas
authored andcommitted
arm64/mm: Map pages for guarded control stack
Map pages flagged as being part of a GCS as such rather than using the full set of generic VM flags. This is done using a conditional rather than extending the size of protection_map since that would make for a very sparse array. Reviewed-by: Thiago Jung Bauermann <[email protected]> Reviewed-by: Catalin Marinas <[email protected]> Signed-off-by: Mark Brown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent ae80e16 commit 6497b66

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

arch/arm64/include/asm/mman.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ static inline bool arch_validate_flags(unsigned long vm_flags)
7171
return false;
7272
}
7373

74+
if (system_supports_gcs() && (vm_flags & VM_SHADOW_STACK)) {
75+
/* An executable GCS isn't a good idea. */
76+
if (vm_flags & VM_EXEC)
77+
return false;
78+
79+
/* The memory management core should prevent this */
80+
VM_WARN_ON(vm_flags & VM_SHARED);
81+
}
82+
7483
return true;
7584

7685
}

arch/arm64/mm/mmap.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,15 @@ arch_initcall(adjust_protection_map);
8383

8484
pgprot_t vm_get_page_prot(unsigned long vm_flags)
8585
{
86-
pteval_t prot = pgprot_val(protection_map[vm_flags &
86+
pteval_t prot;
87+
88+
/* Short circuit GCS to avoid bloating the table. */
89+
if (system_supports_gcs() && (vm_flags & VM_SHADOW_STACK)) {
90+
prot = _PAGE_GCS_RO;
91+
} else {
92+
prot = pgprot_val(protection_map[vm_flags &
8793
(VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]);
94+
}
8895

8996
if (vm_flags & VM_ARM64_BTI)
9097
prot |= PTE_GP;

0 commit comments

Comments
 (0)