public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: Alan Modra <amodra@gmail.com>
Cc: Simon Marchi <simon.marchi@polymtl.ca>,
	"H.J. Lu" <hjl.tools@gmail.com>,
	binutils@sourceware.org, Florian Weimer <fweimer@redhat.com>,
	Kaylee Blake <klkblake@gmail.com>,
	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>,
	Ryan Goldberg <rgoldber@redhat.com>,
	Matthias Klose <doko@debian.org>,
	nickc@redhat.com
Subject: Re: [PATCH v4 3/7] bfd: Improve nm and objdump without section header
Date: Thu, 13 Jul 2023 23:58:08 +0200	[thread overview]
Message-ID: <20230713215808.GA11829@gnu.wildebeest.org> (raw)
In-Reply-To: <ZK+FYSeBoHqxk70u@squeak.grove.modra.org>

Hi,

On Thu, Jul 13, 2023 at 02:32:25PM +0930, Alan Modra via Binutils wrote:
> > So, the program header of the .debug file describes the segments of the
> > main binary, not sure if that's expected.
> 
> No, that's not expected.  Program headers in a .debug file ought to
> describe the contents of the debug file.  You'll typically see many
> with p_filesz zero.  eu-strip appears to be broken in this respect.

It is by design that eu-strip -f copies over the program headers of
the main file into the .debug file. It would be nice to tag .debug
files as such, to prevent issues like this. There is a binutils bug
about it: https://sourceware.org/bugzilla/show_bug.cgi?id=22136

> There is another problem with the code added to elf_object_p:
> _bfd_elf_get_dynamic_symbols is told that it can access up to e_phnum
> program headers, but they very likely haven't all been swapped in.
> 
> I'm going to apply the following patch.
>
> ----
> 
> elf_object_p load of dynamic symbols
> 
> This fixes an uninitialised memory access on a fuzzed file:
> 0 0xf22e9b in offset_from_vma /src/binutils-gdb/bfd/elf.c:1899:2
> 1 0xf1e90f in _bfd_elf_get_dynamic_symbols /src/binutils-gdb/bfd/elf.c:2099:13
> 2 0x10e6a54 in bfd_elf32_object_p /src/binutils-gdb/bfd/elfcode.h:851:9
> 
> Hopefully it will also stop any attempt to load dynamic symbols from
> eu-strip debug files.
> 
> 	* elfcode.h (elf_object_p): Do not attempt to load dynamic
> 	symbols for a file with no section headers until all the
> 	program headers are swapped in.  Do not fail on eu-strip debug
> 	files.

Thanks! This does resolves an elfutils/debuginfod issue Ryan and I
were tracking down on debian-testing with using binutils objcopy
extracting sections from a .debug file. Debian testing ships with
binutils 2.40.90.20230705.

If possible could this go into 2.41 (and in an update for Debian
testing)?

Thanks,

Mark

  parent reply	other threads:[~2023-07-13 21:58 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-06 17:58 [PATCH v4 0/7] ELF: Strip section header in ELF objects H.J. Lu
2023-06-06 17:58 ` [PATCH v4 1/7] " H.J. Lu
2023-06-06 17:58 ` [PATCH v4 2/7] ELF: Discard non-alloc sections without section header H.J. Lu
2023-06-06 17:58 ` [PATCH v4 3/7] bfd: Improve nm and objdump " H.J. Lu
2023-07-01  2:12   ` Simon Marchi
2023-07-07 15:26     ` H.J. Lu
2023-07-10  3:30       ` Simon Marchi
2023-07-13  5:02         ` Alan Modra
2023-07-13  5:34           ` Fangrui Song
2023-07-13 21:58           ` Mark Wielaard [this message]
2023-07-19  6:21             ` Alan Modra
2023-06-06 17:58 ` [PATCH v4 4/7] ld: Add simple tests for -z nosectionheader H.J. Lu
2023-06-06 17:58 ` [PATCH v4 5/7] binutils: Add a --strip-section-headers test H.J. Lu
2023-06-06 17:58 ` [PATCH v4 6/7] ld: Add tests for -z nosectionheader and --strip-section-headers H.J. Lu
2023-06-29 20:56   ` H.J. Lu
2023-07-06  1:27     ` Alan Modra
2023-06-06 17:58 ` [PATCH v4 7/7] ld: Add -z nosectionheader test to bootstrap.exp H.J. Lu

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=20230713215808.GA11829@gnu.wildebeest.org \
    --to=mark@klomp.org \
    --cc=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=doko@debian.org \
    --cc=fweimer@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=hjl.tools@gmail.com \
    --cc=klkblake@gmail.com \
    --cc=nickc@redhat.com \
    --cc=rgoldber@redhat.com \
    --cc=simon.marchi@polymtl.ca \
    /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).