Re: [PATCH] sparc32: Avoid NULL pointer dereference in fault handler

From: Andreas Larsson

Date: Fri Oct 16 2026 - 10:42:28 EST


On 2026-10-14 15:32, Ludwig Rydberg wrote:
> Add a null pointer check for the return value of
> search_exception_tables() to avoid dereferencing it if no entry is found.
> Without this check, the system will crash silently without providing
> any fault information to the user.
>
> Fixes: b4edf06c8aaa ("sparc32: switch to generic extables")
> Signed-off-by: Ludwig Rydberg <ludwig.rydberg@xxxxxxxxxxx>
> ---
> arch/sparc/mm/fault_32.c | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
> index 86a831ebd8c8..4cfff3d36a99 100644
> --- a/arch/sparc/mm/fault_32.c
> +++ b/arch/sparc/mm/fault_32.c
> @@ -232,15 +232,17 @@ asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write,
> const struct exception_table_entry *entry;
>
> entry = search_exception_tables(regs->pc);
> + if (entry) {
> #ifdef DEBUG_EXCEPTIONS
> - printk("Exception: PC<%08lx> faddr<%08lx>\n",
> - regs->pc, address);
> - printk("EX_TABLE: insn<%08lx> fixup<%08x>\n",
> - regs->pc, entry->fixup);
> + printk("Exception: PC<%08lx> faddr<%08lx>\n",
> + regs->pc, address);
> + printk("EX_TABLE: insn<%08lx> fixup<%08x>\n",
> + regs->pc, entry->fixup);
> #endif
> - regs->pc = entry->fixup;
> - regs->npc = regs->pc + 4;
> - return;
> + regs->pc = entry->fixup;
> + regs->npc = regs->pc + 4;
> + return;
> + }
> }
>
> unhandled_fault(address, tsk, regs);
>
> base-commit: cee9395acd8043be0644b25c34bfa86623f2b935

Reviewed-by: Andreas Larsson <andreas@xxxxxxxxxxx>
Tested-by: Andreas Larsson <andreas@xxxxxxxxxxx>

Picking this up to my for-next.

Thanks,
Andreas