From: Kevin Buettner <kevinb@redhat.com>
To: Andrew Burgess <aburgess@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 1/5] gdbserver: avoid buffer overflow from 'm' and 'x' packets
Date: Sun, 22 Nov 2026 22:26:03 -0700 [thread overview]
Message-ID: <8bf598ac-9352-4556-9eb8-ca012cdff357@redhat.com> (raw)
In-Reply-To: <742c0f2f772ecb9365d3411aef9acad9f7e2ef6d.1795186852.git.aburgess@redhat.com>
On 11/20/26 8:12 AM, Andrew Burgess wrote:
> 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.
I ran the entire series through my AI review workflow. For this first
commit, it found a nit in the documentation:
3. [minor, 1/5 doc] gdb.texinfo limits text is inaccurate.
SUBSTANTIALLY CONFIRMED. The added paragraphs
(gdb.texinfo:43929-43935 and :44322-44328) say "maximum supported
packet size, which is currently 131104 bytes". gdbserver advertises
PacketSize=%x with PBUFSIZ-1 = 131103 (server.cc:2764), so the
quoted number does not match what the stub reports; the text also
states a gdbserver-specific limit in the generic protocol section
without saying whose limit it is, and attributes future change to
GDB releases. The numeric mismatch is objective; the wording
judgements (b)/(c) are editorial.
You can fix that if you want. I'm not that concerned about an
off-by-one inaccuracy.
(I'm still working through the rest.)
Approved-By: Kevin Buettner <kevinb@redhat.com>
next prev parent reply other threads:[~2026-11-23 5:26 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
2026-11-23 5:26 ` Kevin Buettner [this message]
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=8bf598ac-9352-4556-9eb8-ca012cdff357@redhat.com \
--to=kevinb@redhat.com \
--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