summaryrefslogtreecommitdiff
path: root/patches/gdb/6.8/110-security-errata-20050610.patch
blob: 27e8174a3230639fcb16b4ee02adf6d0e8947b5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
Original patch from gentoo: gentoo/src/patchsets/gdb/6.8/35_all_gdb-6.3-security-errata-20050610.patch
-= BEGIN original header =-
2005-06-09  Jeff Johnston  <jjohnstn@redhat.com>

        * gdb.base/gdbinit.exp: New testcase.
        * gdb.base/gdbinit.sample: Sample .gdbinit for gdbinit.exp.

2005-06-08  Daniel Jacobowitz  <dan@codesourcery.com>
            Jeff Johnston  <jjohnstn@redhat.com>

        * Makefile.in (cli-cmds.o): Update.
        * configure.in: Add check for getuid.
        * configure: Regenerated.
        * config.in: Ditto.
        * main.c (captured_main): Pass -1 to source_command when loading
        gdbinit files.
        * cli/cli-cmds.c: Include "gdb_stat.h" and <fcntl.h>.
        (source_command): Update documentation.  Check permissions if
        FROM_TTY is -1.

-= END original header =-
diff -durN gdb-6.8.orig/gdb/Makefile.in gdb-6.8/gdb/Makefile.in
--- gdb-6.8.orig/gdb/Makefile.in	2008-03-17 13:15:08.000000000 +0100
+++ gdb-6.8/gdb/Makefile.in	2008-06-17 16:07:33.000000000 +0200
@@ -3004,7 +3004,7 @@
 	$(expression_h) $(frame_h) $(value_h) $(language_h) $(filenames_h) \
 	$(objfiles_h) $(source_h) $(disasm_h) $(ui_out_h) $(top_h) \
 	$(cli_decode_h) $(cli_script_h) $(cli_setshow_h) $(cli_cmds_h) \
-	$(tui_h)
+	$(tui_h) $(gdb_stat_h)
 	$(CC) -c $(INTERNAL_CFLAGS) $(srcdir)/cli/cli-cmds.c
 cli-decode.o: $(srcdir)/cli/cli-decode.c $(defs_h) $(symtab_h) \
 	$(gdb_regex_h) $(gdb_string_h) $(completer_h) $(ui_out_h) \
diff -durN gdb-6.8.orig/gdb/cli/cli-cmds.c gdb-6.8/gdb/cli/cli-cmds.c
--- gdb-6.8.orig/gdb/cli/cli-cmds.c	2008-01-01 23:53:14.000000000 +0100
+++ gdb-6.8/gdb/cli/cli-cmds.c	2008-06-17 16:07:33.000000000 +0200
@@ -36,6 +36,7 @@
 #include "objfiles.h"
 #include "source.h"
 #include "disasm.h"
+#include "gdb_stat.h"
 
 #include "ui-out.h"
 
@@ -459,12 +460,31 @@
 
   if (fd == -1)
     {
-      if (from_tty)
+      if (from_tty > 0)
 	perror_with_name (file);
       else
 	return;
     }
 
+#ifdef HAVE_GETUID
+  if (from_tty == -1)
+    {
+      struct stat statbuf;
+      if (fstat (fd, &statbuf) < 0)
+	{
+	  perror_with_name (file);
+	  close (fd);
+	  return;
+	}
+      if (statbuf.st_uid != getuid () || (statbuf.st_mode & S_IWOTH))
+	{
+          warning (_("not using untrusted file \"%s\""), file);
+	  close (fd);
+	  return;
+	}
+    }
+#endif
+
   stream = fdopen (fd, FOPEN_RT);
   script_from_file (stream, file);
 
