Skip to content

ospfd: validate extended prefix TLV before accessing prefix SID - #22215

Merged
donaldsharp merged 1 commit into
FRRouting:masterfrom
mjstapp:fix_ospf_pref_sid_size
Jun 4, 2026
Merged

ospfd: validate extended prefix TLV before accessing prefix SID#22215
donaldsharp merged 1 commit into
FRRouting:masterfrom
mjstapp:fix_ospf_pref_sid_size

Conversation

@mjstapp

@mjstapp mjstapp commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Ensure the extended-prefix TLV contains enough data before accessing a prefix-SID sub-tlv.

Ensure the extended-prefix TLV contains enough data
before accessing a prefix-SID sub-tlv.

Signed-off-by: Mark Stapp <mjs@cisco.com>
Reported-by: luzhixiang <lzx0xf1@gmail.com>
@mjstapp

mjstapp commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio backport stable/10.6 stable/10.5

@mergify

mergify Bot commented Jun 4, 2026

Copy link
Copy Markdown

backport stable/10.6 stable/10.5

βœ… Backports have been created

Details

@greptile-apps

greptile-apps Bot commented Jun 4, 2026

Copy link
Copy Markdown

Greptile Summary

Adds a defensive length check in ospf_te_parse_ext_pref to ensure the extended-prefix TLV body is large enough to hold both the prefix TLV data and a prefix-SID sub-TLV before the code casts and dereferences a pointer into that region.

  • Bounds guard added: before computing pref_sid, a new check ensures len >= TLV_HDR_SIZE + EXT_TLV_PREFIX_SIZE + EXT_SUBTLV_PREFIX_SID_SIZE (i.e. β‰₯ 20 bytes), covering the 4-byte outer TLV header offset, the 8-byte prefix body, and the 12-byte prefix-SID sub-TLV; previously a crafted or malformed LSA with a short body could trigger a heap over-read.
  • No functional change when the TLV is well-formed; the new path only fires for unusually short TLVs that would have produced undefined behaviour before.

Confidence Score: 5/5

Safe to merge; the change is a minimal, targeted guard that prevents a heap over-read on malformed LSAs without altering any well-formed code path.

The arithmetic in the new check is correct: the TLV body must be at least 20 bytes to safely reach every field accessed via the pref_sid pointer. All existing checks pass before this new one, and the function's return-on-failure pattern is consistent with the rest of the function.

No files require special attention.

Important Files Changed

Filename Overview
ospfd/ospf_te.c Adds a single bounds check before the fixed-offset pointer cast to ext_subtlv_prefix_sid; the arithmetic is correct (TLV_HDR_SIZE=4 + EXT_TLV_PREFIX_SIZE=8 + EXT_SUBTLV_PREFIX_SID_SIZE=8 = 20 bytes minimum body), and the change does not affect any other code path.

Reviews (1): Last reviewed commit: "ospfd: validate extended prefix TLV befo..." | Re-trigger Greptile

@donaldsharp
donaldsharp merged commit da2c34a into FRRouting:master Jun 4, 2026
25 checks passed
donaldsharp added a commit that referenced this pull request Jun 4, 2026
ospfd: validate extended prefix TLV before accessing prefix SID (backport #22215)
donaldsharp added a commit that referenced this pull request Jun 4, 2026
ospfd: validate extended prefix TLV before accessing prefix SID (backport #22215)
@mjstapp
mjstapp deleted the fix_ospf_pref_sid_size branch June 15, 2026 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants