Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2919949pxj; Mon, 14 Jun 2021 10:05:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyAcUm0Gc/yAjpt7d4qs/jIoVIX1ulmLq/Sg2ZRqIn0sLP+R93gtGuM92qeGbtcHuIcn5u X-Received: by 2002:aa7:c354:: with SMTP id j20mr18065859edr.294.1623690341510; Mon, 14 Jun 2021 10:05:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623690341; cv=none; d=google.com; s=arc-20160816; b=TY/zkl4Ex7KQWd7QDPrqIHOXWW15I4sjVcLcVVmHiRKuwmHJQFFuW8y7IFT2YRwF8t 4w3fBRrXKjaHSLtXrk42s9PIriTdwynDXmEwlbRJEm34FApnxpIZ7vZvFjvosuriVwN2 lMsUGQFA/5rZ+6hs2l4DTg7gI5Cb2WdMUzmDtlpye0o41hLWPJRgn528Xmmxh4Wwv9ou 5N24wjlWLKNDYTOa1nhn3uLkGiveLbcIqgxiFv0tbvME6dejZ1SDxeAAB1/asfu9+zCG z264kTLvB9Ag7hvagsDGfgcxyAOeSsnlyF0JztZfXM45kvc83pijrNu3CdkqdDp52ZTN +jAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=RZlKOxjbq+UNMH8oB72Jscc4FHiJGnbZDpU7uWLFNBw=; b=w4m6MzoqBagPo9dB9qV0optrACRq71h2tPPTxcOYFkZUDhf1OaWv6UOgk9ru6rYytz b0BfUXwbH1nnJtogwz/E4rXd+PQMl2BgHLvrnjrnfDJwMZCLEpQYnzwWKJ7qPsvEn7+w gFPNO2b+Ggz2h9JXg364Wn/tL3t6uEf6jstf5/c+ZZdMQDZpTj8aVvp1ieVI2UKoedqp IQqnWtqm9G3YTZP/SGKq9TtUzZ/H9TaC00rhoFOiLwo4PQVUvqakXL/3J5+QqsUG+elU stGvhsh4yIxKLdQPafRiSERRa9j1jRfSPZ+Migxd1mhdvZrSJ13GtJfEHpM4gNPoLKV4 6A4Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u15si12024074edo.426.2021.06.14.10.05.18; Mon, 14 Jun 2021 10:05:41 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235265AbhFNRFx (ORCPT + 99 others); Mon, 14 Jun 2021 13:05:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235074AbhFNRFw (ORCPT ); Mon, 14 Jun 2021 13:05:52 -0400 Received: from zeniv-ca.linux.org.uk (zeniv-ca.linux.org.uk [IPv6:2607:5300:60:148a::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E39F3C061574 for ; Mon, 14 Jun 2021 10:03:49 -0700 (PDT) Received: from viro by zeniv-ca.linux.org.uk with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1lspzw-0089t0-Fc; Mon, 14 Jun 2021 17:03:40 +0000 Date: Mon, 14 Jun 2021 17:03:40 +0000 From: Al Viro To: Jhih Ming Huang Cc: Greg KH , 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 v2] rtw_security: fix cast to restricted __le32 Message-ID: References: <20210613122858.1433252-1-fbihjmeric@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 14, 2021 at 11:27:03PM +0800, Jhih Ming Huang wrote: > Thanks for your explanation. > > To clarify, even though it might be false positives in some senses, > following "hold the variable native-endian and check the conversion > done correctly" > is much easier than the other way. And it's exactly the current implementation. > > So it's better to keep the current implementation and ignore the > warnings, right? Umm... If that's the case, the warnings should go away if you use cpu_to_le32() for conversions from native to l-e and le32_to_cpu() for conversions from l-e to native. IOW, the choice between those should annotate what's going on. In your case doing *((u32 *)crc) = le32_to_cpu((__force __le32)~crc32_le(~0, payload, length - 4)); is wrong - you have crc32_le(...) native-endian ~crc32_le(...) - ditto le32_to_cpu(~crc32_le(...)) - byteswapped native-endian on b-e, unchanged on l-e. So result will be little-endian representation of ~crc32(...) in all cases. IOW, it's cpu_to_le32(~crc32_le(...)), misannotated as native-endian instead of little-endian it actually is. Then you store that value (actually __le32) into *(u32 *)crc. Seeing that crc is u8[4] there, that *(u32 *) is misleading - you are actually storing __le32 there (and, AFAICS, doing noting with the result). The same story in rtw_tkip_decrypt(), only there you do use the result later. So just make it __le32 crc and crc = cpu_to_le32(~crc32_le(~0, payload, length - 4)); with if (crc[3] != payload[length - 1] || crc[2] != payload[length - 2] || crc[1] != payload[length - 3] || crc[0] != payload[length - 4]) turned into if (memcmp(&crc, payload + length - 4, 4) != 0) (or (crc != get_unaligned((__le32 *)(payload + length - 4))), for that matter, to document what's going on and let the damn thing pick the optimal implementation for given architecture). Incidentally, your secmicgetuint32() is simply get_unaligned_le32() and secmicputuint32() - put_unaligned_le32(). No need to reinvent that wheel...