linux-staging.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Jhih Ming Huang <fbihjmeric@gmail.com>
To: David Laight <David.Laight@aculab.com>
Cc: "gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	 "fabioaiuto83@gmail.com" <fabioaiuto83@gmail.com>,
	 "ross.schm.dev@gmail.com" <ross.schm.dev@gmail.com>,
	"maqianga@uniontech.com" <maqianga@uniontech.com>,
	 "marcocesati@gmail.com" <marcocesati@gmail.com>,
	 "linux-staging@lists.linux.dev" <linux-staging@lists.linux.dev>,
	 "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] rtw_security: fix cast to restricted __le32
Date: Sat, 19 Jun 2021 02:36:49 +0800	[thread overview]
Message-ID: <CAKgboZ_G+46OL3_foSnJ8ZQ_MOR2nNK_rfuqcXc_AjQN63Qk+A@mail.gmail.com> (raw)
In-Reply-To: <8974a58823d74d118595d4f8db5ac870@AcuMS.aculab.com>

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

      reply	other threads:[~2021-06-18 18:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAKgboZ_G+46OL3_foSnJ8ZQ_MOR2nNK_rfuqcXc_AjQN63Qk+A@mail.gmail.com \
    --to=fbihjmeric@gmail.com \
    --cc=David.Laight@aculab.com \
    --cc=fabioaiuto83@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=maqianga@uniontech.com \
    --cc=marcocesati@gmail.com \
    --cc=ross.schm.dev@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).