Repository navigation
Conversation
In completeFileSegment(), appendFilesystemCacheLog(file_segment) was called after completeAndPopFront() which moves and erases the shared_ptr from the holder's list. When the holder's shared_ptr is the last reference (e.g. the cache has already evicted this segment from its metadata), the FileSegment object is destroyed, and the reference becomes dangling. Move the log call before completeAndPopFront() so the FileSegment is still alive when its range and downloaded size are read. Detected by MemorySanitizer in BuzzHouse (amd_msan) — STID 3229. Fixes ClickHouse#100761
Pre-PR Validation Gatea) Deterministic repro? b) Root cause explained? c) Fix matches root cause? d) Test intent preserved? e) Both directions demonstrated? Session: |
|
Workflow [PR], commit [ea82d76] Summary: ❌
AI ReviewSummaryThis PR fixes a lifetime issue in ClickHouse Rules
Final Verdict
|
|
The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix. |
LLVM Coverage Report
Changed lines: 100.00% (5/5) · Uncovered code |
4c74bee
Cherry pick #101161 to 26.3: Fix use-after-free in FileSegmentRangeWriter::completeFileSegment
…r::completeFileSegment
Backport #101161 to 26.3: Fix use-after-free in FileSegmentRangeWriter::completeFileSegment
In
FileSegmentRangeWriter::completeFileSegment(),appendFilesystemCacheLog(file_segment)was called aftercompleteAndPopFront(). The pop operation moves theFileSegmentPtrfrom the holder's list intoFileSegment::complete(), which resets it viaSCOPE_EXIT_SAFE. The list element is then erased. If no othershared_ptrto theFileSegmentexists at that point (e.g. the cache has already evicted this segment from its key metadata), the object is destroyed, and thefile_segmentreference becomes dangling.appendFilesystemCacheLogthen readsrange()andgetDownloadedSize()from freed memory — detected by MemorySanitizer as use-of-uninitialized-value (STID: 3229-51fa, 3229-5315).The fix moves the log call before the pop, where the
FileSegmentis guaranteed to still be alive. The log function only reads immutable segment properties (range(),getDownloadedSize()), so the reorder is safe — no semantic change.Fixes #100761
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a use-after-free in the filesystem cache write path that could cause reads from freed memory when logging completed file segments (detected by MemorySanitizer in BuzzHouse).
Documentation entry for user-facing changes
Version info
26.4.1.101926.3.10.44