Skip to content

Commit 552a379

Browse files
committed
bgpd: fix integer overflow in maximum prefix threshold check
bgp_maximum_prefix_overflow() computes the warning threshold as: pcount > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100) Both operands are unsigned integers (pmax is uint32_t, pmax_threshold is uint8_t), so the multiplication is performed in uint32_t arithmetic. When pmax exceeds ~16.7 million (2^24) and the threshold is high (e.g. 75–100), the product overflows uint32_t, wrapping to a small value. This makes the comparison almost always false, silently disabling the prefix threshold warning. RFC 7454 Section 8 recommends maximum prefix limits as a critical defense mechanism against route table exhaustion and runaway BGP sessions. An overflow that silently disables the threshold warning undermines this protection: a peer can continue advertising prefixes well past the configured warning threshold without any log message or notification, delaying operator awareness until the hard limit is reached (or the router runs out of memory). Cast pmax to uint64_t before the multiplication so the product is computed in 64-bit arithmetic, correctly handling prefix limits up to the uint32_t maximum (~4 billion) with any threshold percentage. Signed-off-by: guozhongfeng.gzf <guozhongfeng.gzf@alibaba-inc.com>
1 parent 1da47d4 commit 552a379

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

bgpd/bgp_route.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5364,7 +5364,7 @@ bool bgp_maximum_prefix_overflow(struct peer *peer, afi_t afi, safi_t safi,
53645364
PEER_STATUS_PREFIX_LIMIT);
53655365

53665366
if (pcount
5367-
> (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100)) {
5367+
> ((uint64_t)peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100)) {
53685368
if (CHECK_FLAG(peer->af_sflags[afi][safi],
53695369
PEER_STATUS_PREFIX_THRESHOLD)
53705370
&& !always)

0 commit comments

Comments
 (0)