public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: "Daniel Xu" <dxu@dxuuu.xyz>
To: elfutils-devel@sourceware.org
Subject: Noop round trip through elf_update() causes segfaults
Date: Wed, 27 Dec 2023 20:40:09 -0600	[thread overview]
Message-ID: <43591825-18a6-4dbd-b27c-fa96d150dc31@app.fastmail.com> (raw)

Hi,

I was working on code that adds an ELF section containing custom
metadata to ELF binaries when I started getting odd segfaults
in the added-to binary.

I've managed to create a minimal reproducer with a couple interesting
discoveries. The reproducer is available here:

        https://github.com/danobi/elf-segfault

Basically it does a noop round trip between elf_begin() and elf_update().
But the resulting binary, when run, outputs:

        $ ./testprog_copy
        fish: Job 1, './testprog_copy' terminated by signal SIGSEGV (Address boundary error)

Furthermore, I built and ran tests/addsections.c [0] against my testbinary
and I still get:

        $ ./testprog_copy_elfutils
        fish: Job 1, './testprog_copy_elfutils' terminated by signal SIGSEGV (Address boundary error)
 
I've also tried linking against upstream libelf built from source
with the same results.

This leads me to believe I'm doing something very wrong or
I'm hitting a bug.

If it's helps, I'm using elfutils on archlinux with the following
package information:

        $ pacman -Qi libelf
        Name            : libelf
        Version         : 0.190-1
        Description     : Handle ELF object files and DWARF debugging information (libraries)
        Architecture    : x86_64
        URL             : https://sourceware.org/elfutils/
        [...]

[0]: https://sourceware.org/git/?p=elfutils.git;a=blob;f=tests/addsections.c;hb=HEAD

Thanks,
Daniel

             reply	other threads:[~2023-12-28  2:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-28  2:40 Daniel Xu [this message]
2023-12-30 17:41 ` Mark Wielaard
2023-12-31  5:16   ` Daniel Xu

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=43591825-18a6-4dbd-b27c-fa96d150dc31@app.fastmail.com \
    --to=dxu@dxuuu.xyz \
    --cc=elfutils-devel@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).