public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@sourceware.org>
To: binutils-cvs@sourceware.org
Subject: [binutils-gdb] asan: heap buffer overflow elf_link_add_to_first_hash
Date: Thu, 11 Apr 2024 07:39:48 +0000 (GMT)	[thread overview]
Message-ID: <20240411073948.AA38D384AB62@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=de9dc65bd45c118d56600bbf1786322284fde795

commit de9dc65bd45c118d56600bbf1786322284fde795
Author: Alan Modra <amodra@gmail.com>
Date:   Thu Apr 11 16:39:18 2024 +0930

    asan: heap buffer overflow elf_link_add_to_first_hash
    
    Seen on mmix.
    mmix  +FAIL: ld-misc/defsym1
    mmix  +FAIL: sysroot-prefix common plain -Lpath, quoted
    mmix  +FAIL: sysroot-prefix common plain -Lpath, unquoted
    mmix  +FAIL: sysroot-prefix common full-path, quoted
    mmix  +FAIL: sysroot-prefix common full-path, unquoted
    mmix  +FAIL: sysroot-prefix common plain =-prefixed with empty, quoted
    mmix  +FAIL: sysroot-prefix common plain =-prefixed with empty, unquoted
    mmix  +FAIL: sysroot-prefix common plain $SYSROOT-prefixed with empty, quoted
    mmix  +FAIL: sysroot-prefix common plain $SYSROOT-prefixed with empty, unquoted
    mmix  +FAIL: sysroot-prefix common plain =-prefixed -Lpath, quoted
    mmix  +FAIL: sysroot-prefix common plain =-prefixed -Lpath, unquoted
    mmix  +FAIL: sysroot-prefix common plain $SYSROOT-prefixed -Lpath, quoted
    mmix  +FAIL: sysroot-prefix common plain $SYSROOT-prefixed -Lpath, unquoted
    mmix  +FAIL: sysroot-prefix common full-path =-prefixed without, quoted
    mmix  +FAIL: sysroot-prefix common full-path =-prefixed without, unquoted
    mmix  +FAIL: sysroot-prefix common full-path $SYSROOT-prefixed without, quoted
    mmix  +FAIL: sysroot-prefix common full-path $SYSROOT-prefixed without, unquoted
    
    ==3746597==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6070000007a0 at pc 0x56d87b0d1a40 bp 0x7fffb1629bf0 sp 0x7fffb1629be0
    READ of size 8 at 0x6070000007a0 thread T0
        #0 0x56d87b0d1a3f in elf_link_add_to_first_hash /home/alan/src/binutils-gdb/bfd/elflink.c:4312
    
    mmix uses bfd_link_generic_hash_table.
    
            * elflink.c (_bfd_elf_archive_symbol_lookup): Dont use first_hash
            unless the hash table is bfd_link_elf_hash_table.
            (elf_link_add_archive_symbols): Likewise.

Diff:
---
 bfd/elflink.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/bfd/elflink.c b/bfd/elflink.c
index 22fddb8f56b..321e3d5e2ff 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -6116,7 +6116,8 @@ _bfd_elf_archive_symbol_lookup (bfd *abfd,
     {
       /* Add this symbol to first hash if this archive has the first
 	 definition.  */
-      elf_link_add_to_first_hash (abfd, info, name, false);
+      if (is_elf_hash_table (info->hash))
+	elf_link_add_to_first_hash (abfd, info, name, false);
       return h;
     }
 
@@ -6258,6 +6259,8 @@ elf_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
 		/* Symbol must be defined.  Don't check it again.  */
 		included[i] = true;
 
+	      if (!is_elf_hash_table (info->hash))
+		continue;
 	      /* Ignore the archive if the symbol isn't defined in a
 		 shared object.  */
 	      if (!((struct elf_link_hash_entry *) h)->def_dynamic)

                 reply	other threads:[~2024-04-11  7:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20240411073948.AA38D384AB62@sourceware.org \
    --to=amodra@sourceware.org \
    --cc=binutils-cvs@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).