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

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