| Issue |
239393
|
| Summary |
[lld][wasm] wasm-ld crashes on a section symbol that names a non-custom section
|
| Labels |
lld:wasm,
crash
|
| Assignees |
|
| Reporter |
AnantaSrikar
|
I'm Ananta Srikar Puranam, a PhD student at Washington State University. I'm reporting this bug on behalf of my team.
`wasm-ld` segfaults when a `WASM_SYMBOL_TYPE_SECTION` symbol names a section that isn't a custom section. `WasmObjectFile` only checks that the symbol is local. `ObjFile::createDefined` looks the index up in `customSectionsByIndex`, which only holds custom sections. The `DenseMap::operator[]` lookup returns null, and the next line dereferences it.
**Version**: main at 65166e24ae34 (2026-11-05), built from the Git repository with `-DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PROJECTS=lld -DLLVM_TARGETS_TO_BUILD="X86;WebAssembly"`, on x86_64 Linux.
### Reproducer
```sh
cat > secsym.yaml <<'YAML'
--- !WASM
FileHeader:
Version: 0x1
Sections:
- Type: TYPE
Signatures:
- Index: 0
ParamTypes: []
ReturnTypes: []
- Type: FUNCTION
FunctionTypes: [ 0 ]
- Type: CODE
Functions:
- Index: 0
Locals: []
Body: 0B
- Type: CUSTOM
Name: .debug_info
Payload: '00'
- Type: CUSTOM
Name: linking
Version: 2
SymbolTable:
- Index: 0
Kind: SECTION
Flags: [ BINDING_LOCAL ]
Section: 2
YAML
yaml2obj secsym.yaml -o secsym.o
wasm-ld --no-entry -o secsym.wasm secsym.o
```
Section 2 is the Code section. With `Section: 3` (the custom `.debug_info` section) instead, the same command links (status 0).
### Observed
The process exits with SIGSEGV (status 139):
```
lld::wasm::ObjFile::createDefined(llvm::object::WasmSymbol const&)
lld::wasm::ObjFile::parse(bool)
lld::wasm::SymbolTable::addFile(lld::wasm::InputFile*, llvm::StringRef)
lld::wasm::(anonymous namespace)::LinkerDriver::linkerMain(llvm::ArrayRef<char const*>)
```
An earlier UBSan build of main (93d242ed5416), on a fuzzed object with the same kind of section symbol, reports `runtime error: member access within null pointer of type 'InputChunk'` in `ObjFile::createDefined`.
With an index past the end of the section list (for example `Section: 40`), the object reader fails first. An assertions build fails the `std::vector<llvm::object::WasmSection>::operator[]` assertion in `WasmObjectFile::parseLinkingSectionSymtab`.
### Expected
An error for the section symbol (for example "section symbol must refer to a custom section"), instead of a crash.
### Analysis
`parseLinkingSectionSymtab` reads the section index and uses it without checking its range or the section's type:
https://github.com/llvm/llvm-project/blob/65166e24ae3499f143ea9d8581e544c37b1977a7/llvm/lib/Object/WasmObjectFile.cpp#L880-L891
`ObjFile::parse` only adds custom sections to `customSectionsByIndex`:
https://github.com/llvm/llvm-project/blob/65166e24ae3499f143ea9d8581e544c37b1977a7/lld/wasm/InputFiles.cpp#L547-L558
`createDefined` subscripts the map, which inserts and returns a null `InputChunk *` for the Code section's index, and then reads `section->discarded`:
https://github.com/llvm/llvm-project/blob/65166e24ae3499f143ea9d8581e544c37b1977a7/lld/wasm/InputFiles.cpp#L706-L713
Checking in `parseLinkingSectionSymtab` that the index is less than `Sections.size()` and names a `WASM_SEC_CUSTOM` section would fix both cases. Alternatively, `createDefined` could use `lookup` and report an error when it returns null.
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