public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Aaron Merey <amerey@redhat.com>, Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb/dwarf2: Check for missing abbrev
Date: Thu, 14 Mar 2024 13:52:48 -0400	[thread overview]
Message-ID: <c60d8b58-6c9e-476a-9708-db17d61c44af@simark.ca> (raw)
In-Reply-To: <CAJDtP-T8N=jzO+6GokBqs0XUZt0Qwx7HdJfW-ONoc=K_b=snQg@mail.gmail.com>



On 2024-03-14 13:45, Aaron Merey wrote:
> On Wed, Mar 13, 2024 at 9:47 PM Simon Marchi <simark@simark.ca> wrote:
>>
>> We generally don't make functions error out like this if they are passed
>> bad parameters (we can use gdb_assert for that if we really want to).
>> It's up to the callers to respect the contract and not pass nullptr
>> where nullptr is not expected.  So I would instead suggest to add the
>> nullptr check in the caller (in scan_attributes itself, after the
>> peek_die_abbrev call lower).
> 
> Moving the nullptr check after peek_die_abbrev is fine, but replacing
> the throw with 'return nullptr' doesn't fix the crash.  It looks like
> scan_attributes currently cannot return nullptr without triggering
> a crash.

I was not suggesting to make scan_attributes return nullptr, throwing an
error (with error() as Tom pointed out it's fine).  I was just
suggesting doing it in the caller rather than in the callee.

>> However, I'd like if we could analyze the problem a bit further to
>> understand more precisely what happens, just to be sure that there isn't
>> a more fundamental problem and we're not just papering over the problem.
>> I added instructions on the bug that should help you reproduce.
>>
>> What I see is that read_unsigned_leb128 in peek_die_abbrev unexpectedly
>> returns 0.  Is it because the corrupted file contains zeros where it
>> shouldn't?  Or is the file truncated and we are reading past the end of
>> the buffer, and there happens to be a zero there?
> 
> The corrupt debuginfo that the reporter used to reproduce this [1] is the
> same size as the non-corrupt version.  A diff of hex dumps of the
> corrupt and non-corrupt versions of the debuginfo show that the corrupt
> file differs by containing all zeros in some places.

Thanks for checking!

> On Thu, Mar 14, 2024 at 8:36 AM Tom Tromey <tom@tromey.com> wrote:
>>
>> Also, I was wondering if this case can be tested somehow.  Perhaps the
>> DWARF assembler could be modified to allow the creation of corrupted
>> debug info.  It seems to me if we're going forward with the security
>> policy, then we're going to need to test these things.
> 
> We should be able to reproduce this in a testcase by overwriting part of
> a small binary with zeros.  I'll resubmit the patch with a testcase.

It sounds difficult to produce something that will give a reliable
result.  But if you can get it working, that's cool.

In the back of my mind, I always think that we should have a repo or
archive on the side (to avoid bloating the source repository) with
sample binaries like this one.  Crafting a test binary with the DWARF
assembler has its advantages, but so is trying it on the real thing.  We
could have tests in the testsuite that would run only if you have the
binary archive repo available locally.

Simon

  reply	other threads:[~2024-03-14 17:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-13 20:18 Aaron Merey
2024-03-14  1:39 ` Simon Marchi
2024-03-14 12:31   ` Tom Tromey
2024-03-14 13:56     ` Simon Marchi
2024-03-14 14:31       ` Tom Tromey
2024-03-14 17:45         ` Aaron Merey
2024-03-14 17:52           ` Simon Marchi [this message]
2024-03-14 12:29 ` Tom Tromey
2024-03-14 12:36 ` Tom Tromey

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=c60d8b58-6c9e-476a-9708-db17d61c44af@simark.ca \
    --to=simark@simark.ca \
    --cc=amerey@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).