Skip to content

Commit

Permalink
Avoid stack overflow in native symbolification
Browse files Browse the repository at this point in the history
If looking up debug info by build id returns a file with MiniDebugInfo
(the `.gnu_debugdata` section), libbacktrace will infinitely recurse,
leading to a stack overflow unless the limit on the maximum number of
open file descriptors is reached before the stack can overflow.

Work around this by ignoring the MiniDebugInfo if we've already
successfully loaded the debug info by its build id.

Signed-off-by: Matt Wozniski <mwozniski@bloomberg.net>
  • Loading branch information
godlygeek authored and pablogsal committed Jun 28, 2024
1 parent 3c31f30 commit f1d984d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions news/639.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug that could in rare circumstances result in a stack overflow while processing native mode stacks.
3 changes: 2 additions & 1 deletion src/vendor/libbacktrace/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -6876,7 +6876,8 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor,
}
}

if (!gnu_debugdata_view_valid
if (!debuginfo
&& !gnu_debugdata_view_valid
&& strcmp (name, ".gnu_debugdata") == 0)
{
if (!elf_get_view (state, descriptor, memory, memory_size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ index 0000000..78f4d8d
+
+#endif /* _DEBUGINFOD_CLIENT_H */
diff --git a/elf.c b/elf.c
index 107e26c..3d2b75f 100644
index 107e26c..e62668b 100644
--- a/elf.c
+++ b/elf.c
@@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. */
Expand Down Expand Up @@ -239,7 +239,17 @@ index 107e26c..3d2b75f 100644
/* Open a separate debug info file, using the build ID to find it.
Returns an open file descriptor, or -1.

@@ -6946,6 +6981,14 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor,
@@ -6841,7 +6876,8 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor,
}
}

- if (!gnu_debugdata_view_valid
+ if (!debuginfo
+ && !gnu_debugdata_view_valid
&& strcmp (name, ".gnu_debugdata") == 0)
{
if (!elf_get_view (state, descriptor, memory, memory_size,
@@ -6946,6 +6982,14 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor,

d = elf_open_debugfile_by_buildid (state, buildid_data, buildid_size,
error_callback, data);
Expand All @@ -254,7 +264,7 @@ index 107e26c..3d2b75f 100644
if (d >= 0)
{
int ret;
@@ -7421,7 +7464,28 @@ backtrace_initialize (struct backtrace_state *state, const char *filename,
@@ -7421,7 +7465,28 @@ backtrace_initialize (struct backtrace_state *state, const char *filename,
pd.exe_filename = filename;
pd.exe_descriptor = ret < 0 ? descriptor : -1;

Expand Down

0 comments on commit f1d984d

Please sign in to comment.