]> 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)
committerAndreas Schwab <schwab@suse.de>
Tue, 21 Jan 2020 14:26:57 +0000 (15:26 +0100)
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").

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

index e7ce410845eaf2a53386e1fd8401525cd78bb9ca..b2f46160e7a9fcfc7c1f97f786509ae2d92dee7b 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 7c2d4726f8b76ce969cc6954f427d3cdcc2b74c5..d1456c8ae4d5603921971e38d019a0c978422ec1 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 65c260ab764c9c78d6805d3f5ad919682f1457c4..8a53a1088f27af137b3cef4f3eac96046889cd92 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];
        }