Skip to content

Check that DWARF attributes do not go past the end of the unit - #131787

Merged
alexey-milovidov merged 5 commits into
masterfrom
fix-dwarf-attribute-past-end-of-section
Nov 17, 2026
Merged

alexey-milovidov merged 5 commits into
masterfrom
fix-dwarf-attribute-past-end-of-section

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

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 the DWARF input format read past the end of .debug_info on 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 throw CANNOT_PARSE_DWARF.

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix a crash of the DWARF input format on an ELF file with a malformed attribute length.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/131787]

Version info

  • Merged into: 26.11.1.2532-master (included in 26.11 and later)
  • Backported to: 26.10.5.50, 26.9.31.15, 26.8.39.14, 26.3.66.10

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]>
@alexey-milovidov alexey-milovidov self-assigned this Nov 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [aac52f1]

Summary: ✅


AI Review

⚠️ Review sessions stopped as a cybersecurity risk

The model provider stopped these review sessions as a possible cybersecurity risk:

  • attempt 1: gpt-6.1-sol

This summary comes from a session with gpt-5.4. A session is typically stopped when it reaches a memory-safety finding, and the finding is lost with it, so this review can miss a real defect. Please review the change in detail, and run the review internally with a model that has cyber access.

Summary

This PR hardens the DWARF input format against malformed attribute lengths by pre-validating the compilation-unit DIE before LLVM’s initial scan and by reading later attributes through a unit-truncated DWARFDataExtractor, which prevents both past-section and cross-unit reads. The new stateless regression covers the original out-of-bounds pattern, the wraparound case, and multi-unit spill cases, and I did not find any remaining correctness issues in the current diff.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). labels Nov 15, 2026
`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]>
alexey-milovidov and others added 2 commits November 16, 2026 17:00
…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]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing aac52f114 with master 64e1b0e77 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

3 object files changed (+33.82 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/DWARFBlockInputFormat.cpp.o 654.07 KiB 687.89 KiB +33.81 KiB (+5.17%)

711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

7 translation units recompiled, 13 s compile time in total, 7 of them have a recent master baseline.

Job report

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]>

@clickhouse-gh clickhouse-gh Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review approves this commit, see the AI Review comment.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 16, 2026
Merged via the queue into master with commit a7ee6e2 Nov 17, 2026
192 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-dwarf-attribute-past-end-of-section branch November 17, 2026 04:39
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 17, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 17, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 17, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 17, 2026
Backport #131787 to 26.10: Check that DWARF attributes do not go past the end of the unit
clickhouse-gh Bot added a commit that referenced this pull request Nov 17, 2026
Backport #131787 to 26.8: Check that DWARF attributes do not go past the end of the unit
clickhouse-gh Bot added a commit that referenced this pull request Nov 17, 2026
Backport #131787 to 26.9: Check that DWARF attributes do not go past the end of the unit
PedroTadim added a commit that referenced this pull request Nov 17, 2026
Backport #131787 to 26.3: Check that DWARF attributes do not go past the end of the unit
mkmkme pushed a commit to Altinity/ClickHouse that referenced this pull request Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants