bgp: fix stack buffer overflow in EVPN parseNlriData#100
Open
xq9mend wants to merge 1 commit intoSNAS:masterfrom
Open
bgp: fix stack buffer overflow in EVPN parseNlriData#100xq9mend wants to merge 1 commit intoSNAS:masterfrom
xq9mend wants to merge 1 commit intoSNAS:masterfrom
Conversation
Add destination-size clamp before memcpy into ip_binary[16] in three EVPN route-type parsing paths (type-2 MAC-IP, type-3 IMET, type-4 ES). Wire-supplied ip_len field (1 byte) could produce addr_bytes up to 31, overflowing the 16-byte stack buffer. Fix: clamp addr_bytes to sizeof(ip_binary) before memcpy. Signed-off-by: xq9mend <xq9mend@users.noreply.github.com>
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.
Why I did it
ip_binary is a 16-byte stack buffer in EVPN::parseNlriData. The IP Address Length field read from wire data (1 byte) was divided by 8 to get addr_bytes, which can be up to 31. This value was passed directly to memcpy with no destination-size check, allowing up to 15 bytes of stack overflow. Three parsing paths were affected: type-2 (MAC-IP Advertisement), type-3 (IMET), and type-4 (ES).
How I did it
Added a clamp after the addr_bytes computation in all three paths:
Also fixed the type-4 path to use the clamped addr_bytes in memcpy instead of the raw unclamped expression it previously used.
How to verify it
Build passes: cmake + make with no errors (tested on Ubuntu 24.04, gcc 13). No unit tests exist in this repo.