Skip to content

bgpd: Avoid cluster list attribute truncation#22081

Merged
donaldsharp merged 1 commit into
FRRouting:masterfrom
opensourcerouting:fix/bgp_cluster_list_truncation
Jun 2, 2026
Merged

bgpd: Avoid cluster list attribute truncation#22081
donaldsharp merged 1 commit into
FRRouting:masterfrom
opensourcerouting:fix/bgp_cluster_list_truncation

Conversation

@ton31337
Copy link
Copy Markdown
Member

No description provided.

RFC 4271 4.3 says:

 The fourth high-order bit (bit 3) of the Attribute Flags octet
 is the Extended Length bit.  It defines whether the Attribute
 Length is one octet (if set to 0) or two octets (if set to 1).

 The lower-order four bits of the Attribute Flags octet are
 unused.  They MUST be zero when sent and MUST be ignored when
 received.

 If the Extended Length bit of the Attribute Flags octet is set
 to 0, the third octet of the Path Attribute contains the length
 of the attribute data in octets.

 If the Extended Length bit of the Attribute Flags octet is set
 to 1, the third and fourth octets of the path attribute contain
 the length of the attribute data in octets.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 27, 2026

Greptile Summary

This PR fixes a silent truncation bug in the BGP cluster list attribute encoding: when the total cluster list value exceeds 255 bytes, the old code called stream_putc for the length field, silently wrapping the value to its low 8 bits. The fix follows the same pattern already used for communities, large communities, and extended communities — switching to the RFC 4271 Extended Length encoding (BGP_ATTR_FLAG_EXTLEN + two-byte stream_putw) when cluster->length + 4 > 255.

  • The condition cluster && cluster->length + 4 > 255 correctly gates the extended-length path; the cluster == NULL case falls through to the else branch and always fits in one byte.
  • Duplicate router-id/cluster-id write logic from both branches of the original if (cluster) / else block is properly consolidated after the header-encoding split.

Confidence Score: 5/5

Safe to merge. The change is a targeted bug fix for a well-understood truncation path, follows an existing pattern already in the file, and the receive side already handles extended-length for all attributes.

The fix is self-contained, touches only the cluster list attribute encoding branch, and mirrors the identical extended-length pattern already applied to communities, large communities, and ecommunities in the same function. The receiving parser's extended-length handling at the attribute-loop level means no receive-side change is needed, and the flag-validation code already masks out EXTLEN before comparing. No edge-case regressions were identified.

No files require special attention.

Important Files Changed

Filename Overview
bgpd/bgp_attr.c Adds RFC 4271 Extended Length encoding for CLUSTER_LIST when total value length exceeds 255 bytes; consolidates duplicate cluster-id write logic; logic is correct and symmetric with the already-present extended-length handling on the receive path.

Reviews (1): Last reviewed commit: "bgpd: Avoid cluster list attribute trunc..." | Re-trigger Greptile

@ton31337
Copy link
Copy Markdown
Member Author

@Mergifyio backport stable/10.6 stable/10.5 stable/10.4 stable/10.3 stable/10.2

@mergify
Copy link
Copy Markdown

mergify Bot commented May 27, 2026

backport stable/10.6 stable/10.5 stable/10.4 stable/10.3 stable/10.2

✅ Backports have been created

Details

Comment thread bgpd/bgp_attr.c
else
stream_put_in_addr(s, &bgp->router_id);
stream_putc(s, BGP_ATTR_FLAG_OPTIONAL);
stream_putc(s, BGP_ATTR_CLUSTER_LIST);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not move these two lines outside the if/else and remove lines 5730 and 5731

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's valid, but IMO, this doesn't do anything with the relevant fix. We should then fix this together with BGP_ATTR_LARGE_COMMUNITIES, BGP_ATTR_COMMUNITIES, etc. (the same pattern).

Copy link
Copy Markdown
Member

@riw777 riw777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

@donaldsharp donaldsharp merged commit f5c7c60 into FRRouting:master Jun 2, 2026
25 checks passed
donaldsharp added a commit that referenced this pull request Jun 2, 2026
bgpd: Avoid cluster list attribute truncation (backport #22081)
donaldsharp added a commit that referenced this pull request Jun 2, 2026
bgpd: Avoid cluster list attribute truncation (backport #22081)
donaldsharp added a commit that referenced this pull request Jun 2, 2026
bgpd: Avoid cluster list attribute truncation (backport #22081)
donaldsharp added a commit that referenced this pull request Jun 2, 2026
bgpd: Avoid cluster list attribute truncation (backport #22081)
donaldsharp added a commit that referenced this pull request Jun 2, 2026
bgpd: Avoid cluster list attribute truncation (backport #22081)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants