diff mbox series

[v2] powerpc/32: Implement validation of emergency stack

Message ID 2439d50b019f758db4a6d7b238b06441ab109799.1724156805.git.christophe.leroy@csgroup.eu (mailing list archive)
State Accepted
Commit dca5b1d69aea36ab559d9ca13729370007c60df1
Headers show
Series [v2] powerpc/32: Implement validation of emergency stack | expand

Checks

Context Check Description
snowpatch_ozlabs/github-powerpc_ppctests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_selftests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_sparse success Successfully ran 4 jobs.
snowpatch_ozlabs/github-powerpc_clang success Successfully ran 5 jobs.
snowpatch_ozlabs/github-powerpc_kernel_qemu success Successfully ran 21 jobs.

Commit Message

Christophe Leroy Aug. 20, 2024, 12:26 p.m. UTC
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>
---
Declare emergency_ctx[] at all time, not only when CONFIG_VMAP_STACK is set
---
 arch/powerpc/include/asm/thread_info.h |  4 ++++
 arch/powerpc/kernel/process.c          | 20 ++++++++++++++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)

Comments

Michael Ellerman Sept. 6, 2024, 11:52 a.m. UTC | #1
On Tue, 20 Aug 2024 14:26:54 +0200, Christophe Leroy wrote:
> 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.
> 
> 
> [...]

Applied to powerpc/next.

[1/1] powerpc/32: Implement validation of emergency stack
      https://git.kernel.org/powerpc/c/dca5b1d69aea36ab559d9ca13729370007c60df1

cheers
diff mbox series

Patch

diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
index 15c5691dd218..6ebca2996f18 100644
--- a/arch/powerpc/include/asm/thread_info.h
+++ b/arch/powerpc/include/asm/thread_info.h
@@ -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__ */
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 3b506d4c55f3..b27e2f69930c 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -2177,10 +2177,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);
 
@@ -2208,10 +2208,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