From 5e91185bb13d804ca98d3e40e1ad30e22ad4b1bf Mon Sep 17 00:00:00 2001 From: Justin Hibbits Date: Wed, 30 May 2018 03:48:27 +0000 Subject: [PATCH] Protect dtrace_getpcstack() from a NULL stack pointer in a trap frame Found when trying to use lockstat on a POWER9, the stack pointer (r1) could be NULL, and result in a NULL pointer dereference, crashing the kernel. --- sys/cddl/dev/dtrace/powerpc/dtrace_isa.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sys/cddl/dev/dtrace/powerpc/dtrace_isa.c b/sys/cddl/dev/dtrace/powerpc/dtrace_isa.c index c6c72a3ceb1f..b6a3b3ec11a8 100644 --- a/sys/cddl/dev/dtrace/powerpc/dtrace_isa.c +++ b/sys/cddl/dev/dtrace/powerpc/dtrace_isa.c @@ -98,6 +98,7 @@ static __inline uintptr_t dtrace_next_sp(uintptr_t sp) { vm_offset_t callpc; + uintptr_t *r1; struct trapframe *frame; #ifdef __powerpc64__ @@ -114,7 +115,10 @@ dtrace_next_sp(uintptr_t sp) callpc + OFFSET == (vm_offset_t) &asttrapexit)) { /* Access the trap frame */ frame = (struct trapframe *)(sp + FRAME_OFFSET); - return (*(uintptr_t *)(frame->fixreg[1])); + r1 = (uintptr_t *)frame->fixreg[1]; + if (r1 == NULL) + return (0); + return (*r1); } return (*(uintptr_t*)sp);