Skip to content

Commit 2142b7f

Browse files
committed
Merge tag 'hardening-v5.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull kernel hardening updates from Kees Cook: - Add arm64 Shadow Call Stack support for GCC 12 (Dan Li) - Avoid memset with stack offset randomization under Clang (Marco Elver) - Clean up stackleak plugin to play nice with .noinstr (Kees Cook) - Check stack depth for greater usercopy hardening coverage (Kees Cook) * tag 'hardening-v5.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: arm64: Add gcc Shadow Call Stack support m68k: Implement "current_stack_pointer" xtensa: Implement "current_stack_pointer" usercopy: Check valid lifetime via stack depth stack: Constrain and fix stack offset randomization with Clang builds stack: Introduce CONFIG_RANDOMIZE_KSTACK_OFFSET gcc-plugins/stackleak: Ignore .noinstr.text and .entry.text gcc-plugins/stackleak: Exactly match strings instead of prefixes gcc-plugins/stackleak: Provide verbose mode
2 parents fd2d7a4 + afcf544 commit 2142b7f

21 files changed

Lines changed: 139 additions & 31 deletions

File tree

arch/Kconfig

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -599,21 +599,22 @@ config STACKPROTECTOR_STRONG
599599
config ARCH_SUPPORTS_SHADOW_CALL_STACK
600600
bool
601601
help
602-
An architecture should select this if it supports Clang's Shadow
603-
Call Stack and implements runtime support for shadow stack
602+
An architecture should select this if it supports the compiler's
603+
Shadow Call Stack and implements runtime support for shadow stack
604604
switching.
605605

606606
config SHADOW_CALL_STACK
607-
bool "Clang Shadow Call Stack"
608-
depends on CC_IS_CLANG && ARCH_SUPPORTS_SHADOW_CALL_STACK
607+
bool "Shadow Call Stack"
608+
depends on ARCH_SUPPORTS_SHADOW_CALL_STACK
609609
depends on DYNAMIC_FTRACE_WITH_REGS || !FUNCTION_GRAPH_TRACER
610610
help
611-
This option enables Clang's Shadow Call Stack, which uses a
612-
shadow stack to protect function return addresses from being
613-
overwritten by an attacker. More information can be found in
614-
Clang's documentation:
611+
This option enables the compiler's Shadow Call Stack, which
612+
uses a shadow stack to protect function return addresses from
613+
being overwritten by an attacker. More information can be found
614+
in the compiler's documentation:
615615

616-
https://clang.llvm.org/docs/ShadowCallStack.html
616+
- Clang: https://clang.llvm.org/docs/ShadowCallStack.html
617+
- GCC: https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#Instrumentation-Options
617618

618619
Note that security guarantees in the kernel differ from the
619620
ones documented for user space. The kernel must store addresses
@@ -1159,16 +1160,30 @@ config HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET
11591160
to the compiler, so it will attempt to add canary checks regardless
11601161
of the static branch state.
11611162

1162-
config RANDOMIZE_KSTACK_OFFSET_DEFAULT
1163-
bool "Randomize kernel stack offset on syscall entry"
1163+
config RANDOMIZE_KSTACK_OFFSET
1164+
bool "Support for randomizing kernel stack offset on syscall entry" if EXPERT
1165+
default y
11641166
depends on HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET
1167+
depends on INIT_STACK_NONE || !CC_IS_CLANG || CLANG_VERSION >= 140000
11651168
help
11661169
The kernel stack offset can be randomized (after pt_regs) by
11671170
roughly 5 bits of entropy, frustrating memory corruption
11681171
attacks that depend on stack address determinism or
1169-
cross-syscall address exposures. This feature is controlled
1170-
by kernel boot param "randomize_kstack_offset=on/off", and this
1171-
config chooses the default boot state.
1172+
cross-syscall address exposures.
1173+
1174+
The feature is controlled via the "randomize_kstack_offset=on/off"
1175+
kernel boot param, and if turned off has zero overhead due to its use
1176+
of static branches (see JUMP_LABEL).
1177+
1178+
If unsure, say Y.
1179+
1180+
config RANDOMIZE_KSTACK_OFFSET_DEFAULT
1181+
bool "Default state of kernel stack offset randomization"
1182+
depends on RANDOMIZE_KSTACK_OFFSET
1183+
help
1184+
Kernel stack offset randomization is controlled by kernel boot param
1185+
"randomize_kstack_offset=on/off", and this config chooses the default
1186+
boot state.
11721187

11731188
config ARCH_OPTIONAL_KERNEL_RWX
11741189
def_bool n

arch/arm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ config ARM
55
select ARCH_32BIT_OFF_T
66
select ARCH_CORRECT_STACKTRACE_ON_KRETPROBE if HAVE_KRETPROBES && FRAME_POINTER && !ARM_UNWIND
77
select ARCH_HAS_BINFMT_FLAT
8+
select ARCH_HAS_CURRENT_STACK_POINTER
89
select ARCH_HAS_DEBUG_VIRTUAL if MMU
910
select ARCH_HAS_DMA_WRITE_COMBINE if !ARM_DMA_MEM_BUFFERABLE
1011
select ARCH_HAS_ELF_RANDOMIZE

