From 413ad6d87797c469702c50368d6563a9cca89457 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sat, 21 Nov 2026 17:38:42 +0100 Subject: [PATCH 1/2] confd: guard the gated CBS slope against a gate that never opens Coverity flags a division by zero in gen_cbs(), CID 566178, where the idle slope is scaled by the cycle over the gate's open time. Validation rejects a credit-based shaper on a gate that never opens, but nothing in gen_cbs() itself says so. Leave the slope unscaled when the open time is zero. Signed-off-by: Joachim Wiberg --- src/confd/src/if-qos.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/confd/src/if-qos.c b/src/confd/src/if-qos.c index 8acbfad1d..3a0580b6a 100644 --- a/src/confd/src/if-qos.c +++ b/src/confd/src/if-qos.c @@ -1133,7 +1133,8 @@ static void gen_cbs(FILE *fp, const char *ifname, struct qos_egress *eg, int han uint64_t cycle = qos_gate_cycle(&eg->gates); uint64_t open = qos_gate_open(&eg->gates, tc); - bps = bps / open * cycle + bps % open * cycle / open; + if (open) + bps = bps / open * cycle + bps % open * cycle / open; } idle = (bps + 999) / 1000; band = by_queue ? tc + 1 : eg->num_tc - tc; From 5475e50dac1efb125542b762adf0d66d35309074 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sat, 21 Nov 2026 17:38:43 +0100 Subject: [PATCH 2/2] confd: bound the port speed before converting it to bps Coverity flags the Mbps to bps conversion in qos_port_rate() and qos_link_rate(), CID 566177 and 566179. The speed is a long read from sysfs or parsed from ethtool output, so the tool sees a value that may be negative, or large enough to wrap, when cast and multiplied. Convert in one place, qos_bps(), which falls back to a gigabit for a speed outside 1 Mbps to 1 Tbps. Signed-off-by: Joachim Wiberg --- src/confd/src/if-qos.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/confd/src/if-qos.c b/src/confd/src/if-qos.c index 3a0580b6a..04a153ff0 100644 --- a/src/confd/src/if-qos.c +++ b/src/confd/src/if-qos.c @@ -15,6 +15,7 @@ #define MAX_TC 8 #define FRAME_OVERHEAD 22 /* Ethernet header, VLAN tag and FCS beyond the MTU */ #define MAX_GATE_ENTRIES 1024 /* where the port names no limit of its own */ +#define MAX_MBPS 1000000 /* 1 Tbps, bounds a speed read from the system */ #define NSEC_PER_SEC 1000000000ULL /* @@ -575,6 +576,15 @@ static long qos_max_speed(const char *ifname) return max; } +/* Mbps to bits per second, a gigabit for a speed no port links at. */ +static uint64_t qos_bps(long mbps) +{ + if (mbps <= 0 || mbps > MAX_MBPS) + mbps = 1000; + + return (uint64_t)mbps * 1000000; +} + /* The port's highest rate in bits per second, a gigabit when it is virtual. */ static uint64_t qos_port_rate(const char *ifname) { @@ -583,7 +593,7 @@ static uint64_t qos_port_rate(const char *ifname) if (!speed) speed = qos_sysfs_long(ifname, "speed", 1000); - return (uint64_t)speed * 1000000; + return qos_bps(speed); } /* Link rate in bits per second, the port's highest while the link is down. */ @@ -591,7 +601,7 @@ static uint64_t qos_link_rate(const char *ifname) { long speed = qos_sysfs_long(ifname, "speed", 0); - return speed ? (uint64_t)speed * 1000000 : qos_port_rate(ifname); + return speed ? qos_bps(speed) : qos_port_rate(ifname); } /*