Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Keith Seitz <keiths@redhat.com>
To: Andrew Burgess <aburgess@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 2/5] [gdb/remote] Fix stack overflow in parse_tracepoint_definition
Date: Tue, 24 Nov 2026 11:28:47 -0800	[thread overview]
Message-ID: <ff3c7bf8-5f4c-4455-a74b-7899735f431b@redhat.com> (raw)
In-Reply-To: <xhuyf8q2ithj2.fsf@aburgess-thinkpadp1gen8.rmtgb.csb>

Hi,

Thank you for the review. I'd like to give you my opinion
on your follow-up question below.

On 11/24/26 6:45 AM, Andrew Burgess wrote:
>> @@ -3501,24 +3507,20 @@ parse_tracepoint_definition (const char *line, struct uploaded_tp **utpp)
>>         /* Parse a chunk of source form definition.  */
>>         utp = get_uploaded_tp (num, addr, utpp);
>>         srctype = p;
>> -      p = strchr (p, ':');
>> -      p++;  /* skip a colon */
>> +      p = require (strchr (p, ':'));
>>         p = unpack_varlen_hex (p, &start);
>> -      p++;  /* skip a colon */
>> +      p = require (p);
>>         p = unpack_varlen_hex (p, &xlen);
>> -      p++;  /* skip a colon */
>> -
>> -      buf = (char *) alloca (strlen (line));
>> +      p = require (p);
>>   
>> -      end = hex2bin (p, (gdb_byte *) buf, strlen (p) / 2);
>> -      buf[end] = '\0';
>> +      std::string decoded = hex2str (p);
> 
> Maybe I'm looking in the wrong place, but I couldn't find the
> specification for this 'Z' case anywhere, so I'm guessing a little bit
> about what the fields mean.

I believe that the meaning of the fields of 'Z' follow 'QTDPsrc':

Z<n>:<addr>:<type>:<start>:<slen>:<bytes>

 From the manual (QTDPsrc):

start — offset of this packet’s bytes within the overall source string
slen (xlen in the parser) — total length of the source string
bytes — hex encoding of a chunk (possibly not the whole string)

> Still, we parse XLEN from the packet, then process the remaining bytes
> as a string.  XLEN isn't used anywhere else.  I'm assuming that XLEN is
> supposed to be the number of bytes in the string?

That's how I interpret it.

> The old code didn't check that these things matched, but maybe, as
> you're improving the code anyway, we could/should add something like:
> 
>    if (decoded.size () != xlen)
>      bad_trace_definition ("tracepoint", line);
> 
> What do you think?
Honestly, I think I'd rather not touch this because the issue isn't
quite so simple.

XLEN is the Z/QTDPsrc 'slen', the total length of the source
string in bytes.  'start' is the offset of this packet's bytes within
that string, for strings that need more than one packet.

I think the main issue here is that the code is attempting to partially
implement that multi-packet protocol possibility. It parses start and
slen, but then ignores both and hex2str's "whatever remains as if it
were the whole string" <cough>feature</cough>.

GDB's encoder always sends start=0 with the full string today,
so in practice decoded.size() == xlen is correct, but a strict
equality check would reject a valid chunked reply if that ever
did occur.

This is definitely another cleanup that could be done, but I'd prefer
to not cloud the CVE-related malformed-packet issues that this
series focuses on.

Is that acceptable?

Keith


  parent reply	other threads:[~2026-11-24 19:29 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 17:41 [PATCH 0/5] tracepoint.c hardening against missing separators Keith Seitz
2026-11-12 17:41 ` [PATCH 1/5] [gdb/remote] Fix stack overflow in parse_tsv_definition Keith Seitz
2026-11-24 12:07   ` Andrew Burgess
2026-11-12 17:41 ` [PATCH 2/5] [gdb/remote] Fix stack overflow in parse_tracepoint_definition Keith Seitz
2026-11-24 14:45   ` Andrew Burgess
2026-11-24 17:12     ` Andrew Burgess
2026-11-24 19:28     ` Keith Seitz [this message]
2026-11-12 17:41 ` [PATCH 3/5] [gdb/remote] Harden parse_static_tracepoint_marker_definition Keith Seitz
2026-11-12 17:41 ` [PATCH 4/5] [gdb/remote] Harden comma separator in parse_tracepoint_definition Keith Seitz
2026-11-12 17:41 ` [PATCH 5/5] [gdb/remote] Harden parse_tracepoint_status Keith Seitz
2026-11-24 17:14 ` [PATCH 0/5] tracepoint.c hardening against missing separators Andrew Burgess
2026-11-25 17:38   ` Keith Seitz

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=ff3c7bf8-5f4c-4455-a74b-7899735f431b@redhat.com \
    --to=keiths@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