linux-staging.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtw_security: fix cast to restricted __le32
@ 2021-06-13 10:22 Jhih-Ming Huang
  2021-06-13 10:26 ` Greg KH
  2021-06-14 20:48 ` David Laight
  0 siblings, 2 replies; 4+ messages in thread
From: Jhih-Ming Huang @ 2021-06-13 10:22 UTC (permalink / raw)
  To: gregkh, fabioaiuto83, ross.schm.dev, maqianga, marcocesati,
	linux-staging, linux-kernel
  Cc: Jhih-Ming Huang

This patch fixes the sparse warning of fix cast to restricted __le32.

Signed-off-by: Jhih-Ming Huang <fbihjmeric@gmail.com>
---
 drivers/staging/rtl8723bs/core/rtw_security.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_security.c b/drivers/staging/rtl8723bs/core/rtw_security.c
index a99f439328f1..2f4da67e31c6 100644
--- a/drivers/staging/rtl8723bs/core/rtw_security.c
+++ b/drivers/staging/rtl8723bs/core/rtw_security.c
@@ -121,7 +121,7 @@ void rtw_wep_decrypt(struct adapter  *padapter, u8 *precvframe)
 		arc4_crypt(ctx, payload, payload,  length);
 
 		/* calculate icv and compare the icv */
-		*((u32 *)crc) = le32_to_cpu(~crc32_le(~0, payload, length - 4));
+		*((u32 *)crc) = le32_to_cpu((__force __le32)~crc32_le(~0, payload, length - 4));
 
 	}
 }
@@ -618,7 +618,8 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe)
 			arc4_setkey(ctx, rc4key, 16);
 			arc4_crypt(ctx, payload, payload, length);
 
-			*((u32 *)crc) = le32_to_cpu(~crc32_le(~0, payload, length - 4));
+			*((u32 *)crc) = le32_to_cpu((__force __le32)~crc32_le(~0, payload,
+						length - 4));
 
 			if (crc[3] != payload[length - 1] || crc[2] != payload[length - 2] ||
 			    crc[1] != payload[length - 3] || crc[0] != payload[length - 4])
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] rtw_security: fix cast to restricted __le32
  2021-06-13 10:22 [PATCH] rtw_security: fix cast to restricted __le32 Jhih-Ming Huang
@ 2021-06-13 10:26 ` Greg KH
  2021-06-14 20:48 ` David Laight
  1 sibling, 0 replies; 4+ messages in thread
From: Greg KH @ 2021-06-13 10:26 UTC (permalink / raw)
  To: Jhih-Ming Huang
  Cc: fabioaiuto83, ross.schm.dev, maqianga, marcocesati,
	linux-staging, linux-kernel

On Sun, Jun 13, 2021 at 06:22:29PM +0800, Jhih-Ming Huang wrote:
> This patch fixes the sparse warning of fix cast to restricted __le32.
> 
> Signed-off-by: Jhih-Ming Huang <fbihjmeric@gmail.com>
> ---
>  drivers/staging/rtl8723bs/core/rtw_security.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/rtl8723bs/core/rtw_security.c b/drivers/staging/rtl8723bs/core/rtw_security.c
> index a99f439328f1..2f4da67e31c6 100644
> --- a/drivers/staging/rtl8723bs/core/rtw_security.c
> +++ b/drivers/staging/rtl8723bs/core/rtw_security.c
> @@ -121,7 +121,7 @@ void rtw_wep_decrypt(struct adapter  *padapter, u8 *precvframe)
>  		arc4_crypt(ctx, payload, payload,  length);
>  
>  		/* calculate icv and compare the icv */
> -		*((u32 *)crc) = le32_to_cpu(~crc32_le(~0, payload, length - 4));
> +		*((u32 *)crc) = le32_to_cpu((__force __le32)~crc32_le(~0, payload, length - 4));

When you use __force, that usually implies something is wrong here.

Look at the recent changes that were just submitted for this a week or
so ago in the mailing list archives, and the discussion about them, to
see the issues involved here.

