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

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