Skip to content

Commit

Permalink
net: neighbor: fix a crash caused by mod zero
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
weichenchen authored and davem330 committed Dec 28, 2020
1 parent 21fdca2 commit a533b70
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions net/core/neighbour.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a533b70

Please sign in to comment.