Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Keith Seitz <keiths@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 1/5] [gdb/remote] Fix stack overflow in parse_tsv_definition
Date: Tue, 24 Nov 2026 12:07:12 +0000	[thread overview]
Message-ID: <xhuyfbj7etoun.fsf@aburgess-thinkpadp1gen8.rmtgb.csb> (raw)
In-Reply-To: <0075bc3fc2908558e86385531ee62479683149a7.1794430701.git.keiths@redhat.com>

Keith Seitz <keiths@redhat.com> writes:

> gdb/34967 demonstrates how a malicious remote stub may cause
> a stack overflow with a malformed tsv definition.
>
> parse_tsv_definition skips field separators without checking whether
> the skipped character is really the field separator.  Worse, a short
> definition such as "1:0:0000" (which is missing a colon) would point
> a buffer past the terminating NUL into leftover bytes of a reused RSP packet
> buffer. hex2bin then copied more bytes than allocated by alloca.
>
> Fix this by introducing shared helpers that require a field separator
> and report a malformed definition.  Only parse_tsv_definition is
> converted here; follow-up patches will use the same helpers for the
> remaining trace definition parsers.
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34967

Thanks for fixing this.  I have one small suggestion, see inline below.

>  
> +/* Free UTSVP, including each node's name.  */
> +
> +static void
> +cleanup_uploaded_tsvs (uploaded_tsv **utsvp)
> +{
> +  for (uploaded_tsv *utsv = *utsvp; utsv != nullptr; utsv = utsv->next)
> +    xfree (const_cast<char *> (utsv->name));
> +  free_uploaded_tsvs (utsvp);
> +}

I think it would be better to move the free of uploaded_tsv::name into
free_uploaded_tsvs, which would close a memory leak.  I took a look
through the GDB code and I think name is only ever assigned in one place
by strdup, and the name is owned entirely by the uploaded_tsv, so I
cannot see why freeing the name would cause any problems.

This could be done in this commit as it's a small enough fix.

Thanks,
Andrew


  reply	other threads:[~2026-11-24 12:07 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 [this message]
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
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=xhuyfbj7etoun.fsf@aburgess-thinkpadp1gen8.rmtgb.csb \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=keiths@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