Skip to content

Validate malformed responses from HDFS DataNode and NameNode - #126546

Merged
rschu1ze merged 3 commits into
masterfrom
fix-libhdfs3-malformed-responses
Oct 21, 2026
Merged

rschu1ze merged 3 commits into
masterfrom
fix-libhdfs3-malformed-responses

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

Update libhdfs3 to validate malformed responses from the HDFS DataNode and NameNode. Previously, inconsistent packet offsets sent by a DataNode could lead to an out-of-bounds memcpy in RemoteBlockReader, and block locations from a NameNode with mismatched storageTypes and storageIDs arrays led to an out-of-bounds read. Now such responses throw an exception.

Related: ClickHouse/libhdfs3#79

Changelog category (leave one):

  • Improvement

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

Fix a possible crash or out-of-bounds memory access when reading from HDFS if a DataNode or NameNode sends malformed responses.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.435-master (included in 26.11 and later)
  • Backported to: 26.10.2.65, 26.9.24.15, 26.8.34.6, 26.7.37.8, 26.3.59.7

@clickhouse-gh

clickhouse-gh Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ea532ac]

Summary: ✅


AI Review

Summary

This PR updates libhdfs3 to validate malformed DataNode packets and NameNode block locations, and also imports slow DataNode avoidance and timeout retries. ⚠️ Request changes: focused regression evidence for the memory-safety fixes is still missing at PR head ea532acd162e59b82b36f22bbb80b1971b49a26c.

Findings

