Commit 552a379
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
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5364 | 5364 | | |
5365 | 5365 | | |
5366 | 5366 | | |
5367 | | - | |
| 5367 | + | |
5368 | 5368 | | |
5369 | 5369 | | |
5370 | 5370 | | |
| |||
0 commit comments