]> 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)
committerTulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
Fri, 20 Mar 2020 18:23:11 +0000 (15:23 -0300)
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)

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

diff --git a/NEWS b/NEWS
index ace1b86fdbcc93d3ef1a2421d7cd91f8ee373130..038541c83b07c7e2cdcd05224576b684555b2958 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -73,6 +73,7 @@ The following bugs are resolved with this release:
   [25204] Ignore LD_PREFER_MAP_32BIT_EXEC for SUID programs
   [25225] ld.so fails to link on x86 if GCC defaults to -fcf-protection
   [25232] No const correctness for strchr et al. for Clang++
+  [25423] Array overflow in backtrace on powerpc
 
 Security related changes:
 
index 0e6fb1a02463a4566cd81f37bb317a95e1df969c..a117f1544f6b9d473711653f065f2bed2f5ca86d 100644 (file)
@@ -88,6 +88,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 5422fdd50d3a2116919bcbfef3dd5b5a03e955ae..c7b64f9e9bafe7f43243227734a9d48b4bdf83ed 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 c0c4b48262cf30d2f30c0dc11b85bc550fcff6ea..0acf17b37e45e32476ee3be60cc49480455d02d4 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];
        }