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

selftests: sigaltstack: fix -Wuninitialized

Building sigaltstack with clang via:
$ ARCH=x86 make LLVM=1 -C tools/testing/selftests/sigaltstack/

produces the following warning:
warning: variable 'sp' is uninitialized when used here [-Wuninitialized]
if (sp < (unsigned long)sstack ||
^~

Clang expects these to be declared at global scope; we've fixed this in
the kernel proper by using the macro `current_stack_pointer`. This is
defined in different headers for different target architectures, so just
create a new header that defines the arch-specific register names for
the stack pointer register, and define it for more targets (at least the
ones that support current_stack_pointer/ARCH_HAS_CURRENT_STACK_POINTER).

Reported-by: Linux Kernel Functional Testing <lkft@linaro.org>
Link: https://lore.kernel.org/lkml/CA+G9fYsi3OOu7yCsMutpzKDnBMAzJBCPimBp86LhGBa0eCnEpA@mail.gmail.com/
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Linux Kernel Functional Testing <lkft@linaro.org>
Tested-by: Anders Roxell <anders.roxell@linaro.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Nick Desaulniers and committed by
Shuah Khan
05107edc 624c60f3

+24 -6
+23
tools/testing/selftests/sigaltstack/current_stack_pointer.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + #if __alpha__ 4 + register unsigned long sp asm("$30"); 5 + #elif __arm__ || __aarch64__ || __csky__ || __m68k__ || __mips__ || __riscv 6 + register unsigned long sp asm("sp"); 7 + #elif __i386__ 8 + register unsigned long sp asm("esp"); 9 + #elif __loongarch64 10 + register unsigned long sp asm("$sp"); 11 + #elif __ppc__ 12 + register unsigned long sp asm("r1"); 13 + #elif __s390x__ 14 + register unsigned long sp asm("%15"); 15 + #elif __sh__ 16 + register unsigned long sp asm("r15"); 17 + #elif __x86_64__ 18 + register unsigned long sp asm("rsp"); 19 + #elif __XTENSA__ 20 + register unsigned long sp asm("a1"); 21 + #else 22 + #error "implement current_stack_pointer equivalent" 23 + #endif
+1 -6
tools/testing/selftests/sigaltstack/sas.c
··· 20 20 #include <sys/auxv.h> 21 21 22 22 #include "../kselftest.h" 23 + #include "current_stack_pointer.h" 23 24 24 25 #ifndef SS_AUTODISARM 25 26 #define SS_AUTODISARM (1U << 31) ··· 46 45 int err; 47 46 stack_t stk; 48 47 struct stk_data *p; 49 - 50 - #if __s390x__ 51 - register unsigned long sp asm("%15"); 52 - #else 53 - register unsigned long sp asm("sp"); 54 - #endif 55 48 56 49 if (sp < (unsigned long)sstack || 57 50 sp >= (unsigned long)sstack + stack_size) {