Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Andrew Burgess <aburgess@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 2/6] gdb: handle incorrect CU size in .gdb_index
Date: Tue, 20 Oct 2026 14:50:18 -0400	[thread overview]
Message-ID: <df1df418-6c7e-4f29-b248-24177fdcb6d6@simark.ca> (raw)
In-Reply-To: <88ff5bde0bbf7a68181ac199bc7facba4fa55432.1792356284.git.aburgess@redhat.com>

On 10/18/26 4:50 PM, Andrew Burgess wrote:
> The CU list within the .gdb_index contains the offset of a CU and the
> length of the CU.
> 
> The length field is not needed when parsing the .gdb_index, it is
> currently only used within GDB to pre-fill the length field of the
> dwarf2_per_cu object.  This pre-filled length is then validated in
> dwarf2_per_cu::set_length when the real CU header is read from the
> .debug_info.
> 
> Unfortunately, this validation is currently done using a gdb_assert,
> which is the wrong approach.  Both the .gdb_index and the CU header
> are untrusted external input.  Either of them (or both of them) might
> be wrong, and though they should have the same value, this is not
> guaranteed.
> 
> I cannot just replace the gdb_assert in dwarf2_per_cu::set_length with
> a call to complaint, there are other paths where the length is
> pre-filled from the actual CU header, in this case there should be no
> possibility of a mismatch, and so gdb_assert is the correct approach.
> 
> I could add a new member variable to dwarf2_per_cu that tracks if the
> pre-filled length came from the real CU header or from the .gdb_index,
> then we could switch on this to either call gdb_assert or complaint.
> 
> But this seemed excessive when complaints are usually turned off by
> default.
> 
> Instead, I propose we just ignore the CU length from the .gdb_index,
> and pass 0 instead when initially creating the dwarf2_per_cu object.
> A length of 0 indicates that the CU length is unknown.  When GDB reads
> the actual CU header it will then set the length at this point.
> 
> The CU length in the .gdb_index is no longer being used, but I am not
> proposing that we change the .gdb_index format, though we could in
> theory bump the index version number and remove the CU length, saving
> a little space.  However, changing the index format means more work
> for downstream tools that read or write .gdb_index sections, so
> avoiding that churn seems best to me.

I think this is ok, dwarf2_find_containing_unit (one of the only
things that uses a unit's length) is ready for this.

Simon

  reply	other threads:[~2026-10-20 18:50 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-18 20:50 [PATCH 0/6] Improved error handling for .gdb_index parsing Andrew Burgess
2026-10-18 20:50 ` [PATCH 1/6] gdb: a number of fixes " Andrew Burgess
2026-10-20 18:39   ` Simon Marchi
2026-10-18 20:50 ` [PATCH 2/6] gdb: handle incorrect CU size in .gdb_index Andrew Burgess
2026-10-20 18:50   ` Simon Marchi [this message]
2026-10-18 20:50 ` [PATCH 3/6] gdb: validate the CU vector offset when loading the .gdb_index Andrew Burgess
2026-10-20 19:00   ` Simon Marchi
2026-10-18 20:50 ` [PATCH 4/6] gdb: address table parsing fixes and tests for .gdb_index Andrew Burgess
2026-10-20 19:09   ` Simon Marchi
2026-10-18 20:50 ` [PATCH 5/6] gdb: handle corrupted .gdb_index header offsets Andrew Burgess
2026-10-20 19:23   ` Simon Marchi
2026-10-18 20:50 ` [PATCH 6/6] gdb: extend .gdb_index tests to skip all data blocks Andrew Burgess
2026-10-20 19:32   ` Simon Marchi

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=df1df418-6c7e-4f29-b248-24177fdcb6d6@simark.ca \
    --to=simark@simark.ca \
    --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