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

            Bug ID: 33471
           Summary: [BUG] A heap-buffer-overflow in
                    elf_x86_64_relocate_section at elf64-x86-64.c:4501
           Product: binutils
           Version: 2.45
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: yfzhang23 at stu dot pku.edu.cn
  Target Milestone: ---

Created attachment 16367
  --> https://sourceware.org/bugzilla/attachment.cgi?id=16367&action=edit
POC

## Description

- Version: Binutils 2.45 with patches in bug 33451, bug 33455, and bug 33457.
- 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 --gc-sections --no-print-gc-sections -w $POC

## Sanitizer output

==147238==ERROR: AddressSanitizer: heap-buffer-overflow on address
0x62900000f1fd at pc 0x000000637818 bp 0x7ffd392edb70 sp 0x7ffd392edb68
READ of size 1 at 0x62900000f1fd thread T0
    #0 0x637817 in elf_x86_64_relocate_section
/benchmark/bin/binutils-2.45/bfd/elf64-x86-64.c:4501:24
    #1 0x7696f4 in elf_link_input_bfd
/benchmark/bin/binutils-2.45/bfd/elflink.c:11926:10
    #2 0x75b539 in bfd_elf_final_link
/benchmark/bin/binutils-2.45/bfd/elflink.c:13185:11
    #3 0x545133 in ldwrite /benchmark/bin/binutils-2.45/ld/ldwrite.c:548:8
    #4 0x53cc51 in main /benchmark/bin/binutils-2.45/ld/./ldmain.c:912:3
    #5 0x7f7601a2f082 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x24082)
    #6 0x41d6ad in _start (/benchmark/bin/binutils-2.45/ld/ld-new+0x41d6ad)

0x62900000f1fd is located 3 bytes to the left of 16384-byte region
[0x62900000f200,0x629000013200)
allocated by thread T0 here:
    #0 0x49917d in malloc
/src/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:145:3
    #1 0x5dcf72 in bfd_malloc /benchmark/bin/binutils-2.45/bfd/libbfd.c:291:9
    #2 0x75a29e in bfd_elf_final_link
/benchmark/bin/binutils-2.45/bfd/elflink.c:13060:38
    #3 0x545133 in ldwrite /benchmark/bin/binutils-2.45/ld/ldwrite.c:548:8
    #4 0x53cc51 in main /benchmark/bin/binutils-2.45/ld/./ldmain.c:912:3
    #5 0x7f7601a2f082 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x24082)

SUMMARY: AddressSanitizer: heap-buffer-overflow
/benchmark/bin/binutils-2.45/bfd/elf64-x86-64.c:4501:24 in
elf_x86_64_relocate_section
Shadow bytes around the buggy address:
  0x0c527fff9de0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c527fff9df0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c527fff9e00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c527fff9e10: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c527fff9e20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c527fff9e30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa[fa]
  0x0c527fff9e40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c527fff9e50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c527fff9e60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c527fff9e70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c527fff9e80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
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
==147238==ABORTING

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV
/benchmark/bin/binutils-2.45/bfd/elf-eh-frame.c:2166:10 in
_bfd_elf_write_section_eh_frame
==146908==ABORTING

## Credit

Reported by Yifan Zhang, [PLL](https://pl.cs.pku.edu.cn/en/)

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

Reply via email to