Skip to content

Commit 4576100

Browse files
n132kuba-moo
authored andcommitted
net/sched: sch_hfsc: fix divide-by-zero in rtsc_min()
m2sm() converts a u32 slope to a u64 scaled value. For large inputs (e.g. m1=4000000000), the result can reach 2^32. rtsc_min() stores the difference of two such u64 values in a u32 variable `dsm` and uses it as a divisor. When the difference is exactly 2^32 the truncation yields zero, causing a divide-by-zero oops in the concave-curve intersection path: Oops: divide error: 0000 RIP: 0010:rtsc_min (net/sched/sch_hfsc.c:601) Call Trace: init_ed (net/sched/sch_hfsc.c:629) hfsc_enqueue (net/sched/sch_hfsc.c:1569) [...] Widen `dsm` to u64 and replace do_div() with div64_u64() so the full difference is preserved. Fixes: 1da177e ("Linux-2.6.12-rc2") Reported-by: Weiming Shi <[email protected]> Signed-off-by: Xiang Mei <[email protected]> Acked-by: Jamal Hadi Salim <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 1a6fdb3 commit 4576100

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

net/sched/sch_hfsc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ static void
555555
rtsc_min(struct runtime_sc *rtsc, struct internal_sc *isc, u64 x, u64 y)
556556
{
557557
u64 y1, y2, dx, dy;
558-
u32 dsm;
558+
u64 dsm;
559559

560560
if (isc->sm1 <= isc->sm2) {
561561
/* service curve is convex */
@@ -598,7 +598,7 @@ rtsc_min(struct runtime_sc *rtsc, struct internal_sc *isc, u64 x, u64 y)
598598
*/
599599
dx = (y1 - y) << SM_SHIFT;
600600
dsm = isc->sm1 - isc->sm2;
601-
do_div(dx, dsm);
601+
dx = div64_u64(dx, dsm);
602602
/*
603603
* check if (x, y1) belongs to the 1st segment of rtsc.
604604
* if so, add the offset.

0 commit comments

Comments
 (0)