Subject: Re: [PATCH net-next 3/5] net/mlx5e: Compare all fields in IPv6 address

From: Leon Romanovsky <[email-masked]>
Date: Thu, 20 Apr 2023 20:13:19 +0300

On Thu, Apr 20, 2023 at 04:35:53PM +0200, Simon Horman wrote:
> On Thu, Apr 20, 2023 at 02:05:01PM +0200, Simon Horman wrote:
> > On Thu, Apr 20, 2023 at 02:52:43PM +0300, Leon Romanovsky wrote:
> > > On Thu, Apr 20, 2023 at 01:09:23PM +0200, Simon Horman wrote:
> > > > On Thu, Apr 20, 2023 at 11:02:49AM +0300, Leon Romanovsky wrote:
> > > > > From: Leon Romanovsky <[email-masked]>
> > > > > 
> > > > > Fix size argument in memcmp to compare whole IPv6 address.
> > > > > 
> > > > > Fixes: b3beba1fb404 ("net/mlx5e: Allow policies with reqid 0, to support IKE policy holes")
> > > > > Reviewed-by: Raed Salem <[email-masked]>
> > > > > Reviewed-by: Emeel Hakim <[email-masked]>
> > > > > Signed-off-by: Leon Romanovsky <[email-masked]>
> > > > > ---
> > > > >  drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h | 2 +-
> > > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > > > 
> > > > > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h
> > > > > index f7f7c09d2b32..4e9887171508 100644
> > > > > --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h
> > > > > +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h
> > > > > @@ -287,7 +287,7 @@ static inline bool addr6_all_zero(__be32 *addr6)
> > > > >  {
> > > > >  	static const __be32 zaddr6[4] = {};
> > > > >  
> > > > > -	return !memcmp(addr6, zaddr6, sizeof(*zaddr6));
> > > > > +	return !memcmp(addr6, zaddr6, sizeof(zaddr6));
> > > > 
> > > > 1. Perhaps array_size() is appropriate here?
> > > 
> > > It is overkill here, sizeof(zaddr6) is constant and can't overflow.
> > 
> > Maybe, but the original code had a bug because using sizeof()
> > directly is error prone.
> 
> Sorry, just to clarify.
> I now realise that ARRAY_SIZE() is what I meant to suggest earlier.

ARRAY_SIZE(zaddr6) will give us 4, so we will need to multiple in
sizeof(__be32) to get the right result (16 bytes).

sizeof(zaddr6) == ARRAY_SIZE(zaddr6) * sizeof(__be32)

Thanks