From: Andrew Burgess <aburgess@redhat.com>
To: Kevin Buettner <kevinb@redhat.com>, gdb-patches@sourceware.org
Cc: Kevin Buettner <kevinb@redhat.com>
Subject: Re: [PATCH v2 1/1] gdbserver: reject malformed agent expressions in gdb_parse_agent_expr
Date: Sun, 22 Nov 2026 21:19:05 +0000 [thread overview]
Message-ID: <xhuyf1p8clg3a.fsf@aburgess-thinkpadp1gen8.rmtgb.csb> (raw)
In-Reply-To: <20261120084131.659727-3-kevinb@redhat.com>
Kevin Buettner <kevinb@redhat.com> writes:
> gdb_parse_agent_expr, defined in gdbserver/ax.cc, is called from four
> different sites within gdbserver, two from mem-break.cc and two from
> tracepoint.cc.
>
> Within tracepoint.cc, gdb_parse_agent_expr is called to handle the 'X'
> portion of a QTDP packet. The 'X' portion describes agent expressions
> used by tracepoints for both conditions and actions.
>
> Within mem-break.cc, it's called to handle breakpoint conditions or
> commands as part of a 'Z' packet. These conditions or commands are
> specified in a bytecode format identical to that used for agent
> expressions for tracepoints.
>
> The current implementation of gdb_parse_agent_expr contains no checks
> about validity of the length specified in the portion of a packet that
> represents an agent expression. This takes the form "X<len>,<hex>".
> (This is not an 'X' packet but, rather, a portion of the 'QTDP' packet
> for tracepoints or 'Z0' packet for breakpoints.) gdb_parse_agent_expr
> allocates LEN bytes and asks hex2bin to convert that number of bytes,
> but hex2bin stops at the end of the packet, leaving the end of the
> buffer uninitialized. For a tracepoint condition, that buffer is
> later sent back to GDB in reply to qTfP/qTsP, which are used to
> request tracepoint data. Thus, using an overly large length can
> provide access to uninitialized gdbserver heap memory, a potential
> security concern.
>
> The parse pointer is also advanced by 2 * LEN bytes regardless of how
> much data was present, so callers continue parsing from a pointer that
> can be far beyond the end of the packet; a large LEN crashes gdbserver.
>
> Fix this by having gdb_parse_agent_expr return nullptr (representing
> an error condition) when the specified length exceeds the amount of
> hex data actually present. This code also wasn't checking for the
> mandated comma character in the packet syntax. I added a check and
> error return for that too.
>
> The remainder of this patch to gdbserver consists of propagating the
> error back to various points in the code where write_enn may be
> called. This causes the error to be sent as the reply to GDB.
>
> For Z0 packet support, I removed two warning messages. One concerned
> a malformed condition and the other was about a malformed action
> (command). A malformed condition was discarded, making the breakpoint
> unconditional; similarly, a malformed action was simply dropped. The
> warning message (which might not even be seen by the user) stated
> these facts. gdbserver now returns an error response for these cases.
>
> The test case uses GDB's little-used "maintenance packet" command to
> send bad packets to gdbserver. This has been done not only for the
> tracepoint related packets, but for the Z0 (set breakpoint) packet as
> well. Z0 used to silently drop malformed packets and set a breakpoint
> without the (presumably intended, but malformed) condition or action.
> It no longer does this. Malformed conditions and actions within a
> Z0 packet now cause an error to be returned.
>
> While working on this patch, I spotted numerous other problems in
> nearby code (e.g. memory leaks and lack of packet syntax checking).
> I left these alone. gdbserver desperately needs attention to fix
> myriad problems.
>
> This fixes the bug associated with CVE-2026-121996.
>
> Regression tested on x86_64 Fedora 44. The new test case was tested
> on RISC-V Fedora 42, for which neither Z0 packets nor tracepoint
> packets are implemented.
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34969
Hi Kevin,
Thanks for working on this. I agree that the gdbserver code is in need
of some serious updates, but you cannot be expected to fix everything in
one go. I think this fix is basically sound. I do have a couple of
minor nits (see inline below), but I think once these are resolved:
Approved-By: Andrew Burgess <aburgess@redhat.com>
> +# Send out Z0 / z0 (breakpoint) packets for this test. Use "main" for the
> +# address at which to place the breakpoint.
> +proc test_Z0 {exp testname} {
> + with_test_prefix $testname {
> + prepare_server
> + set addr [format %x [get_hexadecimal_valueof "&main" 0]]
Is the 'format' really needed here? Doesn't get_hexadecimal_valueof
return a value in hex format?
> +
> +# Check whether gdbserver supports the Z0 packet; return 1 if so, otherwise
> +# return 0 and show that tests involving Z0 packets are unsupported.
Throughout this file: TCL supports true/false, so you don't need to use 1/0.
> diff --git a/gdbserver/tracepoint.cc b/gdbserver/tracepoint.cc
> index 6f657257ee8..4cd1722869b 100644
> --- a/gdbserver/tracepoint.cc
> +++ b/gdbserver/tracepoint.cc
> @@ -1802,7 +1802,7 @@ find_next_tracepoint_by_number (struct tracepoint *prev_tp, int num)
>
> /* Append another action to perform when the tracepoint triggers. */
>
> -static void
> +static bool
> add_tracepoint_action (struct tracepoint *tpoint, const char *packet)
The header comment for this function should be updated to reflect the
change in return type.
Thanks,
Andrew
next prev parent reply other threads:[~2026-11-22 21:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 8:14 [PATCH v2 0/1] PR gdb/server/34969 Kevin Buettner
2026-11-20 8:14 ` [PATCH v2 1/1] gdbserver: reject malformed agent expressions in gdb_parse_agent_expr Kevin Buettner
2026-11-22 21:19 ` Andrew Burgess [this message]
2026-11-24 18:56 ` 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=xhuyf1p8clg3a.fsf@aburgess-thinkpadp1gen8.rmtgb.csb \
--to=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=kevinb@redhat.com \
/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