powerpc: Skip stack validation checking alternate stacks if they are not allocated
authorNicholas Piggin <npiggin@gmail.com>
Fri, 16 Dec 2022 11:59:30 +0000 (21:59 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Fri, 10 Feb 2023 11:19:56 +0000 (22:19 +1100)
Stack validation in early boot can just bail out of checking alternate
stacks if they are not validated yet. Checking against a NULL stack
could cause NULLish pointer values to be considered valid.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20221216115930.2667772-5-npiggin@gmail.com
arch/powerpc/kernel/process.c

index effe9697905dcdf6ae5ba5817f44d19c076707f9..4b29ac5ddac6409cb5c313fa96a8781eb5e182ee 100644 (file)
@@ -2117,6 +2117,9 @@ static inline int valid_irq_stack(unsigned long sp, struct task_struct *p,
        unsigned long stack_page;
        unsigned long cpu = task_cpu(p);
 
+       if (!hardirq_ctx[cpu] || !softirq_ctx[cpu])
+               return 0;
+
        stack_page = (unsigned long)hardirq_ctx[cpu];
        if (sp >= stack_page && sp <= stack_page + THREAD_SIZE - nbytes)
                return 1;
@@ -2138,6 +2141,14 @@ static inline int valid_emergency_stack(unsigned long sp, struct task_struct *p,
        if (!paca_ptrs)
                return 0;
 
+       if (!paca_ptrs[cpu]->emergency_sp)
+               return 0;
+
+# ifdef CONFIG_PPC_BOOK3S_64
+       if (!paca_ptrs[cpu]->nmi_emergency_sp || !paca_ptrs[cpu]->mc_emergency_sp)
+               return 0;
+#endif
+
        stack_page = (unsigned long)paca_ptrs[cpu]->emergency_sp - THREAD_SIZE;
        if (sp >= stack_page && sp <= stack_page + THREAD_SIZE - nbytes)
                return 1;