|
| 1 | +From dfc8716b0a8de82545502fedc7dd2e59e8a64293 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Mark Stapp <mjs@cisco.com> |
| 3 | +Date: Wed, 11 Mar 2026 14:52:54 -0400 |
| 4 | +Subject: [PATCH] bgpd: improve packet parsing for EVPN and ENCAP/VNC |
| 5 | + |
| 6 | +Improve packet validation for EVPN NLRIs and for ENCAP/VNC. |
| 7 | + |
| 8 | +Signed-off-by: Mark Stapp <mjs@cisco.com> |
| 9 | +(cherry picked from commit 7676cad65114aa23adde583d91d9d29e2debd045) |
| 10 | +Signed-off-by: Azure Linux Security Servicing Account <azurelinux-security@microsoft.com> |
| 11 | +Upstream-reference: https://github.com/FRRouting/frr/commit/52c72c5ad8ccb491a9bab096002072667089d2d3.patch |
| 12 | +--- |
| 13 | + bgpd/bgp_evpn.c | 17 +++++++++++++++++ |
| 14 | + bgpd/bgp_evpn_mh.c | 10 +++++++++- |
| 15 | + bgpd/rfapi/rfapi_rib.c | 9 +++++++++ |
| 16 | + 3 files changed, 35 insertions(+), 1 deletion(-) |
| 17 | + |
| 18 | +diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c |
| 19 | +index 2b2cfa0..e45bd46 100644 |
| 20 | +--- a/bgpd/bgp_evpn.c |
| 21 | ++++ b/bgpd/bgp_evpn.c |
| 22 | +@@ -4505,6 +4505,14 @@ static int process_type2_route(struct peer *peer, afi_t afi, safi_t safi, |
| 23 | + goto fail; |
| 24 | + } |
| 25 | + |
| 26 | ++ /* Validate ipaddr_len against the NLRI length */ |
| 27 | ++ if ((psize != 33 + (ipaddr_len / 8)) && (psize != 36 + (ipaddr_len / 8))) { |
| 28 | ++ flog_err(EC_BGP_EVPN_ROUTE_INVALID, |
| 29 | ++ "%u:%s - Rx EVPN Type-2 NLRI with invalid IP address length %d", |
| 30 | ++ peer->bgp->vrf_id, peer->host, ipaddr_len); |
| 31 | ++ goto fail; |
| 32 | ++ } |
| 33 | ++ |
| 34 | + if (ipaddr_len) { |
| 35 | + ipaddr_len /= 8; /* Convert to bytes. */ |
| 36 | + p.prefix.macip_addr.ip.ipa_type = (ipaddr_len == IPV4_MAX_BYTELEN) |
| 37 | +@@ -4603,6 +4611,15 @@ static int process_type3_route(struct peer *peer, afi_t afi, safi_t safi, |
| 38 | + |
| 39 | + /* Get the IP. */ |
| 40 | + ipaddr_len = *pfx++; |
| 41 | ++ |
| 42 | ++ /* Validate */ |
| 43 | ++ if (psize != 13 + (ipaddr_len / 8)) { |
| 44 | ++ flog_err(EC_BGP_EVPN_ROUTE_INVALID, |
| 45 | ++ "%u:%s - Rx EVPN Type-3 NLRI with invalid IP address length %d", |
| 46 | ++ peer->bgp->vrf_id, peer->host, ipaddr_len); |
| 47 | ++ return -1; |
| 48 | ++ } |
| 49 | ++ |
| 50 | + if (ipaddr_len == IPV4_MAX_BITLEN) { |
| 51 | + p.prefix.imet_addr.ip.ipa_type = IPADDR_V4; |
| 52 | + memcpy(&p.prefix.imet_addr.ip.ip.addr, pfx, IPV4_MAX_BYTELEN); |
| 53 | +diff --git a/bgpd/bgp_evpn_mh.c b/bgpd/bgp_evpn_mh.c |
| 54 | +index 5523659..548e9de 100644 |
| 55 | +--- a/bgpd/bgp_evpn_mh.c |
| 56 | ++++ b/bgpd/bgp_evpn_mh.c |
| 57 | +@@ -733,9 +733,17 @@ int bgp_evpn_type4_route_process(struct peer *peer, afi_t afi, safi_t safi, |
| 58 | + memcpy(&esi, pfx, ESI_BYTES); |
| 59 | + pfx += ESI_BYTES; |
| 60 | + |
| 61 | +- |
| 62 | + /* Get the IP. */ |
| 63 | + ipaddr_len = *pfx++; |
| 64 | ++ |
| 65 | ++ /* Validate */ |
| 66 | ++ if (psize != 19 + (ipaddr_len / 8)) { |
| 67 | ++ flog_err(EC_BGP_EVPN_ROUTE_INVALID, |
| 68 | ++ "%u:%s - Rx EVPN Type-4 NLRI with invalid IP address length %d", |
| 69 | ++ peer->bgp->vrf_id, peer->host, ipaddr_len); |
| 70 | ++ return -1; |
| 71 | ++ } |
| 72 | ++ |
| 73 | + if (ipaddr_len == IPV4_MAX_BITLEN) { |
| 74 | + memcpy(&vtep_ip, pfx, IPV4_MAX_BYTELEN); |
| 75 | + } else { |
| 76 | +diff --git a/bgpd/rfapi/rfapi_rib.c b/bgpd/rfapi/rfapi_rib.c |
| 77 | +index a9c0c02..71fcab0 100644 |
| 78 | +--- a/bgpd/rfapi/rfapi_rib.c |
| 79 | ++++ b/bgpd/rfapi/rfapi_rib.c |
| 80 | +@@ -648,11 +648,20 @@ static void rfapiRibBi2Ri(struct bgp_path_info *bpi, struct rfapi_info *ri, |
| 81 | + break; |
| 82 | + |
| 83 | + case BGP_VNC_SUBTLV_TYPE_RFPOPTION: |
| 84 | ++ /* Check for short subtlv: drop */ |
| 85 | ++ if (pEncap->length < 3) |
| 86 | ++ break; |
| 87 | ++ |
| 88 | ++ /* Length of zero not valid */ |
| 89 | ++ if (pEncap->value[1] == 0) |
| 90 | ++ break; |
| 91 | ++ |
| 92 | + hop = XCALLOC(MTYPE_BGP_TEA_OPTIONS, |
| 93 | + sizeof(struct bgp_tea_options)); |
| 94 | + assert(hop); |
| 95 | + hop->type = pEncap->value[0]; |
| 96 | + hop->length = pEncap->value[1]; |
| 97 | ++ |
| 98 | + hop->value = XCALLOC(MTYPE_BGP_TEA_OPTIONS_VALUE, |
| 99 | + pEncap->length - 2); |
| 100 | + assert(hop->value); |
| 101 | +-- |
| 102 | +2.45.4 |
| 103 | + |
0 commit comments