arch/arm64/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ config ARM64
1919
select ARCH_ENABLE_SPLIT_PMD_PTLOCK if PGTABLE_LEVELS > 2
2020
select ARCH_ENABLE_THP_MIGRATION if TRANSPARENT_HUGEPAGE
2121
select ARCH_HAS_CACHE_LINE_SIZE
22+
select ARCH_HAS_CURRENT_STACK_POINTER
2223
select ARCH_HAS_DEBUG_VIRTUAL
2324
select ARCH_HAS_DEBUG_VM_PGTABLE
2425
select ARCH_HAS_DMA_PREP_COHERENT
@@ -1257,7 +1258,7 @@ config HW_PERF_EVENTS
12571258
def_bool y
12581259
depends on ARM_PMU
12591260

1260-
# Supported by clang >= 7.0
1261+
# Supported by clang >= 7.0 or GCC >= 12.0.0
12611262
config CC_HAVE_SHADOW_CALL_STACK
12621263
def_bool $(cc-option, -fsanitize=shadow-call-stack -ffixed-x18)
12631264

arch/m68k/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ config M68K
44
default y
55
select ARCH_32BIT_OFF_T
66
select ARCH_HAS_BINFMT_FLAT
7+
select ARCH_HAS_CURRENT_STACK_POINTER
78
select ARCH_HAS_DMA_PREP_COHERENT if HAS_DMA && MMU && !COLDFIRE
89
select ARCH_HAS_SYNC_DMA_FOR_DEVICE if HAS_DMA
910
select ARCH_HAVE_NMI_SAFE_CMPXCHG if RMW_INSNS

arch/m68k/include/asm/current.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ static inline struct task_struct *get_current(void)
2424

2525
#define current get_current()
2626

27-
#endif /* CONFNIG_MMU */
27+
#endif /* CONFIG_MMU */
28+
29+
register unsigned long current_stack_pointer __asm__("sp");
2830

2931
#endif /* !(_M68K_CURRENT_H) */

arch/powerpc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ config PPC
108108
select ARCH_ENABLE_MEMORY_HOTPLUG
109109
select ARCH_ENABLE_MEMORY_HOTREMOVE
110110
select ARCH_HAS_COPY_MC if PPC64
111+
select ARCH_HAS_CURRENT_STACK_POINTER
111112
select ARCH_HAS_DEBUG_VIRTUAL
112113
select ARCH_HAS_DEBUG_VM_PGTABLE
113114
select ARCH_HAS_DEBUG_WX if STRICT_KERNEL_RWX

arch/s390/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ config S390
6060
select ARCH_ENABLE_MEMORY_HOTPLUG if SPARSEMEM
6161
select ARCH_ENABLE_MEMORY_HOTREMOVE
6262
select ARCH_ENABLE_SPLIT_PMD_PTLOCK if PGTABLE_LEVELS > 2
63+
select ARCH_HAS_CURRENT_STACK_POINTER
6364
select ARCH_HAS_DEBUG_VM_PGTABLE
6465
select ARCH_HAS_DEBUG_WX
6566
select ARCH_HAS_DEVMEM_IS_ALLOWED

arch/sh/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ config SUPERH
77
select ARCH_HAVE_CUSTOM_GPIO_H
88
select ARCH_HAVE_NMI_SAFE_CMPXCHG if (GUSA_RB || CPU_SH4A)
99
select ARCH_HAS_BINFMT_FLAT if !MMU
10+
select ARCH_HAS_CURRENT_STACK_POINTER
1011
select ARCH_HAS_GIGANTIC_PAGE
1112
select ARCH_HAS_GCOV_PROFILE_ALL
1213
select ARCH_HAS_PTE_SPECIAL

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ config X86
6969
select ARCH_ENABLE_THP_MIGRATION if X86_64 && TRANSPARENT_HUGEPAGE
7070
select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI
7171
select ARCH_HAS_CACHE_LINE_SIZE
72+
select ARCH_HAS_CURRENT_STACK_POINTER
7273
select ARCH_HAS_DEBUG_VIRTUAL
7374
select ARCH_HAS_DEBUG_VM_PGTABLE if !X86_PAE
7475
select ARCH_HAS_DEVMEM_IS_ALLOWED

arch/xtensa/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ config XTENSA
33
def_bool y
44
select ARCH_32BIT_OFF_T
55
select ARCH_HAS_BINFMT_FLAT if !MMU
6+
select ARCH_HAS_CURRENT_STACK_POINTER
67
select ARCH_HAS_DMA_PREP_COHERENT if MMU
78
select ARCH_HAS_SYNC_DMA_FOR_CPU if MMU
89
select ARCH_HAS_SYNC_DMA_FOR_DEVICE if MMU

0 commit comments

Comments
 (0)