public inbox for insight@sourceware.org
 help / color / mirror / Atom feed
From: "Andrew Burgess" <aburgess@broadcom.com>
To: insight@sourceware.org
Subject: [PATCH 1/2] Add an assert that we're not overflowing the register cache.
Date: Thu, 05 Sep 2013 14:26:00 -0000	[thread overview]
Message-ID: <5228947C.8040706@broadcom.com> (raw)
In-Reply-To: <5228941F.8080601@broadcom.com>

I'm running on x86-64 linux, and I'm building with --enable-targets=all
(not sure if this makes a difference).  As I start up insight the
setup_architecture_data method is called, and this allocates a register
cache, however, at this point, without know what target binary will be
loaded the exact number of target registers is unknown.

Next I load up a target executable, and run to main.

Finally, I open up the register window.  At this point an attempt is
made to access the register cache for all available registers, however,
the number of registers has grown as a result of loading a target
executable, insight then proceeds to corrupt a random area of memory
off the end of the register cache.

This patch doesn't fix the issue, but adds an assert to detect the bug.

OK to apply?

Thanks,
Andrew

gdb/gdbtk/ChangeLog

2013-09-05  Andrew Burgess  <aburgess@broadcom.com>
 
	* generic/gdbk-register.c (old_regs_count): New variable.
	(register_changed_p): Add new assert.
	(setup_architecture_data): Initialise old_regs_count.
 
Index: ./gdb/gdbtk/generic/gdbtk-register.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-register.c,v
retrieving revision 1.48
diff -u -p -r1.48 gdbtk-register.c
--- ./gdb/gdbtk/generic/gdbtk-register.c	5 Sep 2013 13:14:28 -0000	1.48
+++ ./gdb/gdbtk/generic/gdbtk-register.c	5 Sep 2013 13:46:08 -0000
@@ -63,6 +63,7 @@ static void get_register_types (int regn
    It is an array of (NUM_REGS+NUM_PSEUDO_REGS)*MAX_REGISTER_RAW_SIZE bytes. */
 
 static char *old_regs = NULL;
+static int old_regs_count = 0;
 static int *regformat = (int *)NULL;
 static struct type **regtype = (struct type **)NULL;
 
@@ -443,6 +444,7 @@ static void
 register_changed_p (int regnum, map_arg arg)
 {
   gdb_byte raw_buffer[MAX_REGISTER_SIZE];
+  gdb_assert (regnum < old_regs_count);
 
   if (!target_has_registers
       || !deprecated_frame_register_read (get_selected_frame (NULL), regnum,
@@ -472,6 +474,7 @@ setup_architecture_data (void)
 
   numregs = (gdbarch_num_regs (get_current_arch ())
 	     + gdbarch_num_pseudo_regs (get_current_arch ()));
+  old_regs_count = numregs;
   old_regs = xcalloc (1, numregs * MAX_REGISTER_SIZE + 1);
   regformat = (int *)xcalloc (numregs, sizeof(int));
   regtype = (struct type **)xcalloc (numregs, sizeof(struct type **));



  reply	other threads:[~2013-09-05 14:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-05 14:24 [PATCH 0/2] Memory corruption caused by failure to notice architecture change Andrew Burgess
2013-09-05 14:26 ` Andrew Burgess [this message]
2013-09-05 18:55   ` [PATCH 1/2] Add an assert that we're not overflowing the register cache Keith Seitz
2013-09-06  9:36     ` Andrew Burgess
2013-09-05 14:27 ` [PATCH 2/2] Notice architecture changes even when the register window is not open Andrew Burgess
2013-09-05 19:53   ` Keith Seitz
2013-09-06  9:21     ` Andrew Burgess
2013-09-06  9:40     ` Andrew Burgess

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=5228947C.8040706@broadcom.com \
    --to=aburgess@broadcom.com \
    --cc=insight@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).