From: Daniel Jacobowitz <drow@false.org>
To: gdb-patches@sourceware.org
Subject: RFC: Check permissions of .gdbinit files
Date: Mon, 30 May 2005 19:41:00 -0000 [thread overview]
Message-ID: <20050530185201.GA29332@nevyn.them.org> (raw)
Gentoo recently published a security update for GDB, citing the fact that
GDB would load .gdbinit from the current directory even if that was owned by
another user. I'm not sure how I feel about running GDB in an untrusted
directory or on untrusted binaries and expecting it to behave sensibly, but
this particular issue is easy to fix. Here's my suggested fix; it's not the
same as Gentoo's. If .gdbinit is world writable or owned by a different
user, refuse to open it (and warn the user).
Anyone have opinions on this change?
--
Daniel Jacobowitz
CodeSourcery, LLC
2005-05-30 Daniel Jacobowitz <dan@codesourcery.com>
* Makefile.in (cli-cmds.o): Update.
* 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.
Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.733
diff -u -p -r1.733 Makefile.in
--- Makefile.in 22 May 2005 20:36:18 -0000 1.733
+++ Makefile.in 30 May 2005 18:46:16 -0000
@@ -2766,7 +2766,7 @@ cli-cmds.o: $(srcdir)/cli/cli-cmds.c $(d
$(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) $(ui_out_h) $(cli_cmds_h) \
Index: main.c
===================================================================
RCS file: /cvs/src/src/gdb/main.c,v
retrieving revision 1.51
diff -u -p -r1.51 main.c
--- main.c 2 Apr 2005 20:25:22 -0000 1.51
+++ main.c 30 May 2005 18:46:16 -0000
@@ -604,7 +604,7 @@ extern int gdbtk_test (char *);
if (!inhibit_gdbinit)
{
- catch_command_errors (source_command, homeinit, 0, RETURN_MASK_ALL);
+ catch_command_errors (source_command, homeinit, -1, RETURN_MASK_ALL);
}
/* Do stats; no need to do them elsewhere since we'll only
@@ -691,7 +691,7 @@ extern int gdbtk_test (char *);
|| memcmp ((char *) &homebuf, (char *) &cwdbuf, sizeof (struct stat)))
if (!inhibit_gdbinit)
{
- catch_command_errors (source_command, gdbinit, 0, RETURN_MASK_ALL);
+ catch_command_errors (source_command, gdbinit, -1, RETURN_MASK_ALL);
}
for (i = 0; i < ncmd; i++)
Index: cli/cli-cmds.c
===================================================================
RCS file: /cvs/src/src/gdb/cli/cli-cmds.c,v
retrieving revision 1.61
diff -u -p -r1.61 cli-cmds.c
--- cli/cli-cmds.c 27 May 2005 04:39:33 -0000 1.61
+++ cli/cli-cmds.c 30 May 2005 18:46:17 -0000
@@ -37,6 +37,7 @@
#include "objfiles.h"
#include "source.h"
#include "disasm.h"
+#include "gdb_stat.h"
#include "ui-out.h"
@@ -50,6 +51,8 @@
#include "tui/tui.h" /* For tui_active et.al. */
#endif
+#include <fcntl.h>
+
/* Prototypes for local command functions */
static void complete_command (char *, int);
@@ -419,30 +422,54 @@ cd_command (char *dir, int from_tty)
pwd_command ((char *) 0, 1);
}
\f
+/* Load a GDB command file whose name is given in ARGS. FROM_TTY may
+ be -1, in which case we are loading a gdbinit file; in that case,
+ be paranoid about unsafe files. */
+
void
source_command (char *args, int from_tty)
{
- FILE *stream;
+ FILE *stream = NULL;
+ int fd;
struct cleanup *old_cleanups;
char *file = args;
if (file == NULL)
- {
- error (_("source command requires pathname of file to source."));
- }
+ error (_("source command requires pathname of file to source."));
file = tilde_expand (file);
old_cleanups = make_cleanup (xfree, file);
- stream = fopen (file, FOPEN_RT);
- if (!stream)
+ fd = open (file, O_RDONLY);
+ if (fd != -1)
+ stream = fdopen (fd, FOPEN_RT);
+ if (stream == NULL)
{
- 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);
+ fclose (stream);
+ return;
+ }
+ if (statbuf.st_uid != getuid () || (statbuf.st_mode & S_IWOTH))
+ {
+ warning (_("not using untrusted file \"%s\""), file);
+ fclose (stream);
+ return;
+ }
+ }
+#endif
+
script_from_file (stream, file);
do_cleanups (old_cleanups);
next reply other threads:[~2005-05-30 18:52 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-05-30 19:41 Daniel Jacobowitz [this message]
2005-05-30 19:46 ` Nathan J. Williams
2005-05-30 19:53 ` Daniel Jacobowitz
2005-05-30 19:54 ` Nathan J. Williams
2005-05-30 19:55 ` Daniel Jacobowitz
2005-05-30 21:28 ` Jason Molenda
2005-05-30 22:29 ` Eli Zaretskii
2005-05-30 23:00 ` Daniel Jacobowitz
2005-05-31 13:52 ` Eli Zaretskii
2005-05-31 21:03 ` Christopher Faylor
[not found] ` <umzqb9kha.fsf@gnu.org>
[not found] ` <20050531222233.GF9864@trixie.casa.cgf.cx>
2005-06-02 3:51 ` Eli Zaretskii
2005-06-02 4:26 ` Christopher Faylor
2005-06-02 21:54 ` Eli Zaretskii
2005-05-30 22:42 ` Andreas Schwab
2005-05-30 22:49 ` Daniel Jacobowitz
2005-05-31 2:27 ` Andreas Schwab
2005-05-31 2:50 ` Daniel Jacobowitz
2005-05-31 14:42 ` Bob Rossi
2005-05-31 17:54 ` Stan Shebs
2005-06-11 22:35 ` Mark Kettenis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050530185201.GA29332@nevyn.them.org \
--to=drow@false.org \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox