arrfab / rpms / abrt

Forked from rpms/abrt 5 years ago
Clone

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

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