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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240824175738.GO2164@kernel.org>
Date: Sat, 24 Aug 2024 18:57:38 +0100
From: Simon Horman <horms@...nel.org>
To: Li Zetao <lizetao1@...wei.com>
Cc: davem@...emloft.net, edumazet@...gle.com, kuba@...nel.org,
	pabeni@...hat.com, marcel@...tmann.org, johan.hedberg@...il.com,
	luiz.dentz@...il.com, idryomov@...il.com, xiubli@...hat.com,
	dsahern@...nel.org, trondmy@...nel.org, anna@...nel.org,
	chuck.lever@...cle.com, jlayton@...nel.org, neilb@...e.de,
	okorniev@...hat.com, Dai.Ngo@...cle.com, tom@...pey.com,
	jmaloy@...hat.com, ying.xue@...driver.com, linux@...blig.org,
	jacob.e.keller@...el.com, willemb@...gle.com, kuniyu@...zon.com,
	wuyun.abel@...edance.com, quic_abchauha@...cinc.com,
	gouhao@...ontech.com, netdev@...r.kernel.org,
	linux-bluetooth@...r.kernel.org, ceph-devel@...r.kernel.org,
	linux-nfs@...r.kernel.org, tipc-discussion@...ts.sourceforge.net
Subject: Re: [PATCH net-next 6/8] ipv6: mcast: use min() to simplify the code

On Thu, Aug 22, 2024 at 09:39:06PM +0800, Li Zetao wrote:
> When coping sockaddr in ip6_mc_msfget(), the time of copies
> depends on the minimum value between sl_count and gf_numsrc.
> Using min() here is very semantic.
> 
> Signed-off-by: Li Zetao <lizetao1@...wei.com>
> ---
>  net/ipv6/mcast.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c
> index 7ba01d8cfbae..b244dbf61d5f 100644
> --- a/net/ipv6/mcast.c
> +++ b/net/ipv6/mcast.c
> @@ -586,7 +586,8 @@ int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf,
>  	const struct in6_addr *group;
>  	struct ipv6_mc_socklist *pmc;
>  	struct ip6_sf_socklist *psl;
> -	int i, count, copycount;
> +	unsigned int count;
> +	int i, copycount;
>  
>  	group = &((struct sockaddr_in6 *)&gsf->gf_group)->sin6_addr;
>  
> @@ -610,7 +611,7 @@ int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf,
>  	psl = sock_dereference(pmc->sflist, sk);
>  	count = psl ? psl->sl_count : 0;

Both count and psl->sl_count are unsigned int,
so this looks safe (and more correct than what it replaces, IMHO).

>  
> -	copycount = count < gsf->gf_numsrc ? count : gsf->gf_numsrc;
> +	copycount = min(count, gsf->gf_numsrc);

And gsf->gf_numsrc is a __u32, so min operating on it and
count looks safe to me.

Further, the code it replaces seems to be a max() operation in
both intent and function.

Reviewed-by: Simon Horman <horms@...nel.org>

>  	gsf->gf_numsrc = count;
>  	for (i = 0; i < copycount; i++) {
>  		struct sockaddr_in6 *psin6;
> -- 
> 2.34.1
> 
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