Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2790912pxj; Mon, 14 Jun 2021 07:16:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyIGU2J6SgDHsJMovasz8qwuqMhEGCl8RQMkOjbBWPXJsO9AiGDvmebM2eCku+1Vvlhaeuz X-Received: by 2002:aa7:d0cc:: with SMTP id u12mr17212991edo.48.1623680181953; Mon, 14 Jun 2021 07:16:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623680181; cv=none; d=google.com; s=arc-20160816; b=EyA3cj1Zf06c+sj6wlK0CTgIKUAmHsBIZFotEjqJnloD0K6Jm6AY00yfaVSvonoJXt rUlkD+OmHAqbTZByS+KGfUyvpKSWkR6rfGs2yQzhdw1WwLekKgGG+CL+b8uOsgmEtnq8 zrTa4OOPulQXmcnsGrbvHPyA1e2m3lf3KiI1BJwgxG62CwvgN/po0miJyTBNbEpARR6U KNDRMjT1B1Ip3cgOTJyLtgwcVEmBSWssmZiYUi1aPF1vBTGrL4E/aftAZZEY4yV1oh3B 5Yf9tjJqJWSpdOMMr5KLcVBgLulpxljDEcYpZTKYJTB5XxMkxcir4jmLAV8If0YXMl9D hvJA== 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=H5guff1zVYu97rKIARPMXeYDkdQ690biMCztySZG4VE=; b=umyZQxYP7Zu2SD5/WXaPXHIJyj7uxmnNhDvxjvKBhnfFd670HFehiE/0xPTSMlRYse 6txN5N7sS67VjGvEvhUTYGMLwH2FXyjEK5WFI7RiT3a2Q8Da56urd4aTR9oDKI+YvVkX 7/sFTX5qeFtu7c2vfjYlUhLmLeTGH1Obf6qAxVQtfUGR9LYKmyaX/vlEbeEnDbMGpNiZ rGRDOPhsaw2J2z20oUnIVBPg9khedzoGteQRG6sX78546ylkyCNavlPSVD/QEFpe2sC5 ldWPaV6Lk3k1LlJxOw/ABeykhszwmwgfVk+xOisSOTmYQmFIZhrEcJ6R35Gu1QAdDsbE Vs8A== 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 w15si11729741edj.25.2021.06.14.07.15.59; Mon, 14 Jun 2021 07:16:21 -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 S233952AbhFNOQt (ORCPT + 99 others); Mon, 14 Jun 2021 10:16:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233780AbhFNOQq (ORCPT ); Mon, 14 Jun 2021 10:16:46 -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 9FFD5C061574 for ; Mon, 14 Jun 2021 07:14:43 -0700 (PDT) Received: from viro by zeniv-ca.linux.org.uk with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1lsnLz-0086xp-Gz; Mon, 14 Jun 2021 14:14:15 +0000 Date: Mon, 14 Jun 2021 14:14:15 +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 12:40:27AM +0800, Jhih Ming Huang wrote: > On Sun, Jun 13, 2021 at 8:34 PM Greg KH wrote: > > > > On Sun, Jun 13, 2021 at 08:28:58PM +0800, Jhih-Ming Huang wrote: > > > This patch fixes the sparse warning of fix cast to restricted __le32. > > > > > > Last month, there was a change for replacing private CRC-32 routines with > > > in-kernel ones. > > > In that patch, we replaced getcrc32 with crc32_le in calling le32_to_cpu. > > > le32_to_cpu accepts __le32 type as arg, but crc32_le returns unsigned int. > > > That how it introduced the sparse warning. > > > > As crc32_le returns a u32 which is in native-endian format, how can you > > cast it to le32? Why do you cast it to le32? Isn't that going to be > > incorrect for big endian systems? > > > > thanks, > > > > greg k-h > > Thanks for the fast reply. > Yes, you are right. I did not notice that le32_to_cpu already handles > both of the cases. > > So it seems the warning from sparse is false positives, am I right? In a sense that on all architectures we would be ever likely to support le32_to_cpu and cpu_to_le32 do the same bit-shuffling - yes. In a sense of having those used correctly it's not a false positive, though - it's much easier to follow "this variable always hold native-endian, this - little-endian" and watch for conversions done correctly than to count the byteswaps and try to prove that it's either even for all execution histories or odd for all execution histories. IOW, there's a good reason for keeping separate cpu_to_le32 and le32_to_cpu and not mixing them with each other - it's easier to prove correctness that way *and* easier to look for endianness bugs.