Bug 33456 - [BUG] A heap-buffer-overflow in bfd_putl64 at libbfd.c:989
Summary: [BUG] A heap-buffer-overflow in bfd_putl64 at libbfd.c:989
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.45
: P2 normal
Target Milestone: 2.46
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 33465 33466 33471 (view as bug list)
Depends on:
Blocks:
 
Reported: 2025-09-18 14:41 UTC by Yifan Zhang
Modified: 2025-09-25 02:01 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed: 2025-09-23 00:00:00
Project(s) to access:
ssh public key:


Attachments
POC (2.65 KB, application/x-object)
2025-09-18 14:41 UTC, Yifan Zhang
Details
POC_patch_33457 (2.58 KB, application/x-object)
2025-09-19 13:19 UTC, Yifan Zhang
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Yifan Zhang 2025-09-18 14:41:06 UTC
Created attachment 16352 [details]
POC

## Description

- Version: Binutils 2.45
- Environment: Ubuntu 20.04.6 LTS, Clang 12.0.0

## Steps to reproduce

export CC="clang"
export CFLAGS="-g -fsanitize=address"
./configure
make -j
./ld/ld-new --version-exports-section symbol --shared $POC

## Sanitizer output

==139072==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x62100002a4e7 at pc 0x0000005d101f bp 0x7ffe081c8260 sp 0x7ffe081c8258
WRITE of size 1 at 0x62100002a4e7 thread T0
    #0 0x5d101e in bfd_putl64 /benchmark/RUNDIR-binutils-2.45/binutils-2.45/bfd/libbfd.c:989:11
    #1 0x62ee4a in elf_x86_64_finish_dynamic_symbol /benchmark/RUNDIR-binutils-2.45/binutils-2.45/bfd/elf64-x86-64.c:5519:4
    #2 0x74caa8 in elf_link_output_extsym /benchmark/RUNDIR-binutils-2.45/binutils-2.45/bfd/elflink.c:11011:14
    #3 0x5cd558 in bfd_hash_traverse /benchmark/RUNDIR-binutils-2.45/binutils-2.45/bfd/hash.c:814:8
    #4 0x735ae2 in bfd_elf_final_link /benchmark/RUNDIR-binutils-2.45/binutils-2.45/bfd/elflink.c:13258:3
    #5 0x542fc9 in ldwrite /benchmark/RUNDIR-binutils-2.45/binutils-2.45/ld/ldwrite.c:548:8
    #6 0x53a80d in main /benchmark/RUNDIR-binutils-2.45/binutils-2.45/ld/./ldmain.c:912:3
    #7 0x7f15f1440082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082)
    #8 0x41d69d in _start (/benchmark/bin/DAFL/ld-new-2025-1178+0x41d69d)

0x62100002a4e7 is located 7 bytes to the right of 4064-byte region [0x621000029500,0x62100002a4e0)
allocated by thread T0 here:
    #0 0x49916d in malloc /src/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:145:3
    #1 0x9d1bd2 in _objalloc_alloc /benchmark/RUNDIR-binutils-2.45/binutils-2.45/libiberty/./objalloc.c:159:41
    #2 0x5cf4fd in bfd_alloc /benchmark/RUNDIR-binutils-2.45/binutils-2.45/bfd/libbfd.c:453:9
    #3 0x5cf6ba in bfd_zalloc /benchmark/RUNDIR-binutils-2.45/binutils-2.45/bfd/libbfd.c:478:9
    #4 0x79f73b in alloc_trie_leaf /benchmark/RUNDIR-binutils-2.45/binutils-2.45/bfd/./dwarf2.c:153:10
    #5 0x79f73b in _bfd_dwarf2_slurp_debug_info /benchmark/RUNDIR-binutils-2.45/binutils-2.45/bfd/./dwarf2.c:5451:24
    #6 0x7ad7cc in _bfd_dwarf2_find_nearest_line_with_alt /benchmark/RUNDIR-binutils-2.45/binutils-2.45/bfd/./dwarf2.c:5817:9
    #7 0x6cd6f4 in _bfd_elf_find_nearest_line_with_alt /benchmark/RUNDIR-binutils-2.45/binutils-2.45/bfd/elf.c:9868:7
    #8 0x6cd5c1 in _bfd_elf_find_nearest_line /benchmark/RUNDIR-binutils-2.45/binutils-2.45/bfd/elf.c:9845:10
    #9 0x554f06 in vfinfo /benchmark/RUNDIR-binutils-2.45/binutils-2.45/ld/ldmisc.c:335:10
    #10 0x557a09 in einfo /benchmark/RUNDIR-binutils-2.45/binutils-2.45/ld/ldmisc.c:608:3
    #11 0x53eb5e in multiple_definition /benchmark/RUNDIR-binutils-2.45/binutils-2.45/ld/./ldmain.c
    #12 0x76a563 in _bfd_elf_merge_symbol /benchmark/RUNDIR-binutils-2.45/binutils-2.45/bfd/elflink.c:1705:7
    #13 0x7080e3 in elf_link_add_object_symbols /benchmark/RUNDIR-binutils-2.45/binutils-2.45/bfd/elflink.c:5284:9
    #14 0x7003a7 in bfd_elf_link_add_symbols /benchmark/RUNDIR-binutils-2.45/binutils-2.45/bfd/elflink.c:6416:14
    #15 0x4f9770 in load_symbols /benchmark/RUNDIR-binutils-2.45/binutils-2.45/ld/ldlang.c:3240:7
    #16 0x516363 in open_input_bfds /benchmark/RUNDIR-binutils-2.45/binutils-2.45/ld/ldlang.c:3732:13
    #17 0x50b0ce in lang_process /benchmark/RUNDIR-binutils-2.45/binutils-2.45/ld/ldlang.c:8323:3
    #18 0x53a5b4 in main /benchmark/RUNDIR-binutils-2.45/binutils-2.45/ld/./ldmain.c:882:3
    #19 0x7f15f1440082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082)

