Commit 4d1f1ef356 for frr

commit 4d1f1ef3564ccb85b0339bef9071ea0502d5fec4
Author: Dilshad Tanveer <dilshad@labs.digiscrypt.com>
Date:   Tue Oct 27 21:45:07 2026 +0530

    ospfd: cap Extended Prefix SID prefix length before route lookup

    get_ext_prefix_sid() copies the Extended Prefix TLV pref_length byte
    straight from the wire into srp->prefv4.prefixlen, and apply_mask_ipv4()
    only masks the address, so any value up to 255 survives. ospf_lsa_examin()
    checks nothing but 4-byte alignment for opaque LSAs, so the field is never
    range-checked before that point.

    The Prefix-SID is then looked up in the OSPF route table on the receive
    path (ospf_ext_pref_lsa_update -> ospf_sr_ext_prefix_lsa_update ->
    get_ext_prefix_sid -> update_ext_prefix_sid -> compute_prefix_nhlfe ->
    get_nexthop_by_addr). route_node_lookup() hashes the prefix with
    prefix_hash_key(), where jhash reads offsetof(struct prefix, u.prefix) +
    PSIZE(prefixlen) bytes. With pref_length = 255 that is 40 bytes out of a
    24-byte struct prefix, a read past the end of the object, and prefix_cmp()
    walks prefixlen / 8 = 31 bytes the same way. A neighbor flooding an
    Extended Prefix opaque LSA with pref_length = 0xff is enough to reach it.

    Reject pref_length > IPV4_MAX_BITLEN in the getter, beside the existing
    sub-TLV size and algorithm checks, and drop the Prefix-SID the same way
    those do.

    Signed-off-by: Dilshad Tanveer <dilshad@labs.digiscrypt.com>

diff --git a/ospfd/ospf_sr.c b/ospfd/ospf_sr.c
index 707fe99e95..6a0beb1e29 100644
--- a/ospfd/ospf_sr.c
+++ b/ospfd/ospf_sr.c
@@ -1157,6 +1157,12 @@ static struct sr_prefix *get_ext_prefix_sid(struct tlv_header *tlvh,
 				XFREE(MTYPE_OSPF_SR_PARAMS, srp);
 				return NULL;
 			}
+			if (pref->pref_length > IPV4_MAX_BITLEN) {
+				zlog_warn("SR : Invalid Extended Prefix length %u",
+					  pref->pref_length);
+				XFREE(MTYPE_OSPF_SR_PARAMS, srp);
+				return NULL;
+			}
 			srp->type = PREF_SID;
 			srp->flags = psid->flags;
 			if (CHECK_FLAG(psid->flags, EXT_SUBTLV_PREFIX_SID_VFLG))