From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BEAB0C07E9D for ; Tue, 27 Sep 2022 06:46:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230017AbiI0GqM (ORCPT ); Tue, 27 Sep 2022 02:46:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229849AbiI0GqK (ORCPT ); Tue, 27 Sep 2022 02:46:10 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48C479FAA0; Mon, 26 Sep 2022 23:46:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 085F6B819D3; Tue, 27 Sep 2022 06:46:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 801EFC433B5; Tue, 27 Sep 2022 06:46:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664261166; bh=eEUvxBZsi9LqCvOrkkoLXt0oGQK0hSltb52/gNuFgZc=; h=In-Reply-To:References:Date:From:To:Cc:Subject:From; b=YeF1uQu6QOwIwpqO25V8Se5Jh3/7LmTuggyeQGTEqoYTG4OZwBjgCOJSzYSJXKGjw YSpsg9ZkD5PAQqvi237xvtgYVpQoMz1J9CIquEp+oYCwBBav3raIhCyTBqjVaoPvmU ay7RPeC75QtxLEeiOIoU+mvl5myNqJu+WGuxw9qSyI27+1ZK1u+/KSmpywTDKR1Xlz hyZEvZ7WAYFjgNQYbbX+nNrGF72JqlBKrpMk2/j5kexDYuf/xZmg6wfGMIkFk+WhrY GrEvw6szTG7DNmjTSArOWa2ufvKVt0dxj4VLmMSZMxcDfHH9jAXpIPfHJF/q2CKhlO nU9G5nKrTiy5w== Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailauth.nyi.internal (Postfix) with ESMTP id 5057227C0054; Tue, 27 Sep 2022 02:46:04 -0400 (EDT) Received: from imap51 ([10.202.2.101]) by compute3.internal (MEProxy); Tue, 27 Sep 2022 02:46:04 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeegfedgudduhecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvvefutgesthdtredtreertdenucfhrhhomhepfdet rhhnugcuuegvrhhgmhgrnhhnfdcuoegrrhhnugeskhgvrhhnvghlrdhorhhgqeenucggtf frrghtthgvrhhnpeelvefgudeiheefledttedthfffgfekudegkeelffdtiedvgfevieet teekheffveenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuih iivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghrnhguodhmvghsmhhtphgruhht hhhpvghrshhonhgrlhhithihqdduvdekhedujedtvdegqddvkeejtddtvdeigedqrghrnh gupeepkhgvrhhnvghlrdhorhhgsegrrhhnuggsrdguvg X-ME-Proxy: Feedback-ID: i36794607:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 81704B60089; Tue, 27 Sep 2022 02:46:03 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-968-g04df58079d-fm-20220921.001-g04df5807 Mime-Version: 1.0 Message-Id: <854247e0-6276-4f3b-b4e9-b408e151a6b3@www.fastmail.com> In-Reply-To: <202209261405.619441AC2F@keescook> References: <20220926191109.1803094-1-keescook@chromium.org> <202209261405.619441AC2F@keescook> Date: Tue, 27 Sep 2022 08:45:43 +0200 From: "Arnd Bergmann" To: "Kees Cook" , "Nick Desaulniers" Cc: "Gwan-gyeong Mun" , "Luc Van Oostenryck" , "Nathan Chancellor" , "Tom Rix" , "Daniel Latypov" , "Vitor Massaru Iha" , "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org, llvm@lists.linux.dev, "Jani Nikula" , "Joonas Lahtinen" , "Rodrigo Vivi" , "Tvrtko Ursulin" , "David Airlie" , "Daniel Vetter" , linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-sparse@vger.kernel.org Subject: Re: [PATCH v2] overflow: Introduce overflows_type() and castable_to_type() Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org On Mon, Sep 26, 2022, at 11:07 PM, Kees Cook wrote: > On Mon, Sep 26, 2022 at 01:17:18PM -0700, Nick Desaulniers wrote: >> + Arnd >> >> On Mon, Sep 26, 2022 at 12:11 PM Kees Cook wrote: >> > --- >> > v2: >> > - fix comment typo >> > - wrap clang pragma to avoid GCC warnings >> > - style nit cleanups >> > - rename __castable_to_type() to castable_to_type() >> > - remove prior overflows_type() definition >> > v1: https://lore.kernel.org/lkml/20220926003743.409911-1-keescook@chromium.org >> > diff --git a/lib/overflow_kunit.c b/lib/overflow_kunit.c >> > index f385ca652b74..fffc3f86181d 100644 >> > --- a/lib/overflow_kunit.c >> > +++ b/lib/overflow_kunit.c >> > @@ -16,6 +16,11 @@ >> > #include >> > #include >> > >> > +/* We're expecting to do a lot of "always true" or "always false" tests. */ >> > +#ifdef CONFIG_CC_IS_CLANG >> > +#pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare" >> > +#endif >> >> Any chance we can reuse parts of __diag_ignore or __diag_clang from >> include/linux/compiler_types.h or include/linux/compiler-clang.h >> respectively? > > Hm, I'm not sure how those are supposed to be used. Those defines don't > seem to be used externally? We use them in a couple of places. When I originally introduced them, the idea was to add more infrastructure around these to replace the various -Wno-... flags in local makefiles with more targetted annotations, and then have a way to control the warning levels (W=1 W=2 E=1 etc) per directory and per file, but I never completed the work to add the interesting bits. >> Those are needed for pragmas within preprocessor macros, which we >> don't have here, but I suspect they may be more concise to use here. > > Yeah, I was surprised when I had to wrap it in #ifdef given "clang" is > part of the string. > >> >> > +#define TEST_SAME_TYPE(t1, t2, same) do { \ >> > + typeof(t1) __t1h = type_max(t1); \ >> > + typeof(t1) __t1l = type_min(t1); \ >> > + typeof(t2) __t2h = type_max(t2); \ >> > + typeof(t2) __t2l = type_min(t2); \ >> >> Can we use __auto_type here rather than typeof(macro expansion)? > > I'd rather it stay explicit -- otherwise we start to wander into "oops, > we got lucky" territory for what should be a really distinct test case. The idea of __auto_type is to avoid the more deeply nested macros. If the preprocessed file turns into an absolute mess, adding a temporary variable may help. Not sure if that applies here. Arnd