Skip to content

Fix use-after-free and reading of long values in complex key ssd_cache dictionaries - #126553

Merged
alexey-milovidov merged 4 commits into
masterfrom
fix-ssd-cache-dictionary-keys
Oct 20, 2026
Merged

alexey-milovidov merged 4 commits into
masterfrom
fix-ssd-cache-dictionary-keys

Conversation

@alexey-milovidov

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

Copy link
Copy Markdown
Member

Two fixes in SSDCacheDictionaryStorage:

  • When a complex key ssd_cache dictionary wraps around its partitions, it reads the old keys back from the file to remove them from the index. SSDCacheFileBuffer::readKeys returned keys pointing into a local buffer that was freed on return, so the following lookups in the index read freed memory. Now the caller owns the buffer.
  • The size of the buffer to deserialize values read from the file was taken from read_buffer_blocks_size, which is a number of blocks, not bytes, so reading values longer than a few bytes from the file failed with CANNOT_READ_ALL_DATA.

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 use-after-free in complex key ssd_cache dictionaries when the cache file wraps around its partitions. Fix CANNOT_READ_ALL_DATA when reading long values of ssd_cache dictionaries from the cache file.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.338-master (included in 26.11 and later)
  • Backported to: 26.10.2.49, 26.9.24.4, 26.8.33.6, 26.7.36.7, 26.3.58.5

alexey-milovidov and others added 3 commits October 17, 2026 23:42
`SSDCacheFileBuffer::readKeys` read the blocks into a local `Memory<>`
buffer, and for complex keys `SSDCacheBlock::readComplexKeys` returned
`std::string_view`s pointing into that buffer. The buffer was freed on
return, while the caller in `SSDCacheDictionaryStorage::insertCell`
(the branch that starts reusing old partitions) used these keys for
`index.find` and `eraseKeyFromIndex`.

Now the caller owns the read buffer and keeps it alive while it uses
the keys.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e test faster

The size of the buffer to deserialize the values read from the file was
taken from `read_buffer_blocks_size`, which is a number of blocks, not
bytes, so values longer than a few bytes failed with `CANNOT_READ_ALL_DATA`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [94b3cd4]

Summary: ✅

job_name test_name status info comment
Stateless tests (arm_asan_ubsan, targeted) SKIPPED CIDB timeout in test selection, rerun to test

AI Review

Summary

The PR fixes the lifetime of complex keys during ssd_cache partition reuse and corrects the byte limit used to deserialize cached values from disk. No actionable findings at head 94b3cd4a1a5cd478f46fd4d873d1dcd6524dc822. The new regression test passes in the current-head Fast test report. Validation used source inspection and CI evidence; no local build or tests were run.

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-dictionary Dictionaries (in-memory key-value, periodically refreshed from sources). labels Oct 18, 2026
… MemorySanitizer

The function was not covered by tests before, and MemorySanitizer does not
know that the kernel fills the buffer.

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

@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.

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Oct 20, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 20, 2026
Merged via the queue into master with commit 3b5022c Oct 20, 2026
179 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-ssd-cache-dictionary-keys branch October 20, 2026 19:23
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 20, 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 Oct 20, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 20, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 20, 2026
Backport #126553 to 26.10: Fix use-after-free and reading of long values in complex key `ssd_cache` dictionaries
clickhouse-gh Bot added a commit that referenced this pull request Oct 20, 2026
Backport #126553 to 26.8: Fix use-after-free and reading of long values in complex key `ssd_cache` dictionaries
clickhouse-gh Bot added a commit that referenced this pull request Oct 20, 2026
Backport #126553 to 26.9: Fix use-after-free and reading of long values in complex key `ssd_cache` dictionaries
clickhouse-gh Bot added a commit that referenced this pull request Oct 20, 2026
Backport #126553 to 26.7: Fix use-after-free and reading of long values in complex key `ssd_cache` dictionaries
alexey-milovidov added a commit that referenced this pull request Oct 20, 2026
Backport #126553 to 26.3: Fix use-after-free and reading of long values in complex key `ssd_cache` dictionaries
strtgbb pushed a commit to Altinity/ClickHouse that referenced this pull request Oct 22, 2026
… long values in complex key `ssd_cache` dictionaries
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-ClickHouse__ClickHouse that referenced this pull request Nov 13, 2026
…ed as paths, two readings of one input

Blind reviews of the pull requests that introduced nine bugs fixed later (ported in ClickHouse#131294-ClickHouse#131302) showed these gaps:
- Data the server wrote itself and reads back (parts, patch parts, packed-file indexes, `ssd_cache` files) was
  treated as trusted, so out-of-bounds reads on it were dismissed or rated as Nits (ClickHouse#126553, ClickHouse#116007, ClickHouse#86095).
- No prompt for overflow of sizes computed from user-controlled counts (`ColumnString::replicate`, ClickHouse#61075).
- No prompt for names read from data that become paths (packed archive index, ClickHouse#93414).
- A security check that reads its input differently from the consumer (first vs last repeated key, Boolean
  spellings), which the real review of ClickHouse#106855 missed.
Also ask for a separate pass over parsers and security decisions in large pull requests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-dictionary Dictionaries (in-memory key-value, periodically refreshed from sources). 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.

3 participants