I would need to see a _LOT_ of description in the changelog about why
these changes are actually correct, before I can take them.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] rtw_security: fix cast to restricted __le32
  2021-06-13 10:22 [PATCH] rtw_security: fix cast to restricted __le32 Jhih-Ming Huang
  2021-06-13 10:26 ` Greg KH
@ 2021-06-14 20:48 ` David Laight
  2021-06-18 18:36   ` Jhih Ming Huang
  1 sibling, 1 reply; 4+ messages in thread
From: David Laight @ 2021-06-14 20:48 UTC (permalink / raw)
  To: 'Jhih-Ming Huang',
	gregkh, fabioaiuto83, ross.schm.dev, maqianga, marcocesati,
	linux-staging, linux-kernel

From: Jhih-Ming Huang
> Sent: 13 June 2021 11:22
> 
> This patch fixes the sparse warning of fix cast to restricted __le32.
> 
> Signed-off-by: Jhih-Ming Huang <fbihjmeric@gmail.com>
> ---
>  drivers/staging/rtl8723bs/core/rtw_security.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/rtl8723bs/core/rtw_security.c
> b/drivers/staging/rtl8723bs/core/rtw_security.c
> index a99f439328f1..2f4da67e31c6 100644
> --- a/drivers/staging/rtl8723bs/core/rtw_security.c
> +++ b/drivers/staging/rtl8723bs/core/rtw_security.c
> @@ -121,7 +121,7 @@ void rtw_wep_decrypt(struct adapter  *padapter, u8 *precvframe)
>  		arc4_crypt(ctx, payload, payload,  length);
> 
>  		/* calculate icv and compare the icv */
> -		*((u32 *)crc) = le32_to_cpu(~crc32_le(~0, payload, length - 4));
> +		*((u32 *)crc) = le32_to_cpu((__force __le32)~crc32_le(~0, payload, length - 4));
> 
>  	}
>  }
> @@ -618,7 +618,8 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe)
>  			arc4_setkey(ctx, rc4key, 16);
>  			arc4_crypt(ctx, payload, payload, length);

Is someone using 'rc4' and 'security' in the same file?

> 
> -			*((u32 *)crc) = le32_to_cpu(~crc32_le(~0, payload, length - 4));
> +			*((u32 *)crc) = le32_to_cpu((__force __le32)~crc32_le(~0, payload,
> +						length - 4));
> 
>  			if (crc[3] != payload[length - 1] || crc[2] != payload[length - 2] ||
>  			    crc[1] != payload[length - 3] || crc[0] != payload[length - 4])

In both cases the *((u32 *)crc) is also very dubious.
Casts of pointers to integer types are almost always broken.
Given the code that follows the second hunk I'm guessing you
have 'u8 crc[4];' (or equivalent).
That can be misaligned and then access will panic on some systems.

There is a get_unaligned_be32() (or something similar) that can be used
to read the crc from (payload + length - 4).

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] rtw_security: fix cast to restricted __le32
  2021-06-14 20:48 ` David Laight
@ 2021-06-18 18:36   ` Jhih Ming Huang
  0 siblings, 0 replies; 4+ messages in thread
From: Jhih Ming Huang @ 2021-06-18 18:36 UTC (permalink / raw)
  To: David Laight
  Cc: gregkh, fabioaiuto83, ross.schm.dev, maqianga, marcocesati,
	linux-staging, linux-kernel

On Tue, Jun 15, 2021 at 4:48 AM David Laight <David.Laight@aculab.com> wrote:
>
> From: Jhih-Ming Huang
> > Sent: 13 June 2021 11:22
> >
> > This patch fixes the sparse warning of fix cast to restricted __le32.
> >
> > Signed-off-by: Jhih-Ming Huang <fbihjmeric@gmail.com>
> > ---
> >  drivers/staging/rtl8723bs/core/rtw_security.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/staging/rtl8723bs/core/rtw_security.c
> > b/drivers/staging/rtl8723bs/core/rtw_security.c
> > index a99f439328f1..2f4da67e31c6 100644
> > --- a/drivers/staging/rtl8723bs/core/rtw_security.c
> > +++ b/drivers/staging/rtl8723bs/core/rtw_security.c
> > @@ -121,7 +121,7 @@ void rtw_wep_decrypt(struct adapter  *padapter, u8 *precvframe)
> >               arc4_crypt(ctx, payload, payload,  length);
> >
> >               /* calculate icv and compare the icv */
> > -             *((u32 *)crc) = le32_to_cpu(~crc32_le(~0, payload, length - 4));
> > +             *((u32 *)crc) = le32_to_cpu((__force __le32)~crc32_le(~0, payload, length - 4));
> >
> >       }
> >  }
> > @@ -618,7 +618,8 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe)
> >                       arc4_setkey(ctx, rc4key, 16);
> >                       arc4_crypt(ctx, payload, payload, length);
>
> Is someone using 'rc4' and 'security' in the same file?
Sorry, I don't get it. Could you explain it more? thanks.

>
> >
> > -                     *((u32 *)crc) = le32_to_cpu(~crc32_le(~0, payload, length - 4));
> > +                     *((u32 *)crc) = le32_to_cpu((__force __le32)~crc32_le(~0, payload,
> > +                                             length - 4));
> >
> >                       if (crc[3] != payload[length - 1] || crc[2] != payload[length - 2] ||
> >                           crc[1] != payload[length - 3] || crc[0] != payload[length - 4])
>
> In both cases the *((u32 *)crc) is also very dubious.
> Casts of pointers to integer types are almost always broken.
> Given the code that follows the second hunk I'm guessing you
> have 'u8 crc[4];' (or equivalent).
> That can be misaligned and then access will panic on some systems.
>
yes, I've sent the v3 PATCH and used Al Viro's suggestions.

> There is a get_unaligned_be32() (or something similar) that can be used
> to read the crc from (payload + length - 4).
I also used memcmp for checking.

thanks.

--jmhuang

>
>         David
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-06-18 18:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-13 10:22 [PATCH] rtw_security: fix cast to restricted __le32 Jhih-Ming Huang
2021-06-13 10:26 ` Greg KH
2021-06-14 20:48 ` David Laight
2021-06-18 18:36   ` Jhih Ming Huang

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