public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "bgray at linux dot ibm.com" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug shlibs/30663] Segfault when reading malformed PT_INTERP header
Date: Thu, 18 Jan 2024 04:06:17 +0000	[thread overview]
Message-ID: <bug-30663-4717-SqajFppJeD@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-30663-4717@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=30663

Benjamin Gray <bgray at linux dot ibm.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bgray at linux dot ibm.com

--- Comment #1 from Benjamin Gray <bgray at linux dot ibm.com> ---
Ran into this myself and came here to report it. My binary has a `.interp`
section, but it has size 0. The following section in gdb/solib-svr4.c
enable_break()

    std::optional<gdb::byte_vector> interp_name_holder
      = find_program_interpreter ();
    if (interp_name_holder)
      {
        const char *interp_name = (const char *) interp_name_holder->data ();

Only checks that a vector is present, not that it has allocated anything. So
interp_name is possibly a null pointer. This is propagated down the chain

solib_bfd_open()
  solib_find()
    solib_find_1()
      xstrdup()

which ultimately segfaults on the null pointer.

find_program_interpreter() itself is correctly locating the zero sized
`.interp` section, creating a gdb::byte_vector with size 0. This wraps the
std::vector type, which avoids an allocation for zero vectors. The
bfd_get_section_contents() call trivially returns true because it's 'found' the
contents of this zero sized section, so never touches the data buffer. 
(actually, it _might_ call memset() on the buffer, which is undefined behaviour
as far as I can tell after a quick search).

-- 
You are receiving this mail because:
You are on the CC list for the bug.

      reply	other threads:[~2024-01-18  4:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-21 20:03 [Bug shlibs/30663] New: " mattlloydhouse at gmail dot com
2024-01-18  4:06 ` bgray at linux dot ibm.com [this message]

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=bug-30663-4717-SqajFppJeD@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@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).