mips: Implement "current_stack_pointer"

To follow the existing per-arch conventions replace open-coded uses
of asm "sp" as "current_stack_pointer". This will let it be used in
non-arch places (like HARDENED_USERCOPY).

Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Yanteng Si <siyanteng01@gmail.com>
Cc: linux-mips@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
This commit is contained in:
Kees Cook 2022-02-23 22:04:32 -08:00 коммит произвёл Thomas Bogendoerfer
Родитель 455481fc9a
Коммит 200ed341b8
4 изменённых файлов: 5 добавлений и 5 удалений

Просмотреть файл

@ -4,6 +4,7 @@ config MIPS
default y default y
select ARCH_32BIT_OFF_T if !64BIT select ARCH_32BIT_OFF_T if !64BIT
select ARCH_BINFMT_ELF_STATE if MIPS_FP_SUPPORT select ARCH_BINFMT_ELF_STATE if MIPS_FP_SUPPORT
select ARCH_HAS_CURRENT_STACK_POINTER
select ARCH_HAS_DEBUG_VIRTUAL if !64BIT select ARCH_HAS_DEBUG_VIRTUAL if !64BIT
select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_FORTIFY_SOURCE
select ARCH_HAS_KCOV select ARCH_HAS_KCOV

Просмотреть файл

@ -69,6 +69,8 @@ static inline struct thread_info *current_thread_info(void)
return __current_thread_info; return __current_thread_info;
} }
register unsigned long current_stack_pointer __asm__("sp");
#endif /* !__ASSEMBLY__ */ #endif /* !__ASSEMBLY__ */
/* thread information allocation */ /* thread information allocation */

Просмотреть файл

@ -75,9 +75,8 @@ void __init init_IRQ(void)
#ifdef CONFIG_DEBUG_STACKOVERFLOW #ifdef CONFIG_DEBUG_STACKOVERFLOW
static inline void check_stack_overflow(void) static inline void check_stack_overflow(void)
{ {
unsigned long sp; unsigned long sp = current_stack_pointer;
__asm__ __volatile__("move %0, $sp" : "=r" (sp));
sp &= THREAD_MASK; sp &= THREAD_MASK;
/* /*

Просмотреть файл

@ -40,9 +40,7 @@ unsigned long run_uncached(void *func)
register long ret __asm__("$2"); register long ret __asm__("$2");
long lfunc = (long)func, ufunc; long lfunc = (long)func, ufunc;
long usp; long usp;
long sp; long sp = current_stack_pointer;
__asm__("move %0, $sp" : "=r" (sp));
if (sp >= (long)CKSEG0 && sp < (long)CKSEG2) if (sp >= (long)CKSEG0 && sp < (long)CKSEG2)
usp = CKSEG1ADDR(sp); usp = CKSEG1ADDR(sp);