All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sch_cake: avoid possible divide by zero in cake_enqueue()
@ 2020-01-02  9:21 Wen Yang
  2020-01-02 21:58 ` [Cake] " Jonathan Morton
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Wen Yang @ 2020-01-02  9:21 UTC (permalink / raw)
  To: Toke Høiland-Jørgensen
  Cc: Wen Yang, Kevin Darbyshire-Bryant,
	Toke Høiland-Jørgensen, David S . Miller, Cong Wang,
	cake, netdev, linux-kernel

The variables 'window_interval' is u64 and do_div()
truncates it to 32 bits, which means it can test
non-zero and be truncated to zero for division.
The unit of window_interval is nanoseconds,
so its lower 32-bit is relatively easy to exceed.
Fix this issue by using div64_u64() instead.

Fixes: 7298de9cd725 ("sch_cake: Add ingress mode")
Signed-off-by: Wen Yang <wenyang@linux.alibaba.com>
Cc: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
Cc: Toke Høiland-Jørgensen <toke@redhat.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Cong Wang <xiyou.wangcong@gmail.com>
Cc: cake@lists.bufferbloat.net
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 net/sched/sch_cake.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c
index 6cc3ab1..90ef7cc 100644
--- a/net/sched/sch_cake.c
+++ b/net/sched/sch_cake.c
@@ -1768,7 +1768,7 @@ static s32 cake_enqueue(struct sk_buff *skb, struct Qdisc *sch,
 						      q->avg_window_begin));
 			u64 b = q->avg_window_bytes * (u64)NSEC_PER_SEC;
 
-			do_div(b, window_interval);
+			b = div64_u64(b, window_interval);
 			q->avg_peak_bandwidth =
 				cake_ewma(q->avg_peak_bandwidth, b,
 					  b > q->avg_peak_bandwidth ? 2 : 8);
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Cake] [PATCH] sch_cake: avoid possible divide by zero in cake_enqueue()
  2020-01-02  9:21 [PATCH] sch_cake: avoid possible divide by zero in cake_enqueue() Wen Yang
@ 2020-01-02 21:58 ` Jonathan Morton
  2020-01-02 23:34 ` Toke Høiland-Jørgensen
  2020-01-03  0:35 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Jonathan Morton @ 2020-01-02 21:58 UTC (permalink / raw)
  To: Wen Yang
  Cc: Toke Høiland-Jørgensen, netdev, linux-kernel, cake,
	Kevin Darbyshire-Bryant, Cong Wang, David S . Miller

> On 2 Jan, 2020, at 11:21 am, Wen Yang <wenyang@linux.alibaba.com> wrote:
> 
> The variables 'window_interval' is u64 and do_div()
> truncates it to 32 bits, which means it can test
> non-zero and be truncated to zero for division.
> The unit of window_interval is nanoseconds,
> so its lower 32-bit is relatively easy to exceed.
> Fix this issue by using div64_u64() instead.

That might actually explain a few things.  I approve.

Honestly the *correct* fix is for the compiler to implement division in a way that doesn't require substituting it with function calls.  As this shows, it's error-prone to do this manually.

 - Jonathan Morton

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] sch_cake: avoid possible divide by zero in cake_enqueue()
  2020-01-02  9:21 [PATCH] sch_cake: avoid possible divide by zero in cake_enqueue() Wen Yang
  2020-01-02 21:58 ` [Cake] " Jonathan Morton
@ 2020-01-02 23:34 ` Toke Høiland-Jørgensen
  2020-01-03  0:35 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Toke Høiland-Jørgensen @ 2020-01-02 23:34 UTC (permalink / raw)
  To: Wen Yang
  Cc: Wen Yang, Kevin Darbyshire-Bryant, David S . Miller, Cong Wang,
	cake, netdev, linux-kernel

Wen Yang <wenyang@linux.alibaba.com> writes:

> The variables 'window_interval' is u64 and do_div()
> truncates it to 32 bits, which means it can test
> non-zero and be truncated to zero for division.
> The unit of window_interval is nanoseconds,
> so its lower 32-bit is relatively easy to exceed.
> Fix this issue by using div64_u64() instead.
>
> Fixes: 7298de9cd725 ("sch_cake: Add ingress mode")
> Signed-off-by: Wen Yang <wenyang@linux.alibaba.com>
> Cc: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
> Cc: Toke Høiland-Jørgensen <toke@redhat.com>
> Cc: David S. Miller <davem@davemloft.net>
> Cc: Cong Wang <xiyou.wangcong@gmail.com>
> Cc: cake@lists.bufferbloat.net
> Cc: netdev@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org

Acked-by: Toke Høiland-Jørgensen <toke@toke.dk>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] sch_cake: avoid possible divide by zero in cake_enqueue()
  2020-01-02  9:21 [PATCH] sch_cake: avoid possible divide by zero in cake_enqueue() Wen Yang
  2020-01-02 21:58 ` [Cake] " Jonathan Morton
  2020-01-02 23:34 ` Toke Høiland-Jørgensen
@ 2020-01-03  0:35 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2020-01-03  0:35 UTC (permalink / raw)
  To: wenyang; +Cc: toke, ldir, toke, xiyou.wangcong, cake, netdev, linux-kernel

From: Wen Yang <wenyang@linux.alibaba.com>
Date: Thu,  2 Jan 2020 17:21:43 +0800

> The variables 'window_interval' is u64 and do_div()
> truncates it to 32 bits, which means it can test
> non-zero and be truncated to zero for division.
> The unit of window_interval is nanoseconds,
> so its lower 32-bit is relatively easy to exceed.
> Fix this issue by using div64_u64() instead.
> 
> Fixes: 7298de9cd725 ("sch_cake: Add ingress mode")
> Signed-off-by: Wen Yang <wenyang@linux.alibaba.com>

Applied and queued up for -stable.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-01-03  0:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-02  9:21 [PATCH] sch_cake: avoid possible divide by zero in cake_enqueue() Wen Yang
2020-01-02 21:58 ` [Cake] " Jonathan Morton
2020-01-02 23:34 ` Toke Høiland-Jørgensen
2020-01-03  0:35 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.