Skip to content

Commit a0c4ec2

Browse files
ton31337donaldsharp
authored andcommitted
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 <iggyfran@amazon.com> Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
1 parent 01f232c commit a0c4ec2

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

bgpd/bgp_attr.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3414,15 +3414,6 @@ static int bgp_attr_check(struct peer *peer, struct attr *attr,
34143414
!length)
34153415
return BGP_ATTR_PARSE_WITHDRAW;
34163416

3417-
/* "An UPDATE message that contains the MP_UNREACH_NLRI is not required
3418-
to carry any other path attributes.", though if MP_REACH_NLRI or NLRI
3419-
are present, it should. Check for any other attribute being present
3420-
instead.
3421-
*/
3422-
if ((!CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI)) &&
3423-
CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MP_UNREACH_NLRI))))
3424-
return BGP_ATTR_PARSE_PROCEED;
3425-
34263417
if (!CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_ORIGIN)))
34273418
type = BGP_ATTR_ORIGIN;
34283419

@@ -3441,6 +3432,16 @@ static int bgp_attr_check(struct peer *peer, struct attr *attr,
34413432
&& !CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)))
34423433
type = BGP_ATTR_LOCAL_PREF;
34433434

3435+
/* An UPDATE message that contains the MP_UNREACH_NLRI is not required
3436+
* to carry any other path attributes. Though if MP_REACH_NLRI or NLRI
3437+
* are present, it should. Check for any other attribute being present
3438+
* instead.
3439+
*/
3440+
if (!CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI)) &&
3441+
CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MP_UNREACH_NLRI)))
3442+
return type ? BGP_ATTR_PARSE_MISSING_MANDATORY
3443+
: BGP_ATTR_PARSE_PROCEED;
3444+
34443445
/* If any of the well-known mandatory attributes are not present
34453446
* in an UPDATE message, then "treat-as-withdraw" MUST be used.
34463447
*/

bgpd/bgp_attr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ enum bgp_attr_parse_ret {
379379
/* only used internally, send notify + convert to BGP_ATTR_PARSE_ERROR
380380
*/
381381
BGP_ATTR_PARSE_ERROR_NOTIFYPLS = -3,
382+
BGP_ATTR_PARSE_MISSING_MANDATORY = -4,
382383
};
383384

384385
struct bpacket_attr_vec_arr;

bgpd/bgp_packet.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1983,7 +1983,12 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size)
19831983
/* Network Layer Reachability Information. */
19841984
update_len = end - stream_pnt(s);
19851985

1986-
if (update_len && attribute_len) {
1986+
/* If we received MP_UNREACH_NLRI attribute, but also NLRIs, then
1987+
* NLRIs should be handled as a new data. Though, if we received
1988+
* NLRIs without mandatory attributes, they should be ignored.
1989+
*/
1990+
if (update_len && attribute_len &&
1991+
attr_parse_ret != BGP_ATTR_PARSE_MISSING_MANDATORY) {
19871992
/* Set NLRI portion to structure. */
19881993
nlris[NLRI_UPDATE].afi = AFI_IP;
19891994
nlris[NLRI_UPDATE].safi = SAFI_UNICAST;

0 commit comments

Comments
 (0)