Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 1 Sep 2020 15:15:44 +0000 (UTC)
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r365048 - head/sys/cddl/dev/dtrace/amd64
Message-ID:  <202009011515.081FFiEP093730@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: markj
Date: Tue Sep  1 15:15:44 2020
New Revision: 365048
URL: https://svnweb.freebsd.org/changeset/base/365048

Log:
  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.

Modified:
  head/sys/cddl/dev/dtrace/amd64/dtrace_isa.c

Modified: head/sys/cddl/dev/dtrace/amd64/dtrace_isa.c
==============================================================================
--- head/sys/cddl/dev/dtrace/amd64/dtrace_isa.c	Tue Sep  1 15:15:22 2020	(r365047)
+++ head/sys/cddl/dev/dtrace/amd64/dtrace_isa.c	Tue Sep  1 15:15:44 2020	(r365048)
@@ -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, in
 	__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, in
 			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;
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202009011515.081FFiEP093730>