Commit 954d9416b7 for frr
commit 954d9416b77f2e926671d42a3da5a744fe64657c
Author: Donatas Abraitis <donatas@opensourcerouting.org>
Date: Mon Nov 30 17:18:29 2026 +0200
bgpd: Fix dangling intern-reuse cache
A filtered route could free the attribute still held by the reuse
cache, so the next prefix in the same UPDATE used freed memory.
Also reset the cache after every NLRI section.
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c
index 1751848d3f..bab78c9618 100644
--- a/bgpd/bgp_packet.c
+++ b/bgpd/bgp_packet.c
@@ -312,27 +312,37 @@ static void bgp_update_explicit_eors(struct peer_connection *connection)
int bgp_nlri_parse(struct peer *peer, struct attr *attr,
struct bgp_nlri *packet, bool mp_withdraw)
{
+ int ret = BGP_NLRI_PARSE_ERROR;
+
switch (packet->safi) {
case SAFI_UNICAST:
case SAFI_MULTICAST:
- return bgp_nlri_parse_ip(peer, mp_withdraw ? NULL : attr,
- packet);
+ ret = bgp_nlri_parse_ip(peer, mp_withdraw ? NULL : attr, packet);
+ break;
case SAFI_LABELED_UNICAST:
- return bgp_nlri_parse_label(peer, mp_withdraw ? NULL : attr,
- packet);
+ ret = bgp_nlri_parse_label(peer, mp_withdraw ? NULL : attr, packet);
+ break;
case SAFI_MPLS_VPN:
- return bgp_nlri_parse_vpn(peer, mp_withdraw ? NULL : attr,
- packet);
+ ret = bgp_nlri_parse_vpn(peer, mp_withdraw ? NULL : attr, packet);
+ break;
case SAFI_EVPN:
- return bgp_nlri_parse_evpn(peer, attr, packet, mp_withdraw);
+ ret = bgp_nlri_parse_evpn(peer, attr, packet, mp_withdraw);
+ break;
case SAFI_FLOWSPEC:
- return bgp_nlri_parse_flowspec(peer, attr, packet, mp_withdraw);
+ ret = bgp_nlri_parse_flowspec(peer, attr, packet, mp_withdraw);
+ break;
case SAFI_BGP_LS:
- return bgp_nlri_parse_ls(peer, mp_withdraw ? NULL : attr, packet);
+ ret = bgp_nlri_parse_ls(peer, mp_withdraw ? NULL : attr, packet);
+ break;
case SAFI_UNREACH:
- return bgp_nlri_parse_unreach(peer, attr, packet, mp_withdraw);
+ ret = bgp_nlri_parse_unreach(peer, attr, packet, mp_withdraw);
+ break;
}
- return BGP_NLRI_PARSE_ERROR;
+
+ if (attr)
+ memset(&attr->attr_intern_reuse, 0, sizeof(attr->attr_intern_reuse));
+
+ return ret;
}
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
index 04a30b3884..8a1cc94905 100644
--- a/bgpd/bgp_route.c
+++ b/bgpd/bgp_route.c
@@ -7260,7 +7260,7 @@ filtered:
if (new) {
bgp_unlink_nexthop(new);
bgp_path_info_mark_for_delete(dest, new);
- bgp_attr_unintern(&new->attr);
+ bgp_attr_unintern_clear_reuse(attr, &new->attr);
bgp_path_info_extra_free(&new->extra);
XFREE(MTYPE_BGP_ROUTE, new);
}