SUMMARY: AddressSanitizer: heap-buffer-overflow /benchmark/RUNDIR-binutils-2.45/binutils-2.45/bfd/libbfd.c:989:11 in bfd_putl64
Shadow bytes around the buggy address:
  0x0c427fffd440: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c427fffd450: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c427fffd460: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c427fffd470: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c427fffd480: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c427fffd490: 00 00 00 00 00 00 00 00 00 00 00 00[fa]fa fa fa
  0x0c427fffd4a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c427fffd4b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c427fffd4c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c427fffd4d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c427fffd4e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==139072==ABORTING
## Credit

Reported by Yifan Zhang, [PLL](https://pl.cs.pku.edu.cn/en/)
Comment 1 H.J. Lu 2025-09-18 23:28:43 UTC
Dup.

*** This bug has been marked as a duplicate of bug 33457 ***
Comment 2 Yifan Zhang 2025-09-19 13:18:50 UTC
After applying the patch for bug 33457, the bug can still be triggered using a new POC, which I have uploaded.
Comment 3 Yifan Zhang 2025-09-19 13:19:32 UTC
Created attachment 16362 [details]
POC_patch_33457
Comment 4 H.J. Lu 2025-09-23 01:38:52 UTC
Dup.

*** This bug has been marked as a duplicate of bug 33453 ***
Comment 5 H.J. Lu 2025-09-23 02:07:29 UTC
Reopened
Comment 6 H.J. Lu 2025-09-23 02:07:55 UTC
*** Bug 33465 has been marked as a duplicate of this bug. ***
Comment 7 H.J. Lu 2025-09-23 02:09:05 UTC
*** Bug 33466 has been marked as a duplicate of this bug. ***
Comment 8 H.J. Lu 2025-09-23 02:10:01 UTC
*** Bug 33471 has been marked as a duplicate of this bug. ***
Comment 9 Sourceware Commits 2025-09-23 20:21:49 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

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

commit 1108620d7a521f1c85d2f629031ce0fbae14e331
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Sep 23 10:05:14 2025 +0800

    elf: Disallow the empty global symbol name
    
    Reject the empty global symbol name, "".
    
            PR ld/33456
            * elflink.c (elf_link_add_object_symbols): Disallow the empty
            global symbol name.
    
    Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Comment 10 H.J. Lu 2025-09-23 20:22:38 UTC
Fixed for 2.46.
Comment 11 Sourceware Commits 2025-09-25 02:01:09 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

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

commit 72efdf166aa0ed72ecc69fc2349af6591a7a19c0
Author: Alan Modra <amodra@gmail.com>
Date:   Thu Sep 25 10:41:32 2025 +0930

    Re: elf: Disallow the empty global symbol name
    
    sparc64-linux-gnu  +FAIL: selective2
    sparc64-linux-gnu  +FAIL: selective3
    
            PR ld/33456
            * elflink.c (elf_link_add_object_symbols): Move new check later
            to give the backend add_symbol_hook a chance to remove symbols
            with empty names.