⚠️ Majors

  • contrib/libhdfs3:1 — [dismissed by author -- https://github.com/Validate malformed responses from HDFS DataNode and NameNode #126546#discussion_r4305389420] The malformed-response fixes still have no regression coverage. The author deferred protocol fixtures to an upstream follow-up; the newly pinned revision adds configuration and slow-node tests, but none exercises the changed packet-offset or parallel-array validation. This remains material because normal HDFS reads can pass with the memory-safety protections removed. Add and run focused upstream tests, then pin the tested revision. No duplicate inline comment was posted.
Tests
  • ⚠️ Cover a DataNode packet whose offset would put position > size, mismatched NameNode storageTypes/storageIDs, and a valid read starting inside a checksum chunk. Use small protocol fixtures or mocks in libhdfs3; a full malformed HDFS server is unnecessary. Record the focused test results, preferably with ASan. No local build or runtime tests were run for this review.
Final Verdict

⚠️ Request changes. Minimum action: provide focused regression tests and their results for the malformed-response fixes, and update the submodule pointer if needed.

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix submodule changed At least one submodule changed in this PR. pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Oct 18, 2026
@alexey-milovidov

alexey-milovidov commented Oct 18, 2026 •

Copy link
Copy Markdown
Member Author

I've merged the fix to HDFS plus two more changes. Update the submodule pointer to the latest.
While it may get unrelated changes, it's okay.

@alexey-milovidov alexey-milovidov removed pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-critical-bugfix labels Oct 18, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Changed the category to "Improvement", because no one cares about HDFS.

@clickhouse-gh clickhouse-gh Bot added the comp-external-dependencies Third-party deps updates in contrib/, vendored code, and platform base libraries. label Oct 18, 2026
Comment thread contrib/libhdfs3 Outdated
@@ -1 +1 @@
Subproject commit ceb428c52e6b4362a35ec18b69206d9bb94edce3
Subproject commit d9c26dc4df628219f28904f057d64752c5007704

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.

⚠️ [P2] Add regression coverage for the malformed-response fixes

The pinned libhdfs3 commit changes four production files but adds no tests, and this PR adds none either. Existing reads against a normal HDFS server do not exercise the packet offsets or parallel-array mismatches that caused the out-of-bounds accesses, so they can pass with these protections removed.

Please add focused coverage in libhdfs3 and pin the tested revision: a DataNode packet whose offset leaves position > size must throw HdfsIOException before copying, and a NameNode response with mismatched storageTypes/storageIDs must be handled without an out-of-bounds access. Include a valid read starting inside a checksum chunk to prove the new offset validation still accepts the required backward alignment. These can use a small protocol fixture or mocks; they do not need a full HDFS integration cluster.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🕵 The fix in the submodule was reviewed and merged upstream (ClickHouse/libhdfs3#79), and the pointer now tracks the latest libhdfs3 master (28a9868). The libhdfs3 unit tests are not built or run in ClickHouse CI, so the requested protocol fixtures (a DataNode packet with position > size, a NameNode response with mismatched storageTypes/storageIDs) would belong in a follow-up PR to the libhdfs3 repository rather than here. A ClickHouse-side test would need a deliberately malformed HDFS server, which is out of proportion for this change. Leaving this thread open for a maintainer decision on whether that follow-up is wanted.

@rschu1ze rschu1ze added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Oct 19, 2026
@rschu1ze
rschu1ze added this pull request to the merge queue Oct 19, 2026
@alexey-milovidov
alexey-milovidov removed this pull request from the merge queue due to a manual request Oct 19, 2026
@alexey-milovidov

alexey-milovidov commented Oct 19, 2026 •

Copy link
Copy Markdown
Member Author

@rschu1ze, do not merge red. The stress test has failed.
We also don't merge without review. So you have to approve the changes first.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The code LGTM.

@groeneai

Copy link
Copy Markdown
Collaborator

The fix is #125567 (open, CI finished, waiting for review). The failure is not related to the libhdfs3 bump.

The aborting query (84d37f7c-1146-410c-98ae-0568b848a22e, clickhouse-server.err.log line 260818) comes from the server-side AST fuzzer: a fuzzed CREATE TABLE test_1.ts_t64__fuzz_3 ... ENGINE = TimeSeries whose inner-target column value has CODEC(arrayMap(plus(_, 65537) | toString, [1, 2]), ALP, ZSTD(3)). Inside CODEC, f | g is formatted as the call __compose(...), which parses back without the operator flag, so the tree hashes differ while both dumpTree outputs are identical.

Reduced form:

CREATE TABLE t (value LowCardinality(Float64) CODEC(arrayMap(plus(_, 65537) | toString, [1, 2]), ALP, ZSTD(3))) ENGINE = Memory

It aborts a current master debug build (94e0f5ac) at the same check (executeQuery.cpp:2625) and returns UNKNOWN_CODEC on the amd_debug binary from #125567's CI.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Oct 20, 2026
As requested in the PR discussion, bump the pointer to the tip of
`ClickHouse/libhdfs3` `master`, which also brings slow DataNode
avoidance and an HDFS timeout fix. Add the new `SlowMetrics.cpp` and
`SlowNodeTracker.cpp` sources to the build.

The new revision also contains unit tests (`TestSlowMetrics`,
`TestSlowNodeTracker`) in the `libhdfs3` repository.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failures: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=126546&sha=1b4f834586b7e310c2e9021e6459376128297985&name_0=PR&name_1=Stress%20test%20%28arm_release%29 (S3_ERROR No such key on 05104_s3_plain_rewritable_hard_links_test_1/.../data.packed, read after the blob was deleted) and https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=126546&sha=1b4f834586b7e310c2e9021e6459376128297985&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29 (BackupsWorker: Failed to make internal backup ... Got error from the initiator. Query was cancelled) and provide a fix in a separate PR. If the fix is already in progress, link it here. Both are unrelated to the libhdfs3 bump.

Also: the submodule now points to the latest libhdfs3 master (28a9868), as requested, with the new SlowMetrics.cpp / SlowNodeTracker.cpp sources added to contrib/libhdfs3-cmake/CMakeLists.txt; the clickhouse binary builds and links.

@groeneai

Copy link
Copy Markdown
Collaborator

Both already have fixes in my open PRs:

  • Stress test (arm_release): the failing reads hit test_1.reader__fuzz_1..4, copies of the 05104 reader that the server-side AST fuzzer created at 12:27:05 and nothing dropped. The writer's drop at 12:27:10 removed cbfnok.../data.packed, and fuzzed system-table reads (system.parts from the 04320 session, system.data_skipping_indices from 03792) reached those parts 21 minutes later. Fix: Leave no stale readonly reader behind in tests 05104, 05227 and 05228 #124342, which pins ast_fuzzer_any_query = 0 (and ignore_drop_queries_probability = 0) on the 05104, 05227 and 05228 sessions.
  • Upgrade check (amd_release): on the previous release (26.9.22.3) the DDL queue was stuck on query-0000000026, the KILL PART_MOVE_TO_SHARD ... ON CLUSTER of 05082 (190 retries, No node on .../part_moves_shard), so the 02907 BACKUP ... ON CLUSTER entry query-0000000035 behind it never ran. KILL QUERY WHERE 1 SYNC cancelled its initiator at 12:20:56, and the upgraded server then executed the entry at 12:24:33. Fix: Upgrade check: do not run 05082 in the stress phase #125562, which skips 05082 in the stress phase of the upgrade check.

@clickhouse-gh

clickhouse-gh Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing ea532acd1 with master 3974044bf (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 3eecd1398; 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

22 object files changed (+146.09 KiB total), 2 added.

Object file Master PR Δ
contrib/libhdfs3-cmake/CMakeFiles/_hdfs3.dir/__/libhdfs3/src/client/SlowNodeTracker.cpp.o new 97.27 KiB +97.27 KiB
contrib/libhdfs3-cmake/CMakeFiles/_hdfs3.dir/__/libhdfs3/src/client/SlowMetrics.cpp.o new 18.70 KiB +18.70 KiB

719 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

44 translation units recompiled, 101 s compile time in total, 6 of them have a recent master baseline.

Job report

@rschu1ze
rschu1ze added this pull request to the merge queue Oct 21, 2026
Merged via the queue into master with commit b796de8 Oct 21, 2026
179 checks passed
@rschu1ze
rschu1ze deleted the fix-libhdfs3-malformed-responses branch October 21, 2026 16:21
@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 Oct 21, 2026
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 21, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 21, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 21, 2026
Backport #126546 to 26.10: Validate malformed responses from HDFS DataNode and NameNode
clickhouse-gh Bot added a commit that referenced this pull request Oct 21, 2026
Backport #126546 to 26.9: Validate malformed responses from HDFS DataNode and NameNode
clickhouse-gh Bot added a commit that referenced this pull request Oct 21, 2026
Backport #126546 to 26.8: Validate malformed responses from HDFS DataNode and NameNode
clickhouse-gh Bot added a commit that referenced this pull request Oct 21, 2026
Backport #126546 to 26.7: Validate malformed responses from HDFS DataNode and NameNode
alexey-milovidov added a commit that referenced this pull request Oct 21, 2026
Backport #126546 to 26.3: Validate malformed responses from HDFS DataNode and NameNode
strtgbb pushed a commit to Altinity/ClickHouse that referenced this pull request Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-external-dependencies Third-party deps updates in contrib/, vendored code, and platform base libraries. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-improvement Pull request with some product improvements 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 submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants