Author: markj
Date: Tue Sep  8 12:37:46 2020
New Revision: 365453
URL: https://svnweb.freebsd.org/changeset/base/365453

Log:
  MFC r365048:
  Tighten frame pointer checking in DTrace's amd64 stack unwinder.

Modified:
  stable/12/sys/cddl/dev/dtrace/amd64/dtrace_isa.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/cddl/dev/dtrace/amd64/dtrace_isa.c
==============================================================================
--- stable/12/sys/cddl/dev/dtrace/amd64/dtrace_isa.c    Tue Sep  8 12:37:18 
2020        (r365452)
+++ stable/12/sys/cddl/dev/dtrace/amd64/dtrace_isa.c    Tue Sep  8 12:37:46 
2020        (r365453)
@@ -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;
        }
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to