Repository navigation
Cherry pick #103890 to 25.8: Fix use-after-free in KeeperHandlingConsumer::setKeeper (StorageKafka2) - #105076
Merged
robot-ch-test-poll4 merged 4 commits intoMay 15, 2026
Conversation
`LockedTopicPartitionInfo::lock` (held in `permanent_locks` and `tmp_locks`) is a `zkutil::EphemeralNodeHolder`, which stores a **raw** `ZooKeeper &` reference captured at construction. Its destructor calls `zookeeper.expired()` and possibly `zookeeper.tryRemove()`. `KeeperHandlingConsumer::setKeeper()` assigned the new `keeper` shared_ptr *before* clearing the lock maps. If the consumer was the last shared owner of the previous `ZooKeeper` session, that assignment would synchronously destroy the old session, and the subsequent `permanent_locks.clear()` / `tmp_locks.clear()` would then access a dangling reference -> SIGSEGV. This is the same hazard already documented and handled in `StorageKafka2::partialShutdown()` for `replica_is_active_node` (see the comment at `StorageKafka2.cpp` lines 221-225). This commit mirrors that ordering for the per-consumer lock holders. Caught by `Stress test (arm_release)` on PR #101113 (which is unrelated to Kafka/Keeper -- the crash surfaced under stress-test ZK fault injection): zkutil::EphemeralNodeHolder::~EphemeralNodeHolder() @ 0x15aa9699 DB::KeeperHandlingConsumer::setKeeper(...) @ 0x15a9985c DB::StorageKafka2::streamToViews(unsigned long) @ 0x15b0cf1c Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=101113&sha=4cf4eb894643c2dac6b52dea6126f1a3f2e75cd2&name_0=PR&name_1=Stress%20test%20%28arm_release%29 Related issue: #84616 (sibling crash in StorageKafka2 on Keeper session loss). STID: 3555-2986 Signed-off-by: Groene AI <[email protected]>
Reduce the explanation in `KeeperHandlingConsumer::setKeeper` to a short two-liner that just references the precedent at `StorageKafka2::partialShutdown` for `replica_is_active_node`, where the same use-after-free hazard is already documented.
…storagekafka2-uaf Fix use-after-free in KeeperHandlingConsumer::setKeeper (StorageKafka2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #103890
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job