|
| 1 | +From 530ad90cba0b85ba53f3886a96fd3252eaa2e9c0 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Ritika Chopra <ritika0313@gmail.com> |
| 3 | +Date: Sun, 5 Oct 2025 21:41:46 -0700 |
| 4 | +Subject: [PATCH] T7909-handle-malformed-update-pkts-non-ipv4-int |
| 5 | + |
| 6 | +Code is trying to read more data than is available in the packet stream, leading to crashes. Handling currently added for pkts other than IPv4-Internal route type |
| 7 | +--- |
| 8 | + eigrpd/eigrp_packet.c | 6 ++++++ |
| 9 | + eigrpd/eigrp_update.c | 46 ++++++++++++++++++++++++++++++++++++++++--- |
| 10 | + 2 files changed, 49 insertions(+), 3 deletions(-) |
| 11 | + |
| 12 | +diff --git a/eigrpd/eigrp_packet.c b/eigrpd/eigrp_packet.c |
| 13 | +index 4daff3201..43a36cd7a 100644 |
| 14 | +--- a/eigrpd/eigrp_packet.c |
| 15 | ++++ b/eigrpd/eigrp_packet.c |
| 16 | +@@ -548,6 +548,12 @@ void eigrp_read(struct event *thread) |
| 17 | + /* Advance from IP header to EIGRP header (iph->ip_hl has been verified |
| 18 | + by eigrp_recv_packet() to be correct). */ |
| 19 | + |
| 20 | ++ if((iph->ip_hl * 4) + EIGRP_HEADER_LEN > stream_get_endp(ibuf)) |
| 21 | ++ { |
| 22 | ++ zlog_debug("Malformed packet: IP header extends beyond packet data. IP header len = %u endp = %lu", |
| 23 | ++ iph->ip_hl * 4,stream_get_endp(ibuf)); |
| 24 | ++ return; |
| 25 | ++ } |
| 26 | + stream_forward_getp(ibuf, (iph->ip_hl * 4)); |
| 27 | + eigrph = (struct eigrp_header *)stream_pnt(ibuf); |
| 28 | + |
| 29 | +diff --git a/eigrpd/eigrp_update.c b/eigrpd/eigrp_update.c |
| 30 | +index 7348231c3..5c6d242b9 100644 |
| 31 | +--- a/eigrpd/eigrp_update.c |
| 32 | ++++ b/eigrpd/eigrp_update.c |
| 33 | +@@ -169,6 +169,7 @@ void eigrp_update_receive(struct eigrp *eigrp, struct ip *iph, |
| 34 | + uint8_t graceful_restart_final; |
| 35 | + struct list *nbr_prefixes = NULL; |
| 36 | + |
| 37 | ++ |
| 38 | + /* increment statistics. */ |
| 39 | + ei->update_in++; |
| 40 | + |
| 41 | +@@ -279,6 +280,13 @@ void eigrp_update_receive(struct eigrp *eigrp, struct ip *iph, |
| 42 | + |
| 43 | + /*If there is topology information*/ |
| 44 | + while (s->endp > s->getp) { |
| 45 | ++ /* Ensure we have at least 4 bytes for TLV header */ |
| 46 | ++ if (STREAM_READABLE(s) < 4) { |
| 47 | ++ zlog_debug("End of packet reached, stopping TLV processing"); |
| 48 | ++ stream_forward_getp(s, STREAM_READABLE(s)); |
| 49 | ++ break; |
| 50 | ++ } |
| 51 | ++ |
| 52 | + type = stream_getw(s); |
| 53 | + switch (type) { |
| 54 | + case EIGRP_TLV_IPv4_INT: |
| 55 | +@@ -369,11 +377,43 @@ void eigrp_update_receive(struct eigrp *eigrp, struct ip *iph, |
| 56 | + * for now, lets just not creash the box |
| 57 | + */ |
| 58 | + default: |
| 59 | ++ /* Handle unknown TLV types gracefully */ |
| 60 | ++ zlog_debug("Unknown TLV type: 0x%04x", type); |
| 61 | ++ |
| 62 | ++ /* Validate we have enough data for TLV length */ |
| 63 | ++ if (STREAM_READABLE(s) < 2) { |
| 64 | ++ zlog_warn("Malformed packet: insufficient data for TLV length, skipping to end"); |
| 65 | ++ stream_forward_getp(s, STREAM_READABLE(s)); |
| 66 | ++ break; |
| 67 | ++ } |
| 68 | ++ |
| 69 | + length = stream_getw(s); |
| 70 | +- // -2 for type, -2 for len |
| 71 | +- for (length -= 4; length; length--) { |
| 72 | +- (void)stream_getc(s); |
| 73 | ++ |
| 74 | ++ /* Validate TLV length */ |
| 75 | ++ if (length < 4) { |
| 76 | ++ zlog_warn("Malformed packet: TLV length too small (%u), skipping to end", length); |
| 77 | ++ stream_forward_getp(s, STREAM_READABLE(s)); |
| 78 | ++ break; |
| 79 | + } |
| 80 | ++ |
| 81 | ++ /* Check for reasonable TLV length */ |
| 82 | ++ if (length > 1024) { |
| 83 | ++ zlog_warn("Malformed packet: TLV length too large (%u), skipping to end", length); |
| 84 | ++ stream_forward_getp(s, STREAM_READABLE(s)); |
| 85 | ++ break; |
| 86 | ++ } |
| 87 | ++ |
| 88 | ++ /* Check if TLV extends beyond packet */ |
| 89 | ++ if (length > STREAM_READABLE(s) + 4) { |
| 90 | ++ zlog_warn("Malformed packet: TLV length (%u) exceeds remaining data (%zu) + 4, skipping to end", |
| 91 | ++ length, STREAM_READABLE(s)); |
| 92 | ++ break; |
| 93 | ++ } |
| 94 | ++ /* Skip current TLV data safely to move on to next TLV */ |
| 95 | ++ zlog_debug("Skipping unknown TLV: type=0x%04x, length=%u", type, length); |
| 96 | ++ stream_forward_getp(s, length - 4); |
| 97 | ++ |
| 98 | ++ |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | +-- |
| 103 | +2.47.3 |
| 104 | + |
0 commit comments