Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2483051rdb; Sun, 3 Dec 2023 20:13:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IEgA/6cfwXg2FfSoofdxjB7if7u3GyiGvpS79OWlWlsVKDD4sDhIJxhYd6y19XTroM4Cmz0 X-Received: by 2002:a05:6a00:3494:b0:6cd:fd83:7a10 with SMTP id cp20-20020a056a00349400b006cdfd837a10mr931068pfb.10.1701663181865; Sun, 03 Dec 2023 20:13:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701663181; cv=none; d=google.com; s=arc-20160816; b=vFjAekNLFT8k1qYM9LuYk3Ek/xGEIb5fA1eT47D1uv759srNmsTFW16ABckxDrExtu pQUpBjGDoSnRGMxThfYLfdJJMuUYPbi32if8ZcFSgoIX1bZb3DdnvkIbb0ev5I+VX9l7 X3NbgqowUL9EJA8wPRIDS2XIepR77SsnWJnleHBAAGmzlBRyFTDliAJJ/sQlXugHH/Rm MDzZv8iGWmXTMqovPbbbE2C6u4VK81gSa2IED8wtT/Ydy9eJe9WOE1z/Nuzun76T6U+r Rs2GQCqr9yHOVlVMWGRMXSGCDzOyPjAmvxgnb+6rC7JTb1zapwJoFYft1mTbINRS8ceC vA0A== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=uSIjHQyxvuiMYpm126xyxG1Zci+DFvN4cs1bYgkFaNU=; fh=LA5TcmG+J+MIumlHbsq7Y7740AEUuCryJJIwYOuLYy0=; b=INsep776CwLQeaHc9wrPF/9w7nNsTLZRZUJh3yB/vXHb/523oetFlrbfcjxMzFfcNj F4Jh6T/PpPfKPcTfsJjF7SksHO05oZF8cwlt23AKI8D4JtKN4MqEz8CFye2v3qWBi/FR lSr8slpl7P4RlIiHq2phU6xBQrjCwSXaYoHVuJVaTL3cAzJsa/WrUPsKr3PbnCZf2DDq 1OeMMUvMccCaCUFe21EKyAG8fBY3uXKnD+X6wjzKpPWhvihqT/SgSKWTdBHx3jsNUV6t U6z/po0TxzwXKq8G191DgbPR6z0sWCnB+zlsj4DN3X+5UjFCrbLlFmnobt4Gkw/qG9By MZyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AjY5m3WZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id v186-20020a632fc3000000b005bdd8af5a15si7076390pgv.668.2023.12.03.20.13.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 20:13:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AjY5m3WZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 33874806BC3D; Sun, 3 Dec 2023 20:12:59 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229869AbjLDEMg (ORCPT + 99 others); Sun, 3 Dec 2023 23:12:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229510AbjLDEMe (ORCPT ); Sun, 3 Dec 2023 23:12:34 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF7A9D5 for ; Sun, 3 Dec 2023 20:12:40 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40b4d9e81deso42577435e9.0 for ; Sun, 03 Dec 2023 20:12:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1701663159; x=1702267959; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=uSIjHQyxvuiMYpm126xyxG1Zci+DFvN4cs1bYgkFaNU=; b=AjY5m3WZdb4y9NSY8BGOtBrPZaPWeU7XUlaaMu0f7XApsVwQOMEWo7J1Q/h4cptJL0 WWyid3cNzIaR5YXKztsOQg+4HYThRlujOBTSNwqsnbM1O6427recNY9PdDv2ueh9asqW HhhLhdHIoadO+UTtH4mSTjnBTu+AfJC6T2aiOT4vdoIlrbbcyoPRz8ntFLIj3D1gCYns WADCVpCClK1PvpiXIkteKC9xWzu95V0WguA/xGfaGn4j1yDcQ8InpeiTw91a7JJjTxkk 1vWJsHE7VbEiYInMv8GOxwa1Q3chrXw3E536LJZA9dk1EKT/TnKWxwLnsKkEb090Rd8N mppg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701663159; x=1702267959; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=uSIjHQyxvuiMYpm126xyxG1Zci+DFvN4cs1bYgkFaNU=; b=hlzZKEqMwkTk9bYx/p4rM7SZ/PbL/WskcZXHCW9lCNiqcJtuyx1q9cS6C/t/zzPobJ X804YzAZ3ykpv4y8xLwf/cLTM9FcDQII7gYLzA0zS7Kl/RdF1nb1mZ70eOD2t/9w66AV +MzRaElHSCCWun+yLuGysujSQBTjN2HIsvpIDB6LQDFdBOClU6VWeOHOJ0cTX7X1NCpd H2+x17T+JIW2rM4kwOPeWxOX8z/RK0eFMOHAjZM2BgiBdJoUsdG7/PZyejfL/R6L25B0 SOdWFSfztW7oqnuoVIwl78jMlmIBdQBMb/tPw2GXzhK07d6ldq50u9RapMOQmqUfRERi gN2Q== X-Gm-Message-State: AOJu0YzBHX0MFf4baTMYY2ue3UnB3hbPDZbAb1cZnjtjOSnQ6jn6rXp4 z9WBKOgtq/Q+8u+inCKhEGNg3w== X-Received: by 2002:a05:600c:3b1d:b0:40b:5e1e:cf9 with SMTP id m29-20020a05600c3b1d00b0040b5e1e0cf9mr1855181wms.52.1701663159222; Sun, 03 Dec 2023 20:12:39 -0800 (PST) Received: from localhost ([102.36.222.112]) by smtp.gmail.com with ESMTPSA id b19-20020a05600c4e1300b0040648217f4fsm17107376wmq.39.2023.12.03.20.12.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 20:12:38 -0800 (PST) Date: Mon, 4 Dec 2023 07:12:35 +0300 From: Dan Carpenter To: Andrey Konovalov , "Liu, Yujie" Cc: Andrew Morton , kernel test robot , Haibo Li , linux-kernel@vger.kernel.org, Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Vincenzo Frascino , Matthias Brugger , AngeloGioacchino Del Regno , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, xiaoming.yu@mediatek.com Subject: Re: [PATCH] fix comparison of unsigned expression < 0 Message-ID: References: <20231128075532.110251-1-haibo.li@mediatek.com> <20231128172238.f80ed8dd74ab2a13eba33091@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Sun, 03 Dec 2023 20:12:59 -0800 (PST) On Wed, Nov 29, 2023 at 04:01:47AM +0100, Andrey Konovalov wrote: > On Wed, Nov 29, 2023 at 2:22 AM Andrew Morton wrote: > > > > On Tue, 28 Nov 2023 15:55:32 +0800 Haibo Li wrote: > > > > > Kernel test robot reported: > > > > > > ''' > > > mm/kasan/report.c:637 kasan_non_canonical_hook() warn: > > > unsigned 'addr' is never less than zero. > > > ''' > > > The KASAN_SHADOW_OFFSET is 0 on loongarch64. > > > > > > To fix it,check the KASAN_SHADOW_OFFSET before do comparison. > > > > > > --- a/mm/kasan/report.c > > > +++ b/mm/kasan/report.c > > > @@ -634,10 +634,10 @@ void kasan_non_canonical_hook(unsigned long addr) > > > { > > > unsigned long orig_addr; > > > const char *bug_type; > > > - > > > +#if KASAN_SHADOW_OFFSET > 0 > > > if (addr < KASAN_SHADOW_OFFSET) > > > return; > > > - > > > +#endif > > > > We'd rather not add ugly ifdefs for a simple test like this. If we > > replace "<" with "<=", does it fix? I suspect that's wrong. > > Changing the comparison into "<=" would be wrong. > I would say that changing it to <= is seldom the correct thing. I've wanted to make that trigger a warning as well. > But I actually don't think we need to fix anything here. > > This issue looks quite close to a similar comparison with 0 issue > Linus shared his opinion on here: > > https://lore.kernel.org/all/Pine.LNX.4.58.0411230958260.20993@ppc970.osdl.org/ > > I don't know if the common consensus with the regard to issues like > that changed since then. But if not, perhaps we can treat this kernel > test robot report as a false positive. I would say that the consensus has changed somewhere around 2015 or so. Unsigned comparisons to zero used to be one of the most common types of bugs in new code but now almost all subsystems have turned on the GCC warning for this. However, this is a Smatch warning and I agree with Linus on this. For example, Smatch doesn't complain about the example code the Linus mentioned. if (a < 0 || a > X) And in this case, it's a one liner fix for me to add KASAN_SHADOW_OFFSET as an allowed macro and silence the warning. regards, dan carpenter