Skip to contentSkip to conversation

mips: Implement "current_stack_pointer"

PATCH Applied Kees Cook 2 participants 2 messages Feb 24, 2022 – Mar 1, 2022 MIPS

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 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 <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Yanteng Si <[email protected]>
---
 arch/mips/Kconfig                   | 1 +
 arch/mips/include/asm/thread_info.h | 2 ++
 arch/mips/kernel/irq.c              | 3 +--
 arch/mips/lib/uncached.c            | 4 +---
 4 files changed, 5 insertions(+), 5 deletions(-)
arch/mips/Kconfig +1 -0
index 058446f01487..6781f87e2218 100644
@@ -4,6 +4,7 @@ config MIPS
 	default y
 	select ARCH_32BIT_OFF_T if !64BIT
 	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_FORTIFY_SOURCE
 	select ARCH_HAS_KCOV
arch/mips/include/asm/thread_info.h +2 -0
index 0b17aaa9e012..4463348d2372 100644
@@ -69,6 +69,8 @@ static inline struct thread_info *current_thread_info(void)
 	return __current_thread_info;
 }
 
+register unsigned long current_stack_pointer __asm__("sp");
+
 #endif /* !__ASSEMBLY__ */
 
 /* thread information allocation */
arch/mips/kernel/irq.c +1 -2
index 5e11582fe308..fc313c49a417 100644
@@ -75,9 +75,8 @@ void __init init_IRQ(void)
 #ifdef CONFIG_DEBUG_STACKOVERFLOW
 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;
 
 	/*
arch/mips/lib/uncached.c +1 -3
index f80a67c092b6..f8d4ca046c3e 100644
@@ -40,9 +40,7 @@ unsigned long run_uncached(void *func)
 	register long ret __asm__("$2");
 	long lfunc = (long)func, ufunc;
 	long usp;
-	long sp;
-
-	__asm__("move %0, $sp" : "=r" (sp));
+	long sp = current_stack_pointer;
 
 	if (sp >= (long)CKSEG0 && sp < (long)CKSEG2)
 		usp = CKSEG1ADDR(sp);
Signature · 1 line
2.30.2
maintainer Applied
#1 lore raw
Quoted 11 lines · Kees Cook

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 <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Yanteng Si <[email protected]>
Quoted 6 lines
---
 arch/mips/Kconfig                   | 1 +
 arch/mips/include/asm/thread_info.h | 2 ++
 arch/mips/kernel/irq.c              | 3 +--
 arch/mips/lib/uncached.c            | 4 +---
 4 files changed, 5 insertions(+), 5 deletions(-)

applied to mips-next.

Thomas.

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]