netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: weichen.chen@linux.alibaba.com
Cc: eric.dumazet@gmail.com, kuba@kernel.org,
	splendidsky.cwc@alibaba-inc.com, yanxu.zw@alibaba-inc.com,
	dsahern@kernel.org, liuhangbin@gmail.com,
	roopa@cumulusnetworks.com, jdike@akamai.com,
	nikolay@cumulusnetworks.com, lirongqing@baidu.com,
	mrv@mojatatu.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4] net: neighbor: fix a crash caused by mod zero
Date: Mon, 28 Dec 2020 14:51:28 -0800 (PST)	[thread overview]
Message-ID: <20201228.145128.1498314185351532341.davem@davemloft.net> (raw)
In-Reply-To: <20201225054448.73256-1-weichen.chen@linux.alibaba.com>

From: weichenchen <weichen.chen@linux.alibaba.com>
Date: Fri, 25 Dec 2020 13:44:45 +0800

> 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 <weichen.chen@linux.alibaba.com>
> ---
> V4:
>     - Use prandom_u32_max() to get a random delay in
>       pneigh_enqueue().
> V3:
>     - Callers need to pass the delay time to pneigh_enqueue()
>       now and they should guarantee it is not zero.
>     - Use READ_ONCE() to read NEIGH_VAR(p, PROXY_DELAY) in both
>       of the existing callers of pneigh_enqueue() and then pass
>       it to pneigh_enqueue().
> V2:
>     - Use READ_ONCE() to prevent the complier from re-reading
>       NEIGH_VAR(p, PROXY_DELAY).
>     - Give a hint to the complier that delay <= 0 is unlikely
>       to happen.
> 
> V4 is quite concise and works well.
> Thanks for Eric's and Jakub's advice.

Applied and queued up for -stable, thanks.

      reply	other threads:[~2020-12-28 23:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201228.145128.1498314185351532341.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=eric.dumazet@gmail.com \
    --cc=jdike@akamai.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lirongqing@baidu.com \
    --cc=liuhangbin@gmail.com \
    --cc=mrv@mojatatu.com \
    --cc=netdev@vger.kernel.org \
    --cc=nikolay@cumulusnetworks.com \
    --cc=roopa@cumulusnetworks.com \
    --cc=splendidsky.cwc@alibaba-inc.com \
    --cc=weichen.chen@linux.alibaba.com \
    --cc=yanxu.zw@alibaba-inc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).