[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20201228.145128.1498314185351532341.davem@davemloft.net>
Date: Mon, 28 Dec 2020 14:51:28 -0800 (PST)
From: David Miller <davem@...emloft.net>
To: weichen.chen@...ux.alibaba.com
Cc: eric.dumazet@...il.com, kuba@...nel.org,
splendidsky.cwc@...baba-inc.com, yanxu.zw@...baba-inc.com,
dsahern@...nel.org, liuhangbin@...il.com,
roopa@...ulusnetworks.com, jdike@...mai.com,
nikolay@...ulusnetworks.com, lirongqing@...du.com,
mrv@...atatu.com, netdev@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v4] net: neighbor: fix a crash caused by mod zero
From: weichenchen <weichen.chen@...ux.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@...ux.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.
Powered by blists - more mailing lists