Repository navigation
Fix integer overflow in Cluster Bus PUBLISH and MODULE message length validation - #987
Open
KIMDONGYEON00 wants to merge 1 commit into
Open
KIMDONGYEON00 wants to merge 1 commit into
KIMDONGYEON00 wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Summary
This PR fixes integer overflows in the length validation of Cluster Bus
PUBLISHandMODULEmessages.In
clusterProcessPacket(), the expected packet length (explen) was calculated using a 32-bit unsigned integer. Since message length fields are supplied through the Cluster Bus protocol, specially crafted values could cause the calculation to wrap around and bypass the packet length validation.For
PUBLISHmessages, this could lead to a heap-buffer-overflow when KeyDB processes the message payload.The issue was reproduced on the original KeyDB build using AddressSanitizer (ASan), and the fix was verified using the same malformed input.
Root Cause
The original implementation calculated the expected packet length using
uint32_t:If the sum of the length fields exceeded
UINT32_MAX, the result wrapped around to a smaller value.As a result, a malformed packet could pass the
totlenvalidation even though its declared payload lengths were much larger than the received data.The subsequent
PUBLISHprocessing path could then attempt to read beyond the allocated receive buffer.A similar integer overflow was possible in the
MODULEmessage length calculation.Changes
Use
uint64_tfor expected message length calculations inPUBLISHandMODULEpacket validation.Reject messages when the calculated length exceeds
UINT32_MAX.Log a warning when a message is rejected due to length overflow.
Preserve the existing packet length validation for valid messages.
Prevent malformed length fields from reaching subsequent message processing.
Validation
The fix was tested using an AddressSanitizer-enabled KeyDB build in an isolated Docker environment.
Test environment
The results confirm that the fix prevents the reproduced
PUBLISHheap-buffer-overflow and rejects malformed length fields in both message types.Security Impact
The vulnerability affects Cluster Bus message processing when malformed length fields cause integer overflow during packet validation.
For
PUBLISHmessages, the overflow can allow an inconsistent packet to pass the length check and trigger an out-of-bounds memory read.This behavior was confirmed using AddressSanitizer.
Potential consequences include:
Out-of-bounds memory reads
Process termination or denial of service
Unexpected behavior during malformed Cluster Bus message processing
The observed impact was a heap-buffer-overflow and loss of server responsiveness in the sanitizer-enabled test environment. No remote code execution or information disclosure was demonstrated.
References
Related upstream Redis fix: https://github.com/redis/redis/pull/15187
Redis fix commit: redis/redis@c0a8326
The full AddressSanitizer log and reproduction details can be provided privately to maintainers if needed.