Dear Maintainers,
I will disclose several issues that my sanitizer for intra-object overflow 
identified in binutils. I will attach a) a report EMAIL.md of the bugs with 
some shallow RCA based on my (and Claude Code's) understanding of your code, b) 
a zip binutils.zip with inputs that reproduce the problems so you can debug 
through them and outputs of the runs against my tool. Unfortunately, my tool is 
an ongoing research project, not available yet. It will be in the future if it 
gets into conferences.
I am available for clarifications and discussion about the found bugs.

Cheers,
Alessandro Mileto, PhD Student at VUSec
Intra-object overflows inside objects in the VAX and s390 disassemblers, readelf and the Alpha VMS writer

While fuzzing binutils' OSS-Fuzz harnesses we found out-of-bounds accesses *inside* objects (a pointer
derived from one member or array row reaching the next one) using a sanitizer for intra-object
overflows.

Configuration (same build used to find and to reproduce):

- binutils-gdb commit: `2de4446d9090b5773c863ab7bbdd95a5d4f81367` (2026-11-11), built by the OSS-Fuzz
  binutils project.
- OS / platform: Ubuntu 20.04.6 LTS, x86-64
- building & running image: `gcr.io/oss-fuzz-base/base-builder:latest@sha256:1f9cf74bc3d7029b528494542f9d9851b256dceed38d3f420989434dc5ae0760`
- reproduce: `/out/<fuzzer> <input-file>`, where `<fuzzer>` is the input's name up to the first dot.
  Inputs attached.
- detection: AFL++ with a sanitizer for intra-object overflows we develop as a research prototype;
  it is not public yet.

These results will be included in my academic research paper because of interest to the
world of sanitizers and intra-object overflow checkers. If my paper makes it through the
reviews, these findings will be public in 90 days.

You can reproduce with GDB on a build of the same binutils version while my tool is not public. I'm
attaching the inputs and the verbose outputs of my tool. If you have other questions, you can ping me so we can discuss the details.

AI DISCLOSURE: the following has been rewritten with Claude Opus 5.5 so it's compressed and (hopefully) understandable. Verbose outputs are attached, though. I verified the output of Claude's mambling, refined it and put it in a presentable form here. The triage is a best-effort based on mine and Claude's understanding of the code base. Still, most bugs are just straight indexing defects. Claude proposed all the fixes, I did not verify them.

---
# Intra-object overflows
## 1. VAX disassembler: instructions longer than `MAXLEN` overflow `the_buffer`
Short: `print_insn_vax()` fetches the bytes of an instruction on demand into `priv.the_buffer[MAXLEN]`
(25 bytes; `priv` is a local `struct private`). Nothing stops a fetch at `MAXLEN`: for longer
instructions, `fetch_data()` has `buffer_read_memory()` copy the next bytes past the end of
`the_buffer`, into the padding and `insn_start`, and the operand printers read them back from there. There are several write and read accesses.

- The write: `opcodes/dis-buf.c:47` (`memcpy (myaddr, info->buffer + addr_off, length);`), called by
  `fetch_data()` (`opcodes/vax-dis.c:95`) with `myaddr = priv->max_fetched`.
- The reads, through `NEXTBYTE`/`NEXTWORD`/`NEXTLONG` and `p[...]` in `print_insn_mode()` and
  `print_insn_arg()`: `opcodes/vax-dis.c:229, 245, 276, 287, 294, 303, 314, 322, 324, 332, 334, 377`.
- `struct private` is `max_fetched`, `the_buffer[MAXLEN]`, `insn_start`, `bailout`
  (`opcodes/vax-dis.c:72-79`). In our runs the copies and the reads reach byte 42 of it, inside
  `insn_start`.
- Fix: make `fetch_data()` fail (longjmp to `bailout`, as on a read error) when `addr` is past
  `priv->the_buffer + MAXLEN`.
