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 3/6] gdb: validate the CU vector offset when loading the .gdb_index
Date: Tue, 20 Oct 2026 15:00:16 -0400	[thread overview]
Message-ID: <72f2eb0b-315e-42c5-bd18-cb897940b68b@simark.ca> (raw)
In-Reply-To: <17ad2d9bf083c17ea90f2e8ba417b2d0231f66fa.1792356284.git.aburgess@redhat.com>

On 10/18/26 4:50 PM, Andrew Burgess wrote:
> Within the .gdb_index, the symbol table contains indexes that point to
> CU vectors within the constant pool.  Unfortunately, these indexes are
> not validated against the size of the constant pool, so a malformed
> .gdb_index can cause GDB to read outside the bounds of the .gdb_index.
> 
> This commit extends the dwarf.exp gdb_index proc to allow for the CU
> offset to be overridden, this is then used to add tests that expose
> this bug.
> 
> Finally, mapped_gdb_index::build_name_components is updated to sanity
> check the CU offset before it is used.  If we find an invalid offset
> then that symbol will be ignored.
> 
> To improve GDB's ability to catch errors I also added an assert to
> offset_view::operator[] that the whole offset_type is within the view.
> Without the build_name_components fix this assert will be triggered by
> one of the new tests.

Again, I skipped the test part for now.

> diff --git a/gdb/dwarf2/read-gdb-index.c b/gdb/dwarf2/read-gdb-index.c
> index e0895fb6aa8..343ad90847f 100644
> --- a/gdb/dwarf2/read-gdb-index.c
> +++ b/gdb/dwarf2/read-gdb-index.c
> @@ -102,6 +102,11 @@ class offset_view
>    /* Extract the INDEXth offset_type from the array.  */
>    offset_type operator[] (size_t index) const
>    {
> +    /* Ensure the whole offset_type is within the underlying bytes.  If GDB
> +       is compiled with libc++ assert then the access of M_BYTES will be

Not sure if you meant to say libstdc++ here (maybe clang's libc++ has
the same asserts, I don't know).

> +       checked, but this only guarantees that the first byte is within the
> +       array_view as it's a gdb_byte view.  */
> +    gdb_assert (index < size ());
>      const gdb_byte *bytes = &m_bytes[index * sizeof (offset_type)];
>      return (offset_type) extract_unsigned_integer (bytes,
>  						   sizeof (offset_type),
> @@ -273,7 +278,22 @@ mapped_gdb_index::build_name_components (dwarf2_per_objfile *per_objfile)
>        gdb_assert (components.size () > 0);
>  
>        std::vector<cooked_index_entry *> these_entries;
> -      offset_view vec (constant_pool.slice (symbol_vec_index (idx)));
> +
> +      offset_type vec_index = symbol_vec_index (idx);
> +      /* The CU vector starts with an offset_type length word.  Check that
> +	 VEC_INDEX lands inside CONSTANT_POOL, and that there is at least an
> +	 offset_type worth of bytes beyond this in CONSTANT_POOL to be
> +	 read.  */
> +      if (vec_index >= constant_pool.size ()
> +	  || constant_pool.size () - vec_index < sizeof (offset_type))

Can this be simplified to just:

  if (vec_index + sizeof (offset_type) > constant_pool.size ())
    {
      // bad
    }

Simon

  reply	other threads:[~2026-10-20 19:00 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 [this message]
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=72f2eb0b-315e-42c5-bd18-cb897940b68b@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