linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jhih-Ming Huang <fbihjmeric@gmail.com>
To: gregkh@linuxfoundation.org, fabioaiuto83@gmail.com,
	ross.schm.dev@gmail.com, maqianga@uniontech.com,
	marcocesati@gmail.com, linux-staging@lists.linux.dev,
	linux-kernel@vger.kernel.org
Cc: Jhih-Ming Huang <fbihjmeric@gmail.com>,
	kernel test robot <lkp@intel.com>
Subject: [PATCH v7] rtw_security: fix cast to restricted __le32
Date: Sun,  1 Aug 2021 23:51:52 +0800	[thread overview]
Message-ID: <20210801155152.242089-1-fbihjmeric@gmail.com> (raw)
In-Reply-To: <YOIGbc2ymnWrThVK@kroah.com>

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

There was a change for replacing private CRC-32 routines with in kernel
ones.
However, the author used le32_to_cpu to convert crc32_le(), and we
should use cpu_to_le32.

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Jhih-Ming Huang <fbihjmeric@gmail.com>
---
 changes from v6:
   using get_unaligned_le32 to get the value and comparing it with crc,
   instead of using memcmp with raw pointers.

 drivers/staging/rtl8723bs/core/rtw_security.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_security.c b/drivers/staging/rtl8723bs/core/rtw_security.c
index a99f439328f1..ff79e1aacd1a 100644
--- a/drivers/staging/rtl8723bs/core/rtw_security.c
+++ b/drivers/staging/rtl8723bs/core/rtw_security.c
@@ -92,7 +92,6 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
 void rtw_wep_decrypt(struct adapter  *padapter, u8 *precvframe)
 {
 	/*  exclude ICV */
-	u8 crc[4];
 	signed int	length;
 	u32 keylength;
 	u8 *pframe, *payload, *iv, wepkey[16];
@@ -119,10 +118,6 @@ void rtw_wep_decrypt(struct adapter  *padapter, u8 *precvframe)
 		/* decrypt payload include icv */
 		arc4_setkey(ctx, wepkey, 3 + keylength);
 		arc4_crypt(ctx, payload, payload,  length);
-
-		/* calculate icv and compare the icv */
-		*((u32 *)crc) = le32_to_cpu(~crc32_le(~0, payload, length - 4));
-
 	}
 }
 
@@ -537,7 +532,7 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe)
 	u32 pnh;
 	u8   rc4key[16];
 	u8   ttkey[16];
-	u8 crc[4];
+	__le32 crc;
 	signed int			length;
 
 	u8 *pframe, *payload, *iv, *prwskey;
@@ -618,10 +613,9 @@ 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));
+			crc = cpu_to_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])
+			if (crc != get_unaligned_le32(payload + length - 4))
 				res = _FAIL;
 		} else {
 			res = _FAIL;
-- 
2.32.0


  reply	other threads:[~2021-08-01 16:00 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-13 12:28 [PATCH v2] " Jhih-Ming Huang
2021-06-13 12:34 ` Greg KH
2021-06-13 16:40   ` Jhih Ming Huang
2021-06-14 14:14     ` Al Viro
2021-06-14 15:27       ` Jhih Ming Huang
2021-06-14 17:03         ` Al Viro
2021-06-18 18:17           ` [PATCH v3] " Jhih-Ming Huang
2021-06-18 19:29             ` Al Viro
2021-06-19  7:52               ` [PATCH v4] " Jhih-Ming Huang
2021-06-21  8:19                 ` [PATCH v5] " Jhih-Ming Huang
2021-06-21 15:48                   ` [PATCH v6] " Jhih-Ming Huang
2021-06-21 15:51                   ` [PATCH v5] " Jhih-Ming Huang
2021-06-22  9:31                   ` David Laight
2021-07-04 10:31                     ` [PATCH v7] " Jhih-Ming Huang
2021-07-04 19:05                       ` Greg KH
2021-08-01 15:51                         ` Jhih-Ming Huang [this message]
2021-08-05 11:17                           ` Greg KH
2021-06-19  9:20               ` [PATCH v3] " Jhih-Ming Huang
2021-06-18 18:28           ` [PATCH v2] " Jhih Ming Huang

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=20210801155152.242089-1-fbihjmeric@gmail.com \
    --to=fbihjmeric@gmail.com \
    --cc=fabioaiuto83@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=lkp@intel.com \
    --cc=maqianga@uniontech.com \
    --cc=marcocesati@gmail.com \
    --cc=ross.schm.dev@gmail.com \
    --subject='Re: [PATCH v7] rtw_security: fix cast to restricted __le32' \
    /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

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox