https://sourceware.org/bugzilla/show_bug.cgi?id=29882
Bug ID: 29882 Summary: Out of bound read at `case DST__K_SRC_DECLFILE` handler in function `parse_module` Product: binutils Version: 2.40 (HEAD) Status: UNCONFIRMED Severity: normal Priority: P2 Component: binutils Assignee: unassigned at sourceware dot org Reporter: r3tr0spect2019 at gmail dot com Target Milestone: --- Created attachment 14503 --> https://sourceware.org/bugzilla/attachment.cgi?id=14503&action=edit PoC # Reproduce ```bash cd binutils-gdb git reset --hard f2f58a399cf3f946983398cdfe52d0eaa72bf877 mkdir build && cd build ../configure --disable-gdb --disable-gdbserver --disable-gdbsupport --disable-libdecnumber --disable-readline --disable-sim --disable-libbacktrace --disable-gas --disable-ld --disable-werror --enable-targets=all CPPFLAGS=-DDEBUG CFLAGS="-g -O0 -fsanitize=address" make all-binutils MAKEINFO=true && true binutils/addr2line -e poc.bin 0 ``` # Output ``` binutils/addr2line: unknown source command 0 binutils/addr2line: unknown source command 0 binutils/addr2line: unknown source command 0 binutils/addr2line: unknown source command 0 binutils/addr2line: unknown source command 0 binutils/addr2line: unknown source command 0 binutils/addr2line: unknown source command 104 binutils/addr2line: unknown source command 0 binutils/addr2line: unknown source command 0 binutils/addr2line: unknown source command 0 binutils/addr2line: unknown source command 15 binutils/addr2line: unknown source command 0 binutils/addr2line: unknown source command 0 binutils/addr2line: unknown source command 0 binutils/addr2line: unknown source command 0 binutils/addr2line: unknown source command 0 binutils/addr2line: unknown source command 0 binutils/addr2line: unknown source command 0 binutils/addr2line: unknown source command 0 binutils/addr2line: unknown source command 0 binutils/addr2line: unknown source command 0 binutils/addr2line: unknown source command 0 binutils/addr2line: unknown source command 0 binutils/addr2line: unknown source command 0 binutils/addr2line: unknown source command 0 binutils/addr2line: unknown source command 91 binutils/addr2line: unknown source command 0 ================================================================= ==177878==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x61a000000b83 at pc 0x55d65a5bf97c bp 0x7ffd028b3480 sp 0x7ffd028b3470 READ of size 1 at 0x61a000000b83 thread T0 #0 0x55d65a5bf97b in _bfd_vms_save_counted_string ../../bfd/vms-misc.c:170 #1 0x55d659f183cb in parse_module ../../bfd/vms-alpha.c:4457 #2 0x55d659f19fad in module_find_nearest_line ../../bfd/vms-alpha.c:4902 #3 0x55d659f1a911 in _bfd_vms_find_nearest_line ../../bfd/vms-alpha.c:4982 #4 0x55d659946b1e in find_address_in_section ../../binutils/addr2line.c:197 #5 0x55d659961f43 in bfd_map_over_sections ../../bfd/section.c:1366 #6 0x55d6599478eb in translate_addresses ../../binutils/addr2line.c:337 #7 0x55d659947fbc in process_file ../../binutils/addr2line.c:470 #8 0x55d6599485b1 in main ../../binutils/addr2line.c:579 #9 0x7f1b1ce60d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 #10 0x7f1b1ce60e3f in __libc_start_main_impl ../csu/libc-start.c:392 #11 0x55d659946244 in _start (/binutils-gdb/build/binutils/addr2line+0x343244) 0x61a000000b83 is located 3 bytes to the right of 1280-byte region [0x61a000000680,0x61a000000b80) allocated by thread T0 here: #0 0x7f1b1d113867 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145 #1 0x55d6599588d5 in bfd_malloc ../../bfd/libbfd.c:289 #2 0x55d659f0313a in _bfd_malloc_and_read ../../bfd/libbfd.h:970 #3 0x55d659f19f77 in module_find_nearest_line ../../bfd/vms-alpha.c:4896 #4 0x55d659f1a911 in _bfd_vms_find_nearest_line ../../bfd/vms-alpha.c:4982 #5 0x55d659946b1e in find_address_in_section ../../binutils/addr2line.c:197 #6 0x55d659961f43 in bfd_map_over_sections ../../bfd/section.c:1366 #7 0x55d6599478eb in translate_addresses ../../binutils/addr2line.c:337 #8 0x55d659947fbc in process_file ../../binutils/addr2line.c:470 #9 0x55d6599485b1 in main ../../binutils/addr2line.c:579 #10 0x7f1b1ce60d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 SUMMARY: AddressSanitizer: heap-buffer-overflow ../../bfd/vms-misc.c:170 in _bfd_vms_save_counted_string Shadow bytes around the buggy address: 0x0c347fff8120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c347fff8130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c347fff8140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c347fff8150: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c347fff8160: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 =>0x0c347fff8170:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c347fff8180: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c347fff8190: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c347fff81a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c347fff81b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c347fff81c0: 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 ==177878==ABORTING Aborted (core dumped) ``` # Analysis `src_ptr + DST_S_B_SRC_DF_FILENAME` is accessed via `_bfd_vms_save_counted_string` without bound checking.[1] If `src_ptr + DST_S_B_SRC_DF_FILENAME` is larger than `ptr + rec_length`, the `maxlen` argument can overflow and thus be very large. Same overflow also happens at `bfd_getl16` above.[2] [1] https://github.com/bminor/binutils-gdb/blob/85f9067d3a47d51a46ba369c60fdec752da0f885/bfd/vms-alpha.c#L4459 [2] https://github.com/bminor/binutils-gdb/blob/85f9067d3a47d51a46ba369c60fdec752da0f885/bfd/vms-alpha.c#L4456 -- You are receiving this mail because: You are on the CC list for the bug.