lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20201219102116.3cc0d74c@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com>
Date:   Sat, 19 Dec 2020 10:21:16 -0800
From:   Jakub Kicinski <kuba@...nel.org>
To:     weichenchen <weichen.chen@...ux.alibaba.com>
Cc:     davem@...emloft.net, liuhangbin@...il.com, dsahern@...nel.org,
        jdike@...mai.com, mrv@...atatu.com, lirongqing@...du.com,
        nikolay@...ulusnetworks.com, roopa@...ulusnetworks.com,
        netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
        splendidsky.cwc@...baba-inc.com, yanxu.zw@...baba-inc.com
Subject: Re: [PATCH] net: neighbor: fix a crash caused by mod zero

On Fri, 18 Dec 2020 12:20:19 +0800 weichenchen wrote:
> 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@...ux.alibaba.com>

Let's have the caller pass in the value since it did the checking?

> 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)

Not that this still doesn't guarantee that the compiler won't re-read
the value (however unlikely). We need a READ_ONCE().

> +		sched_next = now;
> +	else
> +		sched_next = now + (prandom_u32() % delay);
>  
>  	if (tbl->proxy_queue.qlen > NEIGH_VAR(p, PROXY_QLEN)) {
>  		kfree_skb(skb);

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