[lvc-project] [PATCH] openvswitch: fix band bucket value computation in ovs_meter_execute()

Dmitry Kandybka d.kandybka at gmail.com
Tue Apr 22 00:28:34 MSK 2025


In ovs_meter_execute(), promote 'delta_ms' to 'long long int' to avoid
possible integer overflow. It's assumed that'delta_ms' and 'band->rate'
multiplication leads to overcomming UINT32_MAX.
Compile tested only.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Dmitry Kandybka <d.kandybka at gmail.com>
---
 net/openvswitch/meter.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/openvswitch/meter.c b/net/openvswitch/meter.c
index cc08e0403909..2fab53ac60a8 100644
--- a/net/openvswitch/meter.c
+++ b/net/openvswitch/meter.c
@@ -594,11 +594,11 @@ bool ovs_meter_execute(struct datapath *dp, struct sk_buff *skb,
 {
 	long long int now_ms = div_u64(ktime_get_ns(), 1000 * 1000);
 	long long int long_delta_ms;
+	long long int delta_ms;
 	struct dp_meter_band *band;
 	struct dp_meter *meter;
 	int i, band_exceeded_max = -1;
 	u32 band_exceeded_rate = 0;
-	u32 delta_ms;
 	u32 cost;
 
 	meter = lookup_meter(&dp->meter_tbl, meter_id);
@@ -623,7 +623,7 @@ bool ovs_meter_execute(struct datapath *dp, struct sk_buff *skb,
 	 * wrap around below.
 	 */
 	delta_ms = (long_delta_ms > (long long int)meter->max_delta_t)
-		   ? meter->max_delta_t : (u32)long_delta_ms;
+		   ? meter->max_delta_t : long_delta_ms;
 
 	/* Update meter statistics.
 	 */
-- 
2.43.5




More information about the lvc-project mailing list