diff -durN gdb-6.8.orig/gdb/main.c gdb-6.8/gdb/main.c
--- gdb-6.8.orig/gdb/main.c	2008-01-05 17:49:53.000000000 +0100
+++ gdb-6.8/gdb/main.c	2008-06-17 16:07:33.000000000 +0200
@@ -690,7 +690,7 @@
 
       if (!inhibit_gdbinit)
 	{
-	  catch_command_errors (source_script, homeinit, 0, RETURN_MASK_ALL);
+	  catch_command_errors (source_script, homeinit, -1, RETURN_MASK_ALL);
 	}
 
       /* Do stats; no need to do them elsewhere since we'll only
@@ -778,7 +778,7 @@
       || memcmp ((char *) &homebuf, (char *) &cwdbuf, sizeof (struct stat)))
     if (!inhibit_gdbinit)
       {
-	catch_command_errors (source_script, gdbinit, 0, RETURN_MASK_ALL);
+	catch_command_errors (source_script, gdbinit, -1, RETURN_MASK_ALL);
       }
 
   for (i = 0; i < ncmd; i++)
diff -durN gdb-6.8.orig/gdb/testsuite/gdb.base/gdbinit.exp gdb-6.8/gdb/testsuite/gdb.base/gdbinit.exp
--- gdb-6.8.orig/gdb/testsuite/gdb.base/gdbinit.exp	1970-01-01 01:00:00.000000000 +0100
+++ gdb-6.8/gdb/testsuite/gdb.base/gdbinit.exp	2008-06-17 16:07:33.000000000 +0200
@@ -0,0 +1,98 @@
+#   Copyright 2005
+#   Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
+
+# Please email any bugs, comments, and/or additions to this file to:
+# bug-gdb@prep.ai.mit.edu
+
+# This file was written by Jeff Johnston <jjohnstn@redhat.com>.
+
+if $tracelevel then {
+    strace $tracelevel
+}
+
+set prms_id 0
+set bug_id 0
+
+# are we on a target board
+if [is_remote target] {
+    return
+}
+
+
+global verbose
+global GDB
+global GDBFLAGS
+global gdb_prompt
+global timeout
+global gdb_spawn_id;
+                                                                                
+gdb_stop_suppressing_tests;
+                                                                                
+verbose "Spawning $GDB -nw"
+                                                                                
+if [info exists gdb_spawn_id] {
+    return 0;
+}
+                                                                                
+if ![is_remote host] {
+   if { [which $GDB] == 0 } then {
+        perror "$GDB does not exist."
+        exit 1
+    }
+}
+
+set env(HOME) [pwd]
+remote_exec build "rm .gdbinit"
+remote_exec build "cp ${srcdir}/${subdir}/gdbinit.sample .gdbinit"
+remote_exec build "chmod 646 .gdbinit"
+
+set res [remote_spawn host "$GDB -nw [host_info gdb_opts]"];
+if { $res < 0 || $res == "" } {
+    perror "Spawning $GDB failed."
+    return 1;
+}
+gdb_expect 360 {
+    -re "warning: not using untrusted file.*\.gdbinit.*\[\r\n\]$gdb_prompt $" {
+        pass "untrusted .gdbinit caught."
+    }
+    -re "$gdb_prompt $"     {
+        fail "untrusted .gdbinit caught."
+    }
+    timeout {
+        fail "(timeout) untrusted .gdbinit caught."
+    }
+}
+
+remote_exec build "chmod 644 .gdbinit"
+set res [remote_spawn host "$GDB -nw [host_info gdb_opts]"];
+if { $res < 0 || $res == "" } {
+    perror "Spawning $GDB failed."
+    return 1;
+}
+gdb_expect 360 {
+    -re "warning: not using untrusted file.*\.gdbinit.*\[\r\n\]$gdb_prompt $" {
+        fail "trusted .gdbinit allowed."
+    }
+    -re "in gdbinit.*$gdb_prompt $"     {
+        pass "trusted .gdbinit allowed."
+    }
+    timeout {
+        fail "(timeout) trusted .gdbinit allowed."
+    }
+}
+
+remote_exec build "rm .gdbinit"
diff -durN gdb-6.8.orig/gdb/testsuite/gdb.base/gdbinit.sample gdb-6.8/gdb/testsuite/gdb.base/gdbinit.sample
--- gdb-6.8.orig/gdb/testsuite/gdb.base/gdbinit.sample	1970-01-01 01:00:00.000000000 +0100
+++ gdb-6.8/gdb/testsuite/gdb.base/gdbinit.sample	2008-06-17 16:07:33.000000000 +0200
@@ -0,0 +1 @@
+echo "\nin gdbinit"