File backtrace-powerpc.patch of Package glibc.34926
From d93769405996dfc11d216ddbe415946617b5a494 Mon Sep 17 00:00:00 2001
From: Andreas Schwab <schwab@suse.de>
Date: Mon, 20 Jan 2020 17:01:50 +0100
Subject: [PATCH] Fix array overflow in backtrace on PowerPC (bug 25423)
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 | 12 ++++++++++++
sysdeps/powerpc/powerpc32/backtrace.c | 2 ++
sysdeps/powerpc/powerpc64/backtrace.c | 2 ++
3 files changed, 16 insertions(+)
Index: glibc-2.22/debug/tst-backtrace5.c
===================================================================
--- glibc-2.22.orig/debug/tst-backtrace5.c
+++ glibc-2.22/debug/tst-backtrace5.c
@@ -92,6 +92,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: glibc-2.22/sysdeps/powerpc/powerpc32/backtrace.c
===================================================================
--- glibc-2.22.orig/sysdeps/powerpc/powerpc32/backtrace.c
+++ glibc-2.22/sysdeps/powerpc/powerpc32/backtrace.c
@@ -113,7 +113,11 @@ __backtrace (void **array, int size)
gregset = &sigframe->uc.uc_mcontext.uc_regs->gregs;
}
if (gregset)
- array[++count] = (void*)((*gregset)[PT_NIP]);
+ {
+ if (count + 1 == size)
+ break;
+ array[++count] = (void*)((*gregset)[PT_NIP]);
+ }
}
/* It's possible the second-last stack frame can't return
Index: glibc-2.22/sysdeps/powerpc/powerpc64/backtrace.c
===================================================================
--- glibc-2.22.orig/sysdeps/powerpc/powerpc64/backtrace.c
+++ glibc-2.22/sysdeps/powerpc/powerpc64/backtrace.c
@@ -85,6 +85,8 @@ __backtrace (void **array, int size)
if (is_sigtramp_address ((unsigned long)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];
}
}