mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	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>
			
			
This commit is contained in:
		
							parent
							
								
									624c60f326
								
							
						
					
					
						commit
						05107edc91
					
				
					 2 changed files with 24 additions and 6 deletions
				
			
		
							
								
								
									
										23
									
								
								tools/testing/selftests/sigaltstack/current_stack_pointer.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								tools/testing/selftests/sigaltstack/current_stack_pointer.h
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,23 @@
 | 
				
			||||||
 | 
					/* SPDX-License-Identifier: GPL-2.0 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if __alpha__
 | 
				
			||||||
 | 
					register unsigned long sp asm("$30");
 | 
				
			||||||
 | 
					#elif __arm__ || __aarch64__ || __csky__ || __m68k__ || __mips__ || __riscv
 | 
				
			||||||
 | 
					register unsigned long sp asm("sp");
 | 
				
			||||||
 | 
					#elif __i386__
 | 
				
			||||||
 | 
					register unsigned long sp asm("esp");
 | 
				
			||||||
 | 
					#elif __loongarch64
 | 
				
			||||||
 | 
					register unsigned long sp asm("$sp");
 | 
				
			||||||
 | 
					#elif __ppc__
 | 
				
			||||||
 | 
					register unsigned long sp asm("r1");
 | 
				
			||||||
 | 
					#elif __s390x__
 | 
				
			||||||
 | 
					register unsigned long sp asm("%15");
 | 
				
			||||||
 | 
					#elif __sh__
 | 
				
			||||||
 | 
					register unsigned long sp asm("r15");
 | 
				
			||||||
 | 
					#elif __x86_64__
 | 
				
			||||||
 | 
					register unsigned long sp asm("rsp");
 | 
				
			||||||
 | 
					#elif __XTENSA__
 | 
				
			||||||
 | 
					register unsigned long sp asm("a1");
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error "implement current_stack_pointer equivalent"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					@ -20,6 +20,7 @@
 | 
				
			||||||
#include <sys/auxv.h>
 | 
					#include <sys/auxv.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "../kselftest.h"
 | 
					#include "../kselftest.h"
 | 
				
			||||||
 | 
					#include "current_stack_pointer.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef SS_AUTODISARM
 | 
					#ifndef SS_AUTODISARM
 | 
				
			||||||
#define SS_AUTODISARM  (1U << 31)
 | 
					#define SS_AUTODISARM  (1U << 31)
 | 
				
			||||||
| 
						 | 
					@ -46,12 +47,6 @@ void my_usr1(int sig, siginfo_t *si, void *u)
 | 
				
			||||||
	stack_t stk;
 | 
						stack_t stk;
 | 
				
			||||||
	struct stk_data *p;
 | 
						struct stk_data *p;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if __s390x__
 | 
					 | 
				
			||||||
	register unsigned long sp asm("%15");
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
	register unsigned long sp asm("sp");
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (sp < (unsigned long)sstack ||
 | 
						if (sp < (unsigned long)sstack ||
 | 
				
			||||||
			sp >= (unsigned long)sstack + stack_size) {
 | 
								sp >= (unsigned long)sstack + stack_size) {
 | 
				
			||||||
		ksft_exit_fail_msg("SP is not on sigaltstack\n");
 | 
							ksft_exit_fail_msg("SP is not on sigaltstack\n");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue