eigrpd: improve validation and error-handling in tlv parsing - #21316
Conversation
Harden validation of lengths before accessing packets; detect and handle invalid INT TLVs where they're created. Reported-by: Haruto Kimura (Stella) <harutokimura0608@gmail.com> Signed-off-by: Mark Stapp <mjs@cisco.com>
Greptile SummaryThis PR hardens the EIGRP TLV parsing loop across five packet-receive handlers (
The changes are consistent with the rest of the codebase's stream-API usage. One minor recurring pattern: the Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Receive EIGRP packet] --> B{STREAM_READABLE >= 4?}
B -- No --> B1[zlog_warn + skip remaining + break]
B -- Yes --> C[stream_getw: read type]
C --> D{type == EIGRP_TLV_IPv4_INT?}
D -- No --> E[stream_getw: read length]
E --> F{length < 4 OR readable < length-4?}
F -- Yes --> F1[skip remaining + break]
F -- No --> F2[stream_forward_getp length-4 + continue]
D -- Yes --> G[stream rewind 2 bytes]
G --> H[eigrp_read_ipv4_tlv]
H --> I{STREAM_READABLE >= 25?}
I -- No --> I1[return NULL]
I -- Yes --> J[read fixed 25-byte header fields]
J --> K{STREAM_READABLE >= bytes for prefix?}
K -- No --> K1[free TLV + return NULL]
K -- Yes --> L[read variable-length destination]
L --> M[return TLV]
M --> N{tlv == NULL?}
N -- Yes --> N1[skip remaining + break]
N -- No --> O[process TLV / free TLV]
|
|
hmm, I think checkpatch is wrong in all three of the files it's complaining about: one branch does a "break", and the other does a "continue", and ... that seems ok to me? |
|
I think greptile's comment about eigrp_query.c is valid- pushing a fix |
|
@greptileai review |
|
@Mergifyio backport stable/10.6 stable/10.5 stable/10.4 stable/10.3 stable/10.2 |
β Backports have been createdDetails
Cherry-pick of 284c966 has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally
Cherry-pick of 284c966 has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally
Cherry-pick of 284c966 has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally
Cherry-pick of 284c966 has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally |
Try to skip unknown TLVs in places where we don't process all types. Reported-by: Haruto Kimura (Stella) <harutokimura0608@gmail.com> Signed-off-by: Mark Stapp <mjs@cisco.com>
|
small re-org to try to satisfy checkpatch... |
eigrpd: improve validation and error-handling in tlv parsing (backport #21316)
eigrpd: improve validation and error-handling in tlv parsing (backport #21316 to 10.5)
eigrpd: improve validation and error-handling in tlv parsing (backport #21316)
Add more length validation before accessing packet data; add error-detection in several paths; try to skip unknown TLV types in more cases.