An authenticated user who can publish to a channel on a server running in cluster mode can make the server allocate a heap buffer far smaller than the message it is about to copy into it, and then write past the end of that buffer with attacker-controlled bytes. This reliably crashes the server process, and because the overflowing bytes are chosen by the attacker, it may be possible to escalate it to remote code execution running as the user the server runs as.
This issue affects Valkey 7.2, 8.0, 8.1, 9.0, 9.1 and 9.2 running in cluster mode. Servers that do not have cluster mode enabled are not affected.
When a node propagates a PUBLISH or SPUBLISH to the rest of the
cluster, clusterCreatePublishMsgBlock in src/cluster_legacy.c
(src/cluster.c on 7.2) computes the length of the cluster bus message as
a size_t, but passes it to createClusterMsgSendBlock, which takes a
uint32_t. When the channel and message together exceed UINT32_MAX, the
length is silently truncated and a buffer far smaller than the message is
allocated. The two memcpy calls that follow copy the full channel and
message into it. Both the regular and the light cluster bus header paths
are affected, as are the module publish APIs.
Building a channel and message this large requires more than 4 GiB of
memory. With the default proto-max-bulk-len of 512 MB, a client cannot
send arguments that large directly, but a script can construct them on the
server.
The cluster bus cannot represent a message of this size, so the fix
validates the complete serialized length before any 32-bit conversion or
allocation. PUBLISH and SPUBLISH now reply with an error, and the
message is neither published locally nor propagated.
You can mitigate this issue by using Valkey ACLs to restrict the scripting
commands (EVAL, EVALSHA, EVAL_RO, EVALSHA_RO, FCALL, FCALL_RO
and FUNCTION) if your application does not intend to use them, and by
not raising proto-max-bulk-len above its default.
The defect was reported by Nenad Stojanovski working with Trend Micro Zero Day Initiative (ZDI-CAN-28318). The fix was authored by https://github.com/roshkhatri (#5030).