Skip to content

redis: fix use-after-free on overlapping cluster discovery refresh#45902

Open
mateenali66 wants to merge 2 commits into
envoyproxy:mainfrom
mateenali66:fix/redis-zone-discovery-uaf
Open

redis: fix use-after-free on overlapping cluster discovery refresh#45902
mateenali66 wants to merge 2 commits into
envoyproxy:mainfrom
mateenali66:fix/redis-zone-discovery-uaf

Conversation

@mateenali66

@mateenali66 mateenali66 commented Jun 30, 2026

Copy link
Copy Markdown

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.

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>
@repokitteh-read-only

Copy link
Copy Markdown

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.

🐱

Caused by: #45902 was opened by mateenali66.

see: more, trace.

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>
@mateenali66 mateenali66 requested a deployment to external-contributors June 30, 2026 18:21 — with GitHub Actions Waiting
@RyanTheOptimist

Copy link
Copy Markdown
Contributor

/assign @nezdolik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Redis cluster zone-discovery UAF on overlapping CLUSTER SLOTS refresh

3 participants