public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: gdb-patches@sourceware.org
Subject: [PATCH] Fix buffer overrun in fetch_register_using_p
Date: Wed, 10 Oct 2018 15:46:00 -0000	[thread overview]
Message-ID: <20181010154553.11515-1-richard.henderson@linaro.org> (raw)

If the packet returned from the gdbserver is too long,
the stack would be clobbered and gdb would crash.

gdb/
	* remote.c (remote_target::fetch_register_using_p): Error if
	more data is received than expected in the packet.
---

I am adding SVE support to QEMU's gdbserver stub, and managed to
tickle this bug in the process.


r~

---
 gdb/remote.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gdb/remote.c b/gdb/remote.c
index 724f41cf71..d68faf1046 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -7958,7 +7958,8 @@ remote_target::fetch_register_using_p (struct regcache *regcache,
   struct gdbarch *gdbarch = regcache->arch ();
   struct remote_state *rs = get_remote_state ();
   char *buf, *p;
-  gdb_byte *regp = (gdb_byte *) alloca (register_size (gdbarch, reg->regnum));
+  int size = register_size (gdbarch, reg->regnum);
+  gdb_byte *regp = (gdb_byte *) alloca (size);
   int i;
 
   if (packet_support (PACKET_p) == PACKET_DISABLE)
@@ -8003,6 +8004,8 @@ remote_target::fetch_register_using_p (struct regcache *regcache,
     {
       if (p[1] == 0)
 	error (_("fetch_register_using_p: early buf termination"));
+      if (i == size)
+	error (_("fetch_register_using_p: late buf termination"));
 
       regp[i++] = fromhex (p[0]) * 16 + fromhex (p[1]);
       p += 2;
-- 
2.17.1

             reply	other threads:[~2018-10-10 15:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-10 15:46 Richard Henderson [this message]
2018-10-10 20:38 ` Simon Marchi

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=20181010154553.11515-1-richard.henderson@linaro.org \
    --to=richard.henderson@linaro.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).