Blame SOURCES/0045-gdb-disable-loading-of-auto-loaded-files.patch

06486d
From 5a2f83cd86ce824167fa7ea8e5357c014034ed46 Mon Sep 17 00:00:00 2001
06486d
From: Jakub Filak <jfilak@redhat.com>
06486d
Date: Mon, 9 Jun 2014 17:13:09 +0200
06486d
Subject: [ABRT PATCH 45/66] gdb: disable loading of auto-loaded files
06486d
06486d
https://sourceware.org/gdb/onlinedocs/gdb/Auto_002dloading.html
06486d
06486d
There are two main reasons for doing so:
06486d
1. we cannot trust anybody
06486d
  - the auto-loaded file may change the output format
06486d
  - security?
06486d
2. bugs in such a files (#817)
06486d
06486d
Resolves: #1128637
06486d
06486d
Signed-off-by: Jakub Filak <jfilak@redhat.com>
06486d
---
06486d
 src/lib/hooklib.c | 40 +++++++++++++++++++++-------------------
06486d
 1 file changed, 21 insertions(+), 19 deletions(-)
06486d
06486d
diff --git a/src/lib/hooklib.c b/src/lib/hooklib.c
06486d
index 4a50727..21ad9e0 100644
06486d
--- a/src/lib/hooklib.c
06486d
+++ b/src/lib/hooklib.c
06486d
@@ -252,10 +252,12 @@ char *get_backtrace(const char *dump_dir_name, unsigned timeout_sec, const char
06486d
     /* Let user know what's going on */
06486d
     log(_("Generating backtrace"));
06486d
 
06486d
-    char *args[21];
06486d
+    char *args[23];
06486d
     args[0] = (char*)"gdb";
06486d
     args[1] = (char*)"-batch";
06486d
     args[2] = (char*)"-ex";
06486d
+    args[3] = (char*)"set auto-load off";
06486d
+    args[4] = (char*)"-ex";
06486d
     struct strbuf *set_debug_file_directory = strbuf_new();
06486d
     if(debuginfo_dirs == NULL)
06486d
     {
06486d
@@ -278,7 +280,7 @@ char *get_backtrace(const char *dump_dir_name, unsigned timeout_sec, const char
06486d
             p = colon_or_nul;
06486d
         }
06486d
     }
06486d
-    args[3] = strbuf_free_nobuf(set_debug_file_directory);
06486d
+    args[5] = strbuf_free_nobuf(set_debug_file_directory);
06486d
 
06486d
     /* "file BINARY_FILE" is needed, without it gdb cannot properly
06486d
      * unwind the stack. Currently the unwind information is located
06486d
@@ -300,27 +302,27 @@ char *get_backtrace(const char *dump_dir_name, unsigned timeout_sec, const char
06486d
      * TODO: check mtimes on COREFILE and BINARY_FILE and not supply
06486d
      * BINARY_FILE if it is newer (to at least avoid gdb complaining).
06486d
      */
06486d
-    args[4] = (char*)"-ex";
06486d
-    args[5] = xasprintf("file %s", executable);
06486d
-    free(executable);
06486d
-
06486d
     args[6] = (char*)"-ex";
06486d
-    args[7] = xasprintf("core-file %s/"FILENAME_COREDUMP, dump_dir_name);
06486d
+    args[7] = xasprintf("file %s", executable);
06486d
+    free(executable);
06486d
 
06486d
     args[8] = (char*)"-ex";
06486d
-    /*args[9] = ... see below */
06486d
+    args[9] = xasprintf("core-file %s/"FILENAME_COREDUMP, dump_dir_name);
06486d
+
06486d
     args[10] = (char*)"-ex";
06486d
-    args[11] = (char*)"info sharedlib";
06486d
-    /* glibc's abort() stores its message in __abort_msg variable */
06486d
+    /*args[11] = ... see below */
06486d
     args[12] = (char*)"-ex";
06486d
-    args[13] = (char*)"print (char*)__abort_msg";
06486d
+    args[13] = (char*)"info sharedlib";
06486d
+    /* glibc's abort() stores its message in __abort_msg variable */
06486d
     args[14] = (char*)"-ex";
06486d
-    args[15] = (char*)"print (char*)__glib_assert_msg";
06486d
+    args[15] = (char*)"print (char*)__abort_msg";
06486d
     args[16] = (char*)"-ex";
06486d
-    args[17] = (char*)"info all-registers";
06486d
+    args[17] = (char*)"print (char*)__glib_assert_msg";
06486d
     args[18] = (char*)"-ex";
06486d
-    args[19] = (char*)"disassemble";
06486d
-    args[20] = NULL;
06486d
+    args[19] = (char*)"info all-registers";
06486d
+    args[20] = (char*)"-ex";
06486d
+    args[21] = (char*)"disassemble";
06486d
+    args[22] = NULL;
06486d
 
06486d
     /* Get the backtrace, but try to cap its size */
06486d
     /* Limit bt depth. With no limit, gdb sometimes OOMs the machine */
06486d
@@ -330,9 +332,9 @@ char *get_backtrace(const char *dump_dir_name, unsigned timeout_sec, const char
06486d
     char *bt = NULL;
06486d
     while (1)
06486d
     {
06486d
-        args[9] = xasprintf("%s backtrace %u%s", thread_apply_all, bt_depth, full);
06486d
+        args[11] = xasprintf("%s backtrace %u%s", thread_apply_all, bt_depth, full);
06486d
         bt = exec_vp(args, /*redirect_stderr:*/ 1, timeout_sec, NULL);
06486d
-        free(args[9]);
06486d
+        free(args[11]);
06486d
         if ((bt && strnlen(bt, 256*1024) < 256*1024) || bt_depth <= 32)
06486d
         {
06486d
             break;
06486d
@@ -357,7 +359,7 @@ char *get_backtrace(const char *dump_dir_name, unsigned timeout_sec, const char
06486d
          * End of assembler dump.
06486d
          * (IOW: "empty" dump)
06486d
          */
06486d
-        args[19] = (char*)"disassemble $pc-20, $pc+64";
06486d
+        args[21] = (char*)"disassemble $pc-20, $pc+64";
06486d
 
06486d
         if (bt_depth <= 64 && thread_apply_all[0] != '\0')
06486d
         {
06486d
@@ -373,9 +375,9 @@ char *get_backtrace(const char *dump_dir_name, unsigned timeout_sec, const char
06486d
         }
06486d
     }
06486d
 
06486d
-    free(args[3]);
06486d
     free(args[5]);
06486d
     free(args[7]);
06486d
+    free(args[9]);
06486d
     return bt;
06486d
 }
06486d
 
06486d
-- 
06486d
1.8.3.1
06486d