Skip to content

Commit b08afc8

Browse files
committed
bgpd: Handle MP_REACH_NLRI malformed packets with session reset
Avoid crashing bgpd. ``` (gdb) bgp_mp_reach_parse (args=<optimized out>, mp_update=0x7fffffffe140) at bgpd/bgp_attr.c:2341 2341 stream_get(&attr->mp_nexthop_global, s, IPV6_MAX_BYTELEN); (gdb) stream_get (dst=0x7fffffffe1ac, s=0x7ffff0006e80, size=16) at lib/stream.c:320 320 { (gdb) 321 STREAM_VERIFY_SANE(s); (gdb) 323 if (STREAM_READABLE(s) < size) { (gdb) 34 return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest)); (gdb) Thread 1 "bgpd" received signal SIGSEGV, Segmentation fault. 0x00005555556e37be in route_set_aspath_prepend (rule=0x555555aac0d0, prefix=0x7fffffffe050, object=0x7fffffffdb00) at bgpd/bgp_routemap.c:2282 2282 if (path->attr->aspath->refcnt) (gdb) ``` With the configuration: ``` neighbor 127.0.0.1 remote-as external neighbor 127.0.0.1 passive neighbor 127.0.0.1 ebgp-multihop neighbor 127.0.0.1 disable-connected-check neighbor 127.0.0.1 update-source 127.0.0.2 neighbor 127.0.0.1 timers 3 90 neighbor 127.0.0.1 timers connect 1 address-family ipv4 unicast redistribute connected neighbor 127.0.0.1 default-originate neighbor 127.0.0.1 route-map RM_IN in exit-address-family ! route-map RM_IN permit 10 set as-path prepend 200 exit ``` Reported-by: Iggy Frankovic <iggyfran@amazon.com> Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
1 parent 01d84db commit b08afc8

3 files changed

Lines changed: 2 additions & 11 deletions

File tree

bgpd/bgp_attr.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2421,7 +2421,7 @@ int bgp_mp_reach_parse(struct bgp_attr_parser_args *args,
24212421

24222422
mp_update->afi = afi;
24232423
mp_update->safi = safi;
2424-
return BGP_ATTR_PARSE_EOR;
2424+
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_MAL_ATTR, 0);
24252425
}
24262426

24272427
mp_update->afi = afi;
@@ -3759,10 +3759,6 @@ enum bgp_attr_parse_ret bgp_attr_parse(struct peer *peer, struct attr *attr,
37593759
goto done;
37603760
}
37613761

3762-
if (ret == BGP_ATTR_PARSE_EOR) {
3763-
goto done;
3764-
}
3765-
37663762
if (ret == BGP_ATTR_PARSE_ERROR) {
37673763
flog_warn(EC_BGP_ATTRIBUTE_PARSE_ERROR,
37683764
"%s: Attribute %s, parse error", peer->host,

bgpd/bgp_attr.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ enum bgp_attr_parse_ret {
364364
/* only used internally, send notify + convert to BGP_ATTR_PARSE_ERROR
365365
*/
366366
BGP_ATTR_PARSE_ERROR_NOTIFYPLS = -3,
367-
BGP_ATTR_PARSE_EOR = -4,
368367
};
369368

370369
struct bpacket_attr_vec_arr;

bgpd/bgp_packet.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,8 +2397,7 @@ static int bgp_update_receive(struct peer_connection *connection,
23972397
* Non-MP IPv4/Unicast EoR is a completely empty UPDATE
23982398
* and MP EoR should have only an empty MP_UNREACH
23992399
*/
2400-
if ((!update_len && !withdraw_len && nlris[NLRI_MP_UPDATE].length == 0)
2401-
|| (attr_parse_ret == BGP_ATTR_PARSE_EOR)) {
2400+
if (!update_len && !withdraw_len && nlris[NLRI_MP_UPDATE].length == 0) {
24022401
afi_t afi = 0;
24032402
safi_t safi;
24042403
struct graceful_restart_info *gr_info;
@@ -2419,9 +2418,6 @@ static int bgp_update_receive(struct peer_connection *connection,
24192418
&& nlris[NLRI_MP_WITHDRAW].length == 0) {
24202419
afi = nlris[NLRI_MP_WITHDRAW].afi;
24212420
safi = nlris[NLRI_MP_WITHDRAW].safi;
2422-
} else if (attr_parse_ret == BGP_ATTR_PARSE_EOR) {
2423-
afi = nlris[NLRI_MP_UPDATE].afi;
2424-
safi = nlris[NLRI_MP_UPDATE].safi;
24252421
}
24262422

24272423
if (afi && peer->afc[afi][safi]) {

0 commit comments

Comments
 (0)