Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Andrew Burgess <aburgess@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 1/5] gdbserver: avoid buffer overflow from 'm' and 'x' packets
Date: Fri, 20 Nov 2026 17:37:49 +0200	[thread overview]
Message-ID: <8633svjyya.fsf@gnu.org> (raw)
In-Reply-To: <742c0f2f772ecb9365d3411aef9acad9f7e2ef6d.1795186852.git.aburgess@redhat.com> (message from Andrew Burgess on Fri, 20 Nov 2026 15:12:46 +0000)

> From: Andrew Burgess <aburgess@redhat.com>
> Cc: Andrew Burgess <aburgess@redhat.com>
> Date: Fri, 20 Nov 2026 15:12:46 +0000
> 
> In the process_serial_event function (gdbserver/server.cc), the 'm'
> and 'x' packets, which both read inferior memory, take a length from
> the incoming packet and read that much data into a fixed-size buffer.
> This read can overflow the buffer.
> 
> Cap the length to avoid this overflow.  For 'm', the length is capped
> at half the buffer size, as the result of the read is passed through
> bin2hex, which encodes each byte as two hex characters, doubling the
> space required for the result.
> 
> For 'x' the raw binary data is returned, so the full buffer size is
> available.  The binary data reply places a 'b' at the front; however,
> the outbound result buffer is actually sized to 'PBUFSIZ + 1'.  The
> '+1' in this case allows for the 'b', as a binary data packet does not
> need a trailing '\0' character.
> 
> I've added a new test gdb.server/mx-packet-overflow.exp which tests a
> number of different read request sizes with the 'm' and 'x' packets.
> ---
>  gdb/doc/gdb.texinfo                           |  16 ++
>  gdb/testsuite/gdb.server/mx-packet-overflow.c |  63 ++++++
>  .../gdb.server/mx-packet-overflow.exp         | 179 ++++++++++++++++++
>  gdbserver/server.cc                           |  15 ++
>  4 files changed, 273 insertions(+)
>  create mode 100644 gdb/testsuite/gdb.server/mx-packet-overflow.c
>  create mode 100644 gdb/testsuite/gdb.server/mx-packet-overflow.exp

Thanks, the gdb.texinfo part is okay.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>

  reply	other threads:[~2026-11-20 15:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 15:12 [PATCH 0/5] gdbserver: fix memory bugs in x, X, m, and M packet handling Andrew Burgess
2026-11-20 15:12 ` [PATCH 1/5] gdbserver: avoid buffer overflow from 'm' and 'x' packets Andrew Burgess
2026-11-20 15:37   ` Eli Zaretskii [this message]
2026-11-23  5:26   ` Kevin Buettner
2026-11-20 15:12 ` [PATCH 2/5] gdbserver: merge look_up_one_symbol and relocate_instruction packet handling Andrew Burgess
2026-11-25  5:55   ` Kevin Buettner
2026-11-26 14:58     ` Andrew Burgess
2026-11-20 15:12 ` [PATCH 3/5] gdbserver: fix buffer overflow in more m/x " Andrew Burgess
2026-11-25  7:24   ` Kevin Buettner
2026-11-20 15:12 ` [PATCH 4/5] gdbserver: reject X packets with an invalid declared length Andrew Burgess
2026-11-25  7:48   ` Kevin Buettner
2026-11-25  7:48   ` Kevin Buettner
2026-11-20 15:12 ` [PATCH 5/5] gdbserver: reject M " Andrew Burgess
2026-11-25  8:03   ` Kevin Buettner

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=8633svjyya.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=aburgess@redhat.com \
    --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