Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

stackleak: allow to specify arch specific stackleak poison function

Factor out the code that fills the stack with the stackleak poison value
in order to allow architectures to provide a faster implementation.

Acked-by: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Link: https://lore.kernel.org/r/20230405130841.1350565-2-hca@linux.ibm.com
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>

authored by

Heiko Carstens and committed by
Vasily Gorbik
491a7866 ccf7c3fb

+13 -4
+13 -4
kernel/stackleak.c
··· 70 70 #define skip_erasing() false 71 71 #endif /* CONFIG_STACKLEAK_RUNTIME_DISABLE */ 72 72 73 + #ifndef __stackleak_poison 74 + static __always_inline void __stackleak_poison(unsigned long erase_low, 75 + unsigned long erase_high, 76 + unsigned long poison) 77 + { 78 + while (erase_low < erase_high) { 79 + *(unsigned long *)erase_low = poison; 80 + erase_low += sizeof(unsigned long); 81 + } 82 + } 83 + #endif 84 + 73 85 static __always_inline void __stackleak_erase(bool on_task_stack) 74 86 { 75 87 const unsigned long task_stack_low = stackleak_task_low_bound(current); ··· 113 101 else 114 102 erase_high = task_stack_high; 115 103 116 - while (erase_low < erase_high) { 117 - *(unsigned long *)erase_low = STACKLEAK_POISON; 118 - erase_low += sizeof(unsigned long); 119 - } 104 + __stackleak_poison(erase_low, erase_high, STACKLEAK_POISON); 120 105 121 106 /* Reset the 'lowest_stack' value for the next syscall */ 122 107 current->lowest_stack = task_stack_high;