Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2108539pxj; Sat, 19 Jun 2021 03:12:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlMERe0mfg3mzcQ8WJslHdS6zAa3US7l3Qn8US++QG7yQKZ5fJ4adgZ2ALf4o3lsS9cxVp X-Received: by 2002:a05:6e02:1e06:: with SMTP id g6mr10439168ila.192.1624097532036; Sat, 19 Jun 2021 03:12:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624097532; cv=none; d=google.com; s=arc-20160816; b=YXPkkdviuI+CY7UHgdZOemZFWrV79DZqpfJ7QENSGOVIlD9HTfLnG6wis0SBHRzGu4 K8fgJg8XwVIcc8YX2cbI7uCcp/eD+RI0zT1Hhe+LX8Url9ceEHN76RNtjpckDRCxSj9W x42qFrOYwZazJuJg1MiZjcPEy3UpxNw8S/CoKsd0MWYYvsK/KrRsll01bEF+Y+xCE/SI glf+obQtkBBwtsB4dZmZNbuVPxseb3Eo6sbLbXVkZqTYKZvi5MNoQjRrIFkBA4lXP9dM zHlOIe+ox09d3abbY3Wgh7raQvX0VGqfa9E0Qn+4dXA2023IUBiiCsZx3TRp7kjExVfe 6C0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=h6U+ip6SC6pAZmxuTxatgMsO1k4mn3H80WDAN7mFMJs=; b=Q+jOlGC+OeT/84JbihEp0znwPip6gaWqL9CJ4F42O2uC+/EOi5WQXAO7fmBM8+GxmR R0Bqz6M9d/97WD/xsn17SALcMpBOZuFeWzcTOHVgP4XrnU4v+MyDTYW49EMc8pl/K8G7 fTNkQfoVoSsNev2gSX5p2IOlGQaZxKVpzjJbjjO1LayD12BkBRz1C4WokDs8eqM3zInW lbqCsRCB3J/OivmpA3zGIbgU8Hxj1hfz9MfBjk8iDCqfY9tro3g32pDOrsA7D9VF5hNl Bpr7GH0u4lXLW04IeTvaIb/BPLEX+AAaJlIAtMPCJuwGodbqwBnv1qk8kn3PpP3yhPU5 mjRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=crcjxWRS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m2si6583100ilu.120.2021.06.19.03.12.00; Sat, 19 Jun 2021 03:12:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=crcjxWRS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232433AbhFSJWk (ORCPT + 99 others); Sat, 19 Jun 2021 05:22:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230318AbhFSJWk (ORCPT ); Sat, 19 Jun 2021 05:22:40 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED693C061574 for ; Sat, 19 Jun 2021 02:20:28 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id u18so4289823pfk.11 for ; Sat, 19 Jun 2021 02:20:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=h6U+ip6SC6pAZmxuTxatgMsO1k4mn3H80WDAN7mFMJs=; b=crcjxWRSpdvPpetfG0nkbWH+v91CS1lUwNKLPPEwAdAGd2dtrYT95d5SQ513CnPgHp Rvo21FuClNdZjUQPLdmqm0iGyh7SSfXnsKx7hSxOwu0vfrDXOuci2eQZGHhGDakR/az9 8WdSod8wdu6MhVFqojuhkgOqIIwpCiINkOsGf8RNQwETMkpXA7Cp3AoZEYr5ZF0UQGC9 ZIBLY3xQKqWw3FRLT/lNgTLxXhHxA0iEzh6dt4Yq8CSSuNqv+x9Dmzl3qOl8fG2xnCZ6 0uCp56ttlWvUTE3xMQSZ0i5zFdnTnZiL+X/BKxBQfODrky79HHm74WDwU2EN/7GrfABK ZncQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=h6U+ip6SC6pAZmxuTxatgMsO1k4mn3H80WDAN7mFMJs=; b=Q+CSK2BuDEd3bgtF3VBF6HJIBPrnDYurpfMuXTzPkPjNhSgTI/07S6sJ6zWc3PQ3pn ok4BvmrYFdsJ9KMx6sgMN4o4TAVUBxqWQUXTbmxRKjRhnYu5eVTZ0RuQEN1nED4IjrIB Wv1QSb1EqxLeL369xJ1aE+8Armxfz03hl/02EDqYdzNcuBClbfEm9qpfL3NINNg68C8W 81ptBtKqAsm/QXBZC7t0T8/aLmojXSTXJi3h53JynYei3zY32gvHkqVuUn9EI2sjxa2J d0mIoguCWaJ02UZauDNcXF3T8/cZpyzfh+SXc3XhQsyzBj8KY64rTvYTv3/t1MWnhl+N Cg6A== X-Gm-Message-State: AOAM533tcUsSikM5VsXrkPTFYqFoni/ftgX0xVwtQKjnSMTOEIq82Fa/ xY05zMzBAjxhOqJS6NAo4tK5cBW73rUBUr+A X-Received: by 2002:a63:5005:: with SMTP id e5mr14257769pgb.340.1624094428284; Sat, 19 Jun 2021 02:20:28 -0700 (PDT) Received: from gmail.com (1-171-85-235.dynamic-ip.hinet.net. [1.171.85.235]) by smtp.gmail.com with ESMTPSA id 35sm9564939pjo.16.2021.06.19.02.20.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Jun 2021 02:20:27 -0700 (PDT) Date: Sat, 19 Jun 2021 17:20:24 +0800 From: Jhih-Ming Huang To: Al Viro Cc: 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 Subject: Re: [PATCH v3] rtw_security: fix cast to restricted __le32 Message-ID: <20210619092024.i6aunzyd24cmr5cs@gmail.com> References: <20210618181751.95967-1-fbihjmeric@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 18, 2021 at 07:29:16PM +0000, Al Viro wrote: > On Sat, Jun 19, 2021 at 02:17:51AM +0800, Jhih-Ming Huang wrote: > > 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 cpu_to_le32. > > > > Ths commit also fixes the payload checking by memcmp instead of checking element > > by element. > > > > Signed-off-by: Jhih-Ming Huang > > --- > > drivers/staging/rtl8723bs/core/rtw_security.c | 7 +++---- > > 1 file changed, 3 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/staging/rtl8723bs/core/rtw_security.c b/drivers/staging/rtl8723bs/core/rtw_security.c > > index a99f439328f1..97a7485f8f58 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)); > > + *crc = cpu_to_le32(~crc32_le(~0, payload, length - 4)); > > Huh? crc is u8[4]; that assignment will truncate that le32 to u8 and store it in > the first byte of your 4-element array. How the hell does sparse *not* complain > on that? facepalm... fixed in v4 PATCH. thanks for your help. > > Either make crc __le32 (and turn assignment into crc = cpu_to_le32(...)), or > make that *(__le32 *)crc = ... > > > @@ -618,10 +618,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)); > > Ditto. Declare crc as __le32 and use > crc = cpu_to_le32(~crc32_le(~0, payload, length - 4)); > here.