Repository navigation
Check that DWARF attributes do not go past the end of the unit - #131787
Conversation
LLVM advances the offset by the length of a block (`DW_FORM_exprloc`, `DW_FORM_block*`) or of a fixed-size form without checking it against the section, and decoding LEB128 checks the offset only with an assertion. So a malformed length made the `DWARF` format read past the end of `.debug_info` on the next attribute. Check the offset after each attribute and throw `CANNOT_PARSE_DWARF`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [aac52f1] Summary: ✅
AI Review
|
`tryExtractDIEsIfNeeded` makes LLVM parse the unit DIE with the same unchecked skipping of attributes, so a malformed length in the unit DIE still made it read past the end of `.debug_info`. Walk the unit DIE with the bounds checks first. Test both the unit DIE and a child DIE. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…round `DWARFFormValue::skipValue` and `extractValue` advance the offset with plain unsigned addition, so a `DW_FORM_exprloc` length near `UINT64_MAX` made it wrap around to before the attribute and pass the end-of-unit check. Also exclude the test from MSan builds, where the `DWARF` format is not built. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes3 object files changed (+33.82 KiB total), 0 added.
711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units7 translation units recompiled, 13 s compile time in total, 7 of them have a recent master baseline. |
Read the entries of each unit through a `DWARFDataExtractor` truncated at the end of the unit, so that an attribute which spills past the end of the unit is rejected without reading the bytes of the next unit. Also reject a `DW_FORM_string` that is not terminated within the unit, since `skipValue` does not advance the offset for it. Add a test with two adjacent units where the first unit ends in the middle of an attribute. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Backport #131787 to 26.10: Check that DWARF attributes do not go past the end of the unit
Backport #131787 to 26.8: Check that DWARF attributes do not go past the end of the unit
Backport #131787 to 26.9: Check that DWARF attributes do not go past the end of the unit
Backport #131787 to 26.3: Check that DWARF attributes do not go past the end of the unit
…t go past the end of the unit
LLVM advances the offset by the length of a block (
DW_FORM_exprloc,DW_FORM_block*) or of a fixed-size form without checking it against the section, and decoding LEB128 checks the offset only with an assertion. So a malformed length in an ELF made theDWARFinput format read past the end of.debug_infoon the next attribute, both in LLVM's parsing of the unit entry (tryExtractDIEsIfNeeded) and in our own parsing of the other entries. Walk the unit entry with bounds checks before LLVM parses it, check the offset after each attribute we parse, and throwCANNOT_PARSE_DWARF.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a crash of the
DWARFinput format on an ELF file with a malformed attribute length.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/131787]
Version info
26.11.1.2532-master(included in26.11and later)26.10.5.50,26.9.31.15,26.8.39.14,26.3.66.10