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 5/6] gdb: handle corrupted .gdb_index header offsets
Date: Tue, 20 Oct 2026 15:23:17 -0400	[thread overview]
Message-ID: <405910c8-c69b-47c3-ad5b-ba7e8200b492@simark.ca> (raw)
In-Reply-To: <b222c954bf141b5c8056e79a087abd60090423f5.1792356284.git.aburgess@redhat.com>

On 10/18/26 4:50 PM, Andrew Burgess wrote:
> The .gdb_index section has a header.  The header is a list of offsets
> into the .gdb_index section.  Currently GDB has basically no error
> checking of these offsets, the offsets can point outside the
> .gdb_index section and GDB will usually try to do something bad as a
> result.
> 
> Most often a bad offset will result in GDB trying to allocate a huge
> amount of memory.  Indeed, I don't recommend running these new tests
> on an unpatched GDB; I managed to bring down my machine due to
> excessive memory allocation.
> 
> I've added a mechanism to the gdb_index proc (in lib/dwarf.exp) to
> allow the various .gdb_index header offsets to be overridden.  Then I
> made use of this in gdb.dwarf2/gdb-index-corrupted.exp to override
> each offset in turn.
> 
> I also added a new test gdb.dwarf2/gdb-index-tiny-header.exp which
> tests with a .gdb_index sized between 0 and 28 bytes (inclusive).
> This covers indexes that are too small to even hold a valid version
> number field, and indexes upto the size of the full header block.  All
> of these indexes are too small to hold useful data so GDB should
> reject them all (without crashing).
> 
> The changes in gdb/dwarf2/read-gdb-index.c are fairly straightforward;
> check the .gdb_index is big enough for the version field, then use the
> version field to check that we have all of the offsets, and that the
> offsets point within the .gdb_index section.
> 
> Also, as the data areas that the .gdb_index header offsets point to
> are arranged in offset order, I also check that offsets are always
> equal or increasing in value.

Claude suggested this as follow-up:

  - Pre-existing, non-blocking (follow-up): the CU list size isn't
    checked to be a multiple of 16, nor the TU list a multiple of 24.
    create_cus_from_gdb_index_list (i += 2 over size/8 elements) and the
    TU loop  (read-gdb-index.c:721, i += 3) then read up to 16 bytes
    past the end of the block. For the dwz index nothing has to follow
    the CU list, so the read can go past the end of the section. This
    patch is the natural place to add that check.

I think that makes sense, it could be a follow-up.  We could decide to
reject the index entirely, or just ignore the incomplete entries at the
end.

> @@ -513,6 +529,49 @@ read_gdb_index_from_buffer (const char *filename,
>  
>    map->version = version;
>  
> +  /* The .gdb_index header is a version number followed by a series of
> +     offsets into the .gdb_index section.  Each header offset points to a
> +     data block, and the offset order, and the data block order are the
> +     same.  This means that each offset must be greater than, or equal to
> +     the previous.  The first offset should point to the first byte after
> +     the .gdb_index header.  None of the header offsets should point outside
> +     of the .gdb_index section.
> +
> +     If any of these requirements are not met then GDB can end either
> +     crashing by accessing invalid memory, or trying to allocate a huge

Missing "up", "can end up either crashing".

Simon

  reply	other threads:[~2026-10-20 19:23 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
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 [this message]
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=405910c8-c69b-47c3-ad5b-ba7e8200b492@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