bgpd: More validations for labeled unicast and ENCAP attribute#21343
Merged
mjstapp merged 2 commits intoFRRouting:masterfrom Mar 26, 2026
Merged
Conversation
…ast NLRI When multiple labels are consumed without BOS, BSIZE(llen) can exceed prefixlen, causing a uint16_t underflow to 65535. Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
If we don't check for length against 0, then we have a test (length < 1) that triggers the whole ENCAP attr to be malformed. Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
Greptile SummaryThis PR adds two defensive input-validation fixes in BGP attribute parsing to harden against malformed UPDATE messages.
Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Receive BGP UPDATE] --> B{Parse ENCAP attribute}
B -->|length < 4| ERR1[Return malformed error]
B -->|OK| C[Read outer TLV type + length\nlength -= 4]
C -->|tlv_length != length| ERR2[Return malformed error]
C -->|OK| D{length > 0 AND\nSTREAM_READABLE >= 4?}
D -->|No - loop exits| E[Done parsing ENCAP]
D -->|Yes| F[Read sub-TLV header\nlength -= header bytes]
F -->|sublength > length| ERR3[Return malformed error]
F -->|OK| G[Read sub-TLV value\nlength -= sublength]
G --> D
H[Receive Labeled Unicast NLRI] --> I[Fetch prefixlen, psize]
I --> J[bgp_nlri_get_labels\nreturns llen]
J -->|llen == 0| ERR4[Return label length error]
J -->|OK| K{prefixlen < 24?}
K -->|Yes| ERR5[Return label length error]
K -->|No| L[p.prefixlen = prefixlen - BSIZE llen]
L --> M{p.prefixlen > max bitlen?}
M -->|Yes| ERR6[Return prefix length error]
M -->|No| N[Process prefix normally]
Reviews (1): Last reviewed commit: "bgpd: Check the length also when parsing..." | Re-trigger Greptile |
mjstapp
approved these changes
Mar 26, 2026
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.
No description provided.