]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix array overflow in backtrace on PowerPC (bug 25423)
authorAndreas Schwab <schwab@suse.de>
Mon, 20 Jan 2020 16:01:50 +0000 (17:01 +0100)
committerPatsy Franklin <patsy@redhat.com>
Wed, 18 Mar 2020 14:26:13 +0000 (10:26 -0400)
When unwinding through a signal frame the backtrace function on PowerPC
didn't check array bounds when storing the frame address.  Fixes commit
d400dcac5e ("PowerPC: fix backtrace to handle signal trampolines").

(cherry picked from commit d93769405996dfc11d216ddbe415946617b5a494)

debug/tst-backtrace5.c
sysdeps/powerpc/powerpc32/backtrace.c
sysdeps/powerpc/powerpc64/backtrace.c

index 5a5ce8bc79bc65ee7e79983f8dd0d642c431c532..aed5ee4c94c7e8233c3f55281665d090df596279 100644 (file)
@@ -89,6 +89,18 @@ handle_signal (int signum)
       }
   /* Symbol names are not available for static functions, so we do not
      check do_test.  */
+
+  /* Check that backtrace does not return more than what fits in the array
+     (bug 25423).  */
+  for (int j = 0; j < NUM_FUNCTIONS; j++)
+    {
+      n = backtrace (addresses, j);
+      if (n > j)
+       {
+         FAIL ();
+         return;
+       }
+    }
 }
 
 NO_INLINE int
index 857a8aad7b996a4263845f5f8ed2dc538493a99b..dc187a8f202874568beb94003191da0c0fce5e30 100644 (file)
@@ -114,6 +114,8 @@ __backtrace (void **array, int size)
         }
       if (gregset)
        {
+         if (count + 1 == size)
+           break;
          array[++count] = (void*)((*gregset)[PT_NIP]);
          current = (void*)((*gregset)[PT_R1]);
        }
index 7a167838d913c25742e65ff7a1e2fdd533566528..ce038a139faa2e23833668d1ba14d9a15d343556 100644 (file)
@@ -87,6 +87,8 @@ __backtrace (void **array, int size)
       if (is_sigtramp_address (current->return_address))
         {
          struct signal_frame_64 *sigframe = (struct signal_frame_64*) current;
+         if (count + 1 == size)
+           break;
           array[++count] = (void*) sigframe->uc.uc_mcontext.gp_regs[PT_NIP];
          current = (void*) sigframe->uc.uc_mcontext.gp_regs[PT_R1];
        }