- Inputs (each also has the `dis-buf.c:47` write): `fuzz_objdump.vax_a` (lines 229, 245, 324, 334),
  `fuzz_objdump.vax_b` (229, 332), `fuzz_objdump.vax_c` (229, 276, 287, 294), `fuzz_objdump.vax_d`
  (303), `fuzz_objdump.vax_e` (287, 377), `fuzz_objdump.vax_f` (229, 322, 334),
  `fuzz_disassemble.vax_g` (229, 314, 334), Outputs: the same names with `.out`

## 2. s390 disassembler: the operand loops read past `operands[6]`
Short: the operand list of a `struct s390_opcode` is `unsigned char operands[6]`, "terminated by a
zero" (`include/opcode/s390.h:106-109`), but instructions with six operands use all six entries. The
loops that walk the list up to the 0 then read `operands[6]`, the padding byte after the array.

- `opcodes/s390-dis.c:291` (`s390_print_insn_with_opcode()`), `:221` (`operand_count()`) and `:260`
  (`skip_optargs_zero_p()`), each `for (...; *opindex != 0; opindex++)`.
- In our run: `vfnms` (`s390_opcodes[1262]`) and `vstrs` (`s390_opcodes[1270]`), in the global table.
- Fix: also stop the loops at the end of the array, or give `operands` a seventh entry for the 0.
- Input: `fuzz_disassemble.s390`, Output: `fuzz_disassemble.s390.out`

## 3. readelf: `free_filedata()` clears the rest of `Filedata` through `&filedata->section_headers`
Short: `memset (&filedata->section_headers, 0, sizeof (Filedata) - offsetof (Filedata,
section_headers));` clears every member from `section_headers` to the end of the (heap) `Filedata`
through a pointer to `section_headers`, an 8-byte member. This one is informative: the memset clears
exactly the memory it means to, but a pointer to a member covers that member only, so the write past
it is undefined behavior.

- `binutils/readelf.c:24413` (`readelf.h` in the report: the fuzzer builds a copy of `readelf.c` under
  that name).
- Fix: derive the pointer from the whole object, e.g.
  `memset ((char *) filedata + offsetof (Filedata, section_headers), 0, ...)`.
- Input: `fuzz_readelf.free_filedata`, Output: `fuzz_readelf.free_filedata.out`

---
# Strict aliasing violation?
I will report a bug that I consider a SAV and that various GCC versions interpret as such when passing pointers to these types to functions. 
## 4. `alpha_vms_write_exec()` lays `struct vms_eiha` and `struct vms_eihi` over a local `struct vms_eihd`
Short: `eiha = (struct vms_eiha *)((char *) &eihd + PRIV (file_pos));` (`bfd/vms-alpha.c:3266`) and the
same for `eihi` (`:3279`) place structures made only of `unsigned char` arrays inside the 512-byte
local `eihd` (`:3216`), and their members are then written: through `bfd_putl32()`/`bfd_putl64()`
(`bfd/libbfd.c:965-968, 989-996`) and directly at `bfd/vms-alpha.c:3294, 3295, 3307, 3308, 3309`.
All writes stay inside `eihd` and are character stores, and char can alias with any type. But the arrays
are selected through a structure type that does not match the object, which the GNU C Language
Manual's own overlay example treats as a strict aliasing violation [https://web.archive.org/web/20261027001811/https://www.gnu.org/software/c-intro-and-ref/manual/html_node/Overlaying-Structures.html]. We report it for completeness;
the impact is likely nil, modulo some miscompilation if the pointers are passed around(?). I would like to hear from you what this is exactly.

- Input: `fuzz_objcopy.alpha_vms_write_exec`, Output: `fuzz_objcopy.alpha_vms_write_exec.out`

---

Attachments (in `binutils.zip`): one input and its verbose output per reproducer. Happy
to answer questions.

NOTE: the verbose reports might be a bit inexact when it comes to the provenance of pointers, but we use that for debugging and it's a best effort thing. Pointer provenance analysis is a whole different beast :(

<<attachment: binutils.zip>>

Reply via email to