netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: neighbor: fix a crash caused by mod zero
@ 2020-12-18  4:20 weichenchen
  2020-12-19 18:21 ` Jakub Kicinski
  0 siblings, 1 reply; 8+ messages in thread
From: weichenchen @ 2020-12-18  4:20 UTC (permalink / raw)
  To: davem, kuba
  Cc: liuhangbin, dsahern, jdike, mrv, lirongqing, nikolay, roopa,
	netdev, linux-kernel, splendidsky.cwc, yanxu.zw, weichenchen

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 double-checks NEIGH_VAR(p, PROXY_DELAY) in
pneigh_enqueue() to ensure not to take zero as modulus.

Signed-off-by: weichenchen <weichen.chen@linux.alibaba.com>
---
 net/core/neighbour.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 9500d28a43b0..eb5d015c53d3 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -1570,9 +1570,14 @@ void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p,
 		    struct sk_buff *skb)
 {
 	unsigned long now = jiffies;
+	unsigned long sched_next;
 
-	unsigned long sched_next = now + (prandom_u32() %
-					  NEIGH_VAR(p, PROXY_DELAY));
+	int delay = NEIGH_VAR(p, PROXY_DELAY);
+
+	if (delay <= 0)
+		sched_next = now;
+	else
+		sched_next = now + (prandom_u32() % delay);
 
 	if (tbl->proxy_queue.qlen > NEIGH_VAR(p, PROXY_QLEN)) {
 		kfree_skb(skb);
-- 
2.20.1 (Apple Git-117)


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

end of thread, other threads:[~2020-12-28 23:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-18  4:20 [PATCH] net: neighbor: fix a crash caused by mod zero weichenchen
2020-12-19 18:21 ` Jakub Kicinski
2020-12-21 13:07   ` [PATCH v2] " weichenchen
2020-12-21 19:32     ` Jakub Kicinski
2020-12-22 12:38       ` [PATCH v3] " weichenchen
2020-12-22 16:34         ` Eric Dumazet
2020-12-25  5:44           ` [PATCH v4] " weichenchen
2020-12-28 22:51             ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).