Skip to contentSkip to conversation

net: sched: taprio: Fix potential integer overflow in taprio_set_picos_per_byte

PATCH In review Vladimir Oltean 3 participants 3 messages Sep 28, 2019 – Oct 1, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: sched: taprio: Fix potential integer overflow in taprio_set_picos_per_byte

The speed divisor is used in a context expecting an s64, but it is evaluated using 32-bit arithmetic.

To avoid that happening, instead of multiplying by 1,000,000 in the first place, simplify the fraction and do a standard 32 bit division instead.

Fixes f04b514c0ce2 ("taprio: Set default link speed to 10 Mbps in taprio_set_picos_per_byte")
---
 net/sched/sch_taprio.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/sched/sch_taprio.c +1 -2
index 2f7b34205c82..2aab46ada94f 100644
@@ -1048,8 +1048,7 @@ static void taprio_set_picos_per_byte(struct net_device *dev,
 		speed = ecmd.base.speed;
 
 skip:
-	picos_per_byte = div64_s64(NSEC_PER_SEC * 1000LL * 8,
-				   speed * 1000 * 1000);
+	picos_per_byte = (USEC_PER_SEC * 8) / speed;
 
 	atomic64_set(&q->picos_per_byte, picos_per_byte);
 	netdev_dbg(dev, "taprio: set %s's picos_per_byte to: %lld, linkspeed: %d\n",
Signature · 1 line
2.17.1
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 7 lines · Vladimir Oltean

The speed divisor is used in a context expecting an s64, but it is evaluated using 32-bit arithmetic.

To avoid that happening, instead of multiplying by 1,000,000 in the first place, simplify the fraction and do a standard 32 bit division instead.

Quoted 5 lines
Fixes f04b514c0ce2 ("taprio: Set default link speed to 10 Mbps in taprio_set_picos_per_byte")

---

maintainer
#2 lore raw
In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>
Date: Sun, 29 Sep 2019 02:01:39 +0300

Quoted 11 lines

The speed divisor is used in a context expecting an s64, but it is evaluated using 32-bit arithmetic.

To avoid that happening, instead of multiplying by 1,000,000 in the first place, simplify the fraction and do a standard 32 bit division instead.

Fixes f04b514c0ce2 ("taprio: Set default link speed to 10 Mbps in taprio_set_picos_per_byte")

Applied and queued up for -stable, thanks.