| Issue |
243368
|
| Summary |
[Object][WebAssembly] A subsection size can move Ctx.End past the section in dylink.0 and linking; out-of-bounds read
|
| Labels |
lld:wasm,
crash
|
| Assignees |
|
| Reporter |
AnantaSrikar
|
`WasmObjectFile::parseDylink0Section` and `parseLinkingSection` read each subsection's size and set `Ctx.End = Ctx.Ptr + Size` without checking it against the end of the enclosing section (`OrigEnd`). The bounded readers then trust the new `Ctx.End`, so an oversized subsection makes them read past the section, and past the input buffer. ASan reports a heap-buffer-overflow; an assertions build without ASan aborts with `LLVM ERROR: EOF while reading string` on the reproducer below.
#76676 adds this check to `parseLinkingSection` only. It was reviewed in 2024 but never merged, and its test input still overflows on main. `parseDylink0Section` has the same problem.
**Version**: main at c7014922f582 (2026-11-16), built from the Git repository with `-DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PROJECTS=lld -DLLVM_USE_SANITIZER="Address;Undefined"`, on x86_64 Linux.
### Reproducer
```sh
cat > dylink.yaml <<'YAML'
--- !WASM
FileHeader:
Version: 0x1
Sections:
- Type: CUSTOM
Name: dylink.0
MemorySize: 0
MemoryAlignment: 0
TableSize: 0
TableAlignment: 0
Needed: []
RuntimePath:
- '/a/b/c'
YAML
yaml2obj dylink.yaml -o dylink.wasm
cp dylink.wasm bad.wasm
# RUNTIME_PATH subsection: size 8 -> 0x70 (offset 0x1e), count 1 -> 5 (0x1f)
printf '\160\005' | dd of=bad.wasm bs=1 seek=30 conv=notrunc
wasm-ld --no-entry --export-all -o out.wasm bad.wasm
```
`dylink.wasm` gets the expected `attempted static link of dynamic object` error (status 1).
### Observed
```
==15==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7bbe69be0151 at pc 0x5647941e37b0 bp 0x7ffddc565690 sp 0x7ffddc565688
#0 in decodeULEB128 llvm/include/llvm/Support/LEB128.h:163:22
#1 in decodeULEB128 llvm/include/llvm/Support/LEB128.h:196:10
#2 in readULEB128 llvm/lib/Object/WasmObjectFile.cpp:124:21
#3 in readString llvm/lib/Object/WasmObjectFile.cpp:132:24
#4 in llvm::object::WasmObjectFile::parseDylink0Section(llvm::object::WasmObjectFile::ReadContext&) llvm/lib/Object/WasmObjectFile.cpp:505:42
#5 in llvm::object::WasmObjectFile::parseCustomSection(llvm::object::WasmSection&, llvm::object::WasmObjectFile::ReadContext&)
```
The 47-byte input from #76676 still gives a heap-buffer-overflow in `parseLinkingSectionSymtab` with `llvm-readobj --sections`.
### Expected
An error that the subsection runs past the end of its section.
### Analysis
https://github.com/llvm/llvm-project/blob/c7014922f5829426952a38d079220c21b0a8ebe8/llvm/lib/Object/WasmObjectFile.cpp#L465-L472
https://github.com/llvm/llvm-project/blob/c7014922f5829426952a38d079220c21b0a8ebe8/llvm/lib/Object/WasmObjectFile.cpp#L650-L657
Returning an error when `Size > OrigEnd - Ctx.Ptr`, before setting `Ctx.End`, in both loops would fix both. That is the check #76676 adds for `parseLinkingSection`.
This report was drafted with help from an AI assistant (Claude); I reviewed it and reproduced it myself.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs