From: weichenchen Date: Fri, 25 Dec 2020 05:44:45 +0000 (+0800) Subject: net: neighbor: fix a crash caused by mod zero X-Git-Tag: v5.11-rc3~39^2~19 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a533b70a657c03137dd49cbcfee70aac086ab2b1;p=thirdparty%2Fkernel%2Flinux.git net: neighbor: fix a crash caused by mod zero pneigh_enqueue() tries to obtain a random delay by mod NEIGH_VAR(p, PROXY_DELAY). However, NEIGH_VAR(p, PROXY_DELAY) migth be zero at that point because someone could write zero to /proc/sys/net/ipv4/neigh/[device]/proxy_delay after the callers check it. This patch uses prandom_u32_max() to get a random delay instead which avoids potential division by zero. Signed-off-by: weichenchen Signed-off-by: David S. Miller --- diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 9500d28a43b0e..277ed854aef1c 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -1569,10 +1569,8 @@ static void neigh_proxy_process(struct timer_list *t) void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p, struct sk_buff *skb) { - unsigned long now = jiffies; - - unsigned long sched_next = now + (prandom_u32() % - NEIGH_VAR(p, PROXY_DELAY)); + unsigned long sched_next = jiffies + + prandom_u32_max(NEIGH_VAR(p, PROXY_DELAY)); if (tbl->proxy_queue.qlen > NEIGH_VAR(p, PROXY_QLEN)) { kfree_skb(skb);