Skip to content

Commit dca5b1d

Browse files
chleroympe
authored andcommitted
powerpc/32: Implement validation of emergency stack
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
1 parent 062e825 commit dca5b1d

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

arch/powerpc/include/asm/thread_info.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ static inline int arch_within_stack_frames(const void * const stack,
226226
return BAD_STACK;
227227
}
228228

229+
#ifdef CONFIG_PPC32
230+
extern void *emergency_ctx[];
231+
#endif
232+
229233
#endif /* !__ASSEMBLY__ */
230234

231235
#endif /* __KERNEL__ */

arch/powerpc/kernel/process.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,10 +2175,10 @@ static inline int valid_irq_stack(unsigned long sp, struct task_struct *p,
21752175
return 0;
21762176
}
21772177

2178+
#ifdef CONFIG_PPC64
21782179
static inline int valid_emergency_stack(unsigned long sp, struct task_struct *p,
21792180
unsigned long nbytes)
21802181
{
2181-
#ifdef CONFIG_PPC64
21822182
unsigned long stack_page;
21832183
unsigned long cpu = task_cpu(p);
21842184

@@ -2206,10 +2206,26 @@ static inline int valid_emergency_stack(unsigned long sp, struct task_struct *p,
22062206
if (sp >= stack_page && sp <= stack_page + THREAD_SIZE - nbytes)
22072207
return 1;
22082208
# endif
2209-
#endif
22102209

22112210
return 0;
22122211
}
2212+
#else
2213+
static inline int valid_emergency_stack(unsigned long sp, struct task_struct *p,
2214+
unsigned long nbytes)
2215+
{
2216+
unsigned long stack_page;
2217+
unsigned long cpu = task_cpu(p);
2218+
2219+
if (!IS_ENABLED(CONFIG_VMAP_STACK))
2220+
return 0;
2221+
2222+
stack_page = (unsigned long)emergency_ctx[cpu] - THREAD_SIZE;
2223+
if (sp >= stack_page && sp <= stack_page + THREAD_SIZE - nbytes)
2224+
return 1;
2225+
2226+
return 0;
2227+
}
2228+
#endif
22132229

22142230
/*
22152231
* validate the stack frame of a particular minimum size, used for when we are

0 commit comments

Comments
 (0)