redis: fix use-after-free on overlapping cluster discovery refresh#45902
Open
mateenali66 wants to merge 2 commits into
Open
redis: fix use-after-free on overlapping cluster discovery refresh#45902mateenali66 wants to merge 2 commits into
mateenali66 wants to merge 2 commits into
Conversation
CLUSTER SLOTS clears current_request_ as soon as it completes, while the zone-discovery INFO requests it triggers are still in flight. A refresh (periodic resolve timer or DNS update) arriving in that window re-entered startResolveRedis(), started a second zone discovery and overwrote zone_callbacks_, freeing the callbacks that the in-flight INFO requests still referenced. Gate startResolveRedis() on pending_zone_requests_ so a refresh is skipped until zone discovery finishes, and add a regression test. Signed-off-by: Mateen Anjum <mateenali66@gmail.com>
|
Hi @mateenali66, welcome and thank you for your contribution. We will try to review your Pull Request as quickly as possible. In the meantime, please take a look at the contribution guidelines if you have not done so already. |
The changelog fragment area must match the canonical set in changelogs/changelogs.yaml; the Redis subsystem area is redis_proxy, not redis. Signed-off-by: Mateen Anjum <mateenali66@gmail.com>
Contributor
|
/assign @nezdolik |
nezdolik
approved these changes
Jul 2, 2026
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.
Fix a use-after-free in the Redis cluster CLUSTER SLOTS discovery. current_request_ is cleared as soon as CLUSTER SLOTS completes, while the zone-discovery INFO requests it triggers are still in flight. A refresh (periodic resolve timer or DNS update) arriving in that window re-entered startResolveRedis(), started a second zone discovery and overwrote zone_callbacks_, freeing the callbacks that the in-flight INFO requests still referenced. Gate startResolveRedis() on pending_zone_requests_ so a refresh is skipped until zone discovery finishes.
Additional Description: startResolveRedis() guarded re-entry only on current_request_, which onResponse() clears the moment CLUSTER SLOTS completes. The INFO requests started by startZoneDiscovery() are still outstanding at that point (tracked by the existing pending_zone_requests_ counter), so an external refresh in the gap passed the guard, ran startZoneDiscovery() again and overwrote zone_callbacks_[addr], freeing the ZoneDiscoveryCallback that an in-flight ClientImpl::PendingRequest still holds by reference. Adds a second early-return guard on pending_zone_requests_. Fixes #45870.
Risk Level: Low (adds an early-return guard in the discovery re-entry path; the normal first-resolution and steady-state paths are unchanged).
Testing: Added unit regression test ZoneDiscoveryRefreshWhileInfoInFlightIsSkipped in test/extensions/clusters/redis/redis_cluster_test.cc: it fires the resolve timer while zone-discovery INFO requests are in flight and asserts no second CLUSTER SLOTS request is issued, then completes discovery normally. Run: ./ci/do_ci.sh debug //test/extensions/clusters/redis:redis_cluster_test
Docs Changes: N/A
Release Notes: changelogs/current/bug_fixes/redis__zone-discovery-use-after-free.rst
I have reviewed and understand all of the submitted code.