]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ospfd: Solved crash in RI parsing with OSPF TE
authorOlivier Dugeon <olivier.dugeon@orange.com>
Wed, 3 Apr 2024 14:28:23 +0000 (16:28 +0200)
committerMergify <37929162+mergify[bot]@users.noreply.github.com>
Fri, 24 May 2024 19:32:27 +0000 (19:32 +0000)
Iggy Frankovic discovered another ospfd crash when performing fuzzing of OSPF
LSA packets. The crash occurs in ospf_te_parse_ri() function when attemping to
read Segment Routing subTLVs. The original code doesn't check if the size of
the SR subTLVs have the correct length. In presence of erronous LSA, this will
cause a buffer overflow and ospfd crash.

This patch introduces new verification of the subTLVs size for Router
Information TLV.

Co-authored-by: Iggy Frankovic <iggyfran@amazon.com>
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
(cherry picked from commit f69d1313b19047d3d83fc2b36a518355b861dfc4)

ospfd/ospf_te.c

index 1a01bf77b88350ff23873595169ffc1831fec145..a48534703ff227c86f934dcfd4a273159d25ec1b 100644 (file)
@@ -2455,6 +2455,9 @@ static int ospf_te_parse_ri(struct ls_ted *ted, struct ospf_lsa *lsa)
 
                switch (ntohs(tlvh->type)) {
                case RI_SR_TLV_SR_ALGORITHM:
+                       if (TLV_BODY_SIZE(tlvh) < 1 ||
+                           TLV_BODY_SIZE(tlvh) > ALGORITHM_COUNT)
+                               break;
                        algo = (struct ri_sr_tlv_sr_algorithm *)tlvh;
 
                        for (int i = 0; i < ntohs(algo->header.length); i++) {
@@ -2479,6 +2482,8 @@ static int ospf_te_parse_ri(struct ls_ted *ted, struct ospf_lsa *lsa)
                        break;
 
                case RI_SR_TLV_SRGB_LABEL_RANGE:
+                       if (TLV_BODY_SIZE(tlvh) != RI_SR_TLV_LABEL_RANGE_SIZE)
+                               break;
                        range = (struct ri_sr_tlv_sid_label_range *)tlvh;
                        size = GET_RANGE_SIZE(ntohl(range->size));
                        lower = GET_LABEL(ntohl(range->lower.value));
@@ -2496,6 +2501,8 @@ static int ospf_te_parse_ri(struct ls_ted *ted, struct ospf_lsa *lsa)
                        break;
 
                case RI_SR_TLV_SRLB_LABEL_RANGE:
+                       if (TLV_BODY_SIZE(tlvh) != RI_SR_TLV_LABEL_RANGE_SIZE)
+                               break;
                        range = (struct ri_sr_tlv_sid_label_range *)tlvh;
                        size = GET_RANGE_SIZE(ntohl(range->size));
                        lower = GET_LABEL(ntohl(range->lower.value));
@@ -2513,6 +2520,8 @@ static int ospf_te_parse_ri(struct ls_ted *ted, struct ospf_lsa *lsa)
                        break;
 
                case RI_SR_TLV_NODE_MSD:
+                       if (TLV_BODY_SIZE(tlvh) < RI_SR_TLV_NODE_MSD_SIZE)
+                               break;
                        msd = (struct ri_sr_tlv_node_msd *)tlvh;
                        if ((CHECK_FLAG(node->flags, LS_NODE_MSD))
                            && (node->msd == msd->value))