Skip to content

Commit c37119d

Browse files
committed
bgpd: Ignore handling NLRIs if we received MP_UNREACH_NLRI
If we receive MP_UNREACH_NLRI, we should stop handling remaining NLRIs if no mandatory path attributes received. In other words, if MP_UNREACH_NLRI received, the remaining NLRIs should be handled as a new data, but without mandatory attributes, it's a malformed packet. In normal case, this MUST not happen at all, but to avoid crashing bgpd, we MUST handle that. Reported-by: Iggy Frankovic <[email protected]> Signed-off-by: Donatas Abraitis <[email protected]>
1 parent 6814f2e commit c37119d

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

bgpd/bgp_attr.c

+10-9
Original file line numberDiff line numberDiff line change
@@ -3399,15 +3399,6 @@ static int bgp_attr_check(struct peer *peer, struct attr *attr,
33993399
!length)
34003400
return BGP_ATTR_PARSE_WITHDRAW;
34013401

3402-
/* "An UPDATE message that contains the MP_UNREACH_NLRI is not required
3403-
to carry any other path attributes.", though if MP_REACH_NLRI or NLRI
3404-
are present, it should. Check for any other attribute being present
3405-
instead.
3406-
*/
3407-
if ((!CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI)) &&
3408-
CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MP_UNREACH_NLRI))))
3409-
return BGP_ATTR_PARSE_PROCEED;
3410-
34113402
if (!CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_ORIGIN)))
34123403
type = BGP_ATTR_ORIGIN;
34133404

@@ -3426,6 +3417,16 @@ static int bgp_attr_check(struct peer *peer, struct attr *attr,
34263417
&& !CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)))
34273418
type = BGP_ATTR_LOCAL_PREF;
34283419

3420+
/* An UPDATE message that contains the MP_UNREACH_NLRI is not required
3421+
* to carry any other path attributes. Though if MP_REACH_NLRI or NLRI
3422+
* are present, it should. Check for any other attribute being present
3423+
* instead.
3424+
*/
3425+
if (!CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI)) &&
3426+
CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MP_UNREACH_NLRI)))
3427+
return type ? BGP_ATTR_PARSE_MISSING_MANDATORY
3428+
: BGP_ATTR_PARSE_PROCEED;
3429+
34293430
/* If any of the well-known mandatory attributes are not present
34303431
* in an UPDATE message, then "treat-as-withdraw" MUST be used.
34313432
*/

bgpd/bgp_attr.h

+1
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ 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_MISSING_MANDATORY = -4,
367368
};
368369

369370
struct bpacket_attr_vec_arr;

bgpd/bgp_packet.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -2359,7 +2359,12 @@ static int bgp_update_receive(struct peer_connection *connection,
23592359
/* Network Layer Reachability Information. */
23602360
update_len = end - stream_pnt(s);
23612361

2362-
if (update_len && attribute_len) {
2362+
/* If we received MP_UNREACH_NLRI attribute, but also NLRIs, then
2363+
* NLRIs should be handled as a new data. Though, if we received
2364+
* NLRIs without mandatory attributes, they should be ignored.
2365+
*/
2366+
if (update_len && attribute_len &&
2367+
attr_parse_ret != BGP_ATTR_PARSE_MISSING_MANDATORY) {
23632368
/* Set NLRI portion to structure. */
23642369
nlris[NLRI_UPDATE].afi = AFI_IP;
23652370
nlris[NLRI_UPDATE].safi = SAFI_UNICAST;

0 commit comments

Comments
 (0)