Tighten frame pointer checking in DTrace's amd64 stack unwinder.

Avoid assuming that the kernel was compiled with
-fno-omit-frame-pointer.

MFC after:	1 week
Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.
This commit is contained in:
markj 2020-09-01 15:15:44 +00:00
parent 1c59d2ad22
commit 4031fa7f1e

View File

@ -56,6 +56,7 @@ void
dtrace_getpcstack(pc_t *pcstack, int pcstack_limit, int aframes,
uint32_t *intrpc)
{
struct thread *td;
int depth = 0;
register_t rbp;
struct amd64_frame *frame;
@ -70,10 +71,16 @@ dtrace_getpcstack(pc_t *pcstack, int pcstack_limit, int aframes,
__asm __volatile("movq %%rbp,%0" : "=r" (rbp));
frame = (struct amd64_frame *)rbp;
td = curthread;
while (depth < pcstack_limit) {
if (!INKERNEL((long) frame))
break;
if ((vm_offset_t)frame >=
td->td_kstack + ptoa(td->td_kstack_pages) ||
(vm_offset_t)frame < td->td_kstack)
break;
callpc = frame->f_retaddr;
if (!INKERNEL(callpc))
@ -84,14 +91,11 @@ dtrace_getpcstack(pc_t *pcstack, int pcstack_limit, int aframes,
if ((aframes == 0) && (caller != 0)) {
pcstack[depth++] = caller;
}
}
else {
} else {
pcstack[depth++] = callpc;
}
if (frame->f_frame <= frame ||
(vm_offset_t)frame->f_frame >= curthread->td_kstack +
curthread->td_kstack_pages * PAGE_SIZE)
if ((vm_offset_t)frame->f_frame <= (vm_offset_t)frame)
break;
frame = frame->f_frame;
}