]> www.infradead.org Git - users/willy/xarray.git/commitdiff
powerpc/32: Implement validation of emergency stack
authorChristophe Leroy <christophe.leroy@csgroup.eu>
Tue, 20 Aug 2024 12:26:54 +0000 (14:26 +0200)
committerMichael Ellerman <mpe@ellerman.id.au>
Fri, 30 Aug 2024 11:30:20 +0000 (21:30 +1000)
VMAP stack added an emergency stack on powerpc/32 for when there is
a stack overflow, but failed to add stack validation for that
emergency stack. That validation is required for show stack.

Implement it.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/2439d50b019f758db4a6d7b238b06441ab109799.1724156805.git.christophe.leroy@csgroup.eu
arch/powerpc/include/asm/thread_info.h
arch/powerpc/kernel/process.c

index 15c5691dd218440d32142779a2a1e2ce5058d60c..6ebca2996f18f8ca9e8ae2f89146f35d78394cb1 100644 (file)
@@ -226,6 +226,10 @@ static inline int arch_within_stack_frames(const void * const stack,
        return BAD_STACK;
 }
 
+#ifdef CONFIG_PPC32
+extern void *emergency_ctx[];
+#endif
+
 #endif /* !__ASSEMBLY__ */
 
 #endif /* __KERNEL__ */
index e7b70c2cc0013038087b765c017225fe8fcc84dd..ff61a3e7984cecce32ecb29e337845b0b56348ce 100644 (file)
@@ -2175,10 +2175,10 @@ static inline int valid_irq_stack(unsigned long sp, struct task_struct *p,
        return 0;
 }
 
+#ifdef CONFIG_PPC64
 static inline int valid_emergency_stack(unsigned long sp, struct task_struct *p,
                                        unsigned long nbytes)
 {
-#ifdef CONFIG_PPC64
        unsigned long stack_page;
        unsigned long cpu = task_cpu(p);
 
@@ -2206,10 +2206,26 @@ static inline int valid_emergency_stack(unsigned long sp, struct task_struct *p,
        if (sp >= stack_page && sp <= stack_page + THREAD_SIZE - nbytes)
                return 1;
 # endif
-#endif
 
        return 0;
 }
+#else
+static inline int valid_emergency_stack(unsigned long sp, struct task_struct *p,
+                                       unsigned long nbytes)
+{
+       unsigned long stack_page;
+       unsigned long cpu = task_cpu(p);
+
+       if (!IS_ENABLED(CONFIG_VMAP_STACK))
+               return 0;
+
+       stack_page = (unsigned long)emergency_ctx[cpu] - THREAD_SIZE;
+       if (sp >= stack_page && sp <= stack_page + THREAD_SIZE - nbytes)
+               return 1;
+
+       return 0;
+}
+#endif
 
 /*
  * validate the stack frame of a particular minimum size, used for when we are