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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A2142C07E9D for ; Mon, 26 Sep 2022 21:07:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5EFFE10E0DA; Mon, 26 Sep 2022 21:07:20 +0000 (UTC) Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by gabe.freedesktop.org (Postfix) with ESMTPS id B0A2310E0DE for ; Mon, 26 Sep 2022 21:07:16 +0000 (UTC) Received: by mail-pf1-x429.google.com with SMTP id a29so7921829pfk.5 for ; Mon, 26 Sep 2022 14:07:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=VUYHQIv2vL8pY0r5skq1FuqyyfYP1QoMOYkxGZwbp6o=; b=TxQD2fJTodac/gzds749N6eKDMqdv7Q8g+tPhsOiW/sX3qUzP3f31tYswj1cNjhZ+P GZ26rUT4PfJw2GQKkiXkOXyDG3qoXJdjcDtY3ngV/e6Eip/wNz2SxOqyLUFoEqou289d 65H2ej14mtX4cRsJfIOnYU6qdCyop+wYz0PRE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=VUYHQIv2vL8pY0r5skq1FuqyyfYP1QoMOYkxGZwbp6o=; b=lngD6g3H53R3qpkpDAAh3Dx/Hcn8SJOaTYGPiB9jikSktkEjD0vUaCd9cPAOuga9dp MIeus+7iLnTr4imFnz2cy8kbFFWDpg4zbxQJW879+2P4aDgAfZ6TfhNasMp4VjFASIEx ROjRiMIw52jDr3/mn/HHZdXTS/5aDVDeUTeSFrrHtue1Tzu8VKwbpHBpuqhu7kF05Yz5 xAgma3af6ek3I2YWOFBRV45UqwVkylivE9SdFnS8dnR21312YW03OLDmLTpyJH8vX5Dk IC2LY16FKdhVtqgRL0CWQvH+U0VrN8+nOpM2o2SLC+QjEoVG2aZE11G5+UNEhEH7zt5P u3ww== X-Gm-Message-State: ACrzQf04J4Z3SV48oDBzXWD+gbGEOum0cj+3xaaDPpCrIMsokkzmOc4q n8vF62tdC8FCvVUkpMT+KXnRjA== X-Google-Smtp-Source: AMsMyM6ac5PcbdyiCXdkvj0iGPsWyVMYvQOqt4HWPCMIqT7ijtbq72queIktQfLMWxfsTRb46FTITA== X-Received: by 2002:a63:441b:0:b0:439:103b:25a4 with SMTP id r27-20020a63441b000000b00439103b25a4mr21064706pga.487.1664226436243; Mon, 26 Sep 2022 14:07:16 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id h6-20020aa79f46000000b00540ffb28da0sm13290247pfr.91.2022.09.26.14.07.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 14:07:15 -0700 (PDT) Date: Mon, 26 Sep 2022 14:07:14 -0700 From: Kees Cook To: Nick Desaulniers Message-ID: <202209261405.619441AC2F@keescook> References: <20220926191109.1803094-1-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: Re: [Intel-gfx] [PATCH v2] overflow: Introduce overflows_type() and castable_to_type() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Arnd Bergmann , David Airlie , Tom Rix , Daniel Latypov , llvm@lists.linux.dev, "Gustavo A. R. Silva" , Nathan Chancellor , linux-sparse@vger.kernel.org, linux-hardening@vger.kernel.org, Daniel Vetter , Rodrigo Vivi , intel-gfx@lists.freedesktop.org, Vitor Massaru Iha , Luc Van Oostenryck Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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? > 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. -- Kees Cook 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 9D083C07E9D for ; Mon, 26 Sep 2022 21:07:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231326AbiIZVHW (ORCPT ); Mon, 26 Sep 2022 17:07:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231332AbiIZVHS (ORCPT ); Mon, 26 Sep 2022 17:07:18 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5F2CA1D55 for ; Mon, 26 Sep 2022 14:07:16 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id d82so7889519pfd.10 for ; Mon, 26 Sep 2022 14:07:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=VUYHQIv2vL8pY0r5skq1FuqyyfYP1QoMOYkxGZwbp6o=; b=TxQD2fJTodac/gzds749N6eKDMqdv7Q8g+tPhsOiW/sX3qUzP3f31tYswj1cNjhZ+P GZ26rUT4PfJw2GQKkiXkOXyDG3qoXJdjcDtY3ngV/e6Eip/wNz2SxOqyLUFoEqou289d 65H2ej14mtX4cRsJfIOnYU6qdCyop+wYz0PRE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=VUYHQIv2vL8pY0r5skq1FuqyyfYP1QoMOYkxGZwbp6o=; b=vIp1pnlHocTL82LRnRsSb0HZzQq60qKt5Wbh/fYSBIoh9mCsqVej+im32aYcgUVcHs fb8sn0mRTnoPzduycKJhXzW1jedWnOZud1vTcJB/ONI7HhyUIMwvA6yqGx5FC5hpDqv8 McnTP2r8eTbm5ZWjssaei9+9OJTFHyKo7avEPEgbSh/jhuSPI/5s+kanyORANkYVeB0P /MOmIuF7fgMJxE0u6IhxAeYQGbjrG7zD+rDGsT+G6odDH7CZtbeW5OYtg0al38A2bQAt gLoyWXmjwm0frfzevDzQj7PD4WFNnV07VBWa1N4xZUu/KXmWRd2fS24nA8QrFv64x9+n jV3Q== X-Gm-Message-State: ACrzQf3ZYsjMLlsDyaNBLMVwaOnwZtsY+kcFcMvAMRfh+eXi0pxP7zP6 JlMOV9ugOm42ua0+2B0GyViZAg== X-Google-Smtp-Source: AMsMyM6ac5PcbdyiCXdkvj0iGPsWyVMYvQOqt4HWPCMIqT7ijtbq72queIktQfLMWxfsTRb46FTITA== X-Received: by 2002:a63:441b:0:b0:439:103b:25a4 with SMTP id r27-20020a63441b000000b00439103b25a4mr21064706pga.487.1664226436243; Mon, 26 Sep 2022 14:07:16 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id h6-20020aa79f46000000b00540ffb28da0sm13290247pfr.91.2022.09.26.14.07.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 14:07:15 -0700 (PDT) Date: Mon, 26 Sep 2022 14:07:14 -0700 From: Kees Cook To: 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, Arnd Bergmann Subject: Re: [PATCH v2] overflow: Introduce overflows_type() and castable_to_type() Message-ID: <202209261405.619441AC2F@keescook> References: <20220926191109.1803094-1-keescook@chromium.org> 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-hardening@vger.kernel.org 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? > 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. -- Kees Cook 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E6578C07E9D for ; Mon, 26 Sep 2022 21:07:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8274510E0DE; Mon, 26 Sep 2022 21:07:20 +0000 (UTC) Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by gabe.freedesktop.org (Postfix) with ESMTPS id ABE9F10E0DA for ; Mon, 26 Sep 2022 21:07:16 +0000 (UTC) Received: by mail-pf1-x42c.google.com with SMTP id y136so7931461pfb.3 for ; Mon, 26 Sep 2022 14:07:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=VUYHQIv2vL8pY0r5skq1FuqyyfYP1QoMOYkxGZwbp6o=; b=TxQD2fJTodac/gzds749N6eKDMqdv7Q8g+tPhsOiW/sX3qUzP3f31tYswj1cNjhZ+P GZ26rUT4PfJw2GQKkiXkOXyDG3qoXJdjcDtY3ngV/e6Eip/wNz2SxOqyLUFoEqou289d 65H2ej14mtX4cRsJfIOnYU6qdCyop+wYz0PRE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=VUYHQIv2vL8pY0r5skq1FuqyyfYP1QoMOYkxGZwbp6o=; b=xst/FDa2elUvTgDfI46vhNE6mYPiTfFb3Rs4Yv1FIhVBkkCWrwnaa4iKR68Lojxa7T wN76uEiXACdtzPqA2e0awgibFxmlzF+USo6G86Wwf4Svb+CDSIUzarHqsYR4IwpwuST1 pjFggytCAcHl05n014Ggt3VElXyTFkVrbhaEjjD66ViNaIIu17kWtJ1WcQXmxsguWxkI XKCXRK9Q9lNCcCMHIMSiN0Qhlgb3lVhH7AXfs56zxWnibU0g7KAxXmBKyDO9Rq8T4q4T Zh06rGEIzwFx9160W6RzTdgWtfxw1p1sqTYz4GocQ6Gx1J5CmP+KoF0gNgszD37s+mX5 E5bQ== X-Gm-Message-State: ACrzQf117YMTIBl5WeWxDUQJOmyA8NBMgDbqvLD+WYT3x5Af1qHSr80x bUEgv6DTFwMS8EDWKSjA3N5trQ== X-Google-Smtp-Source: AMsMyM6ac5PcbdyiCXdkvj0iGPsWyVMYvQOqt4HWPCMIqT7ijtbq72queIktQfLMWxfsTRb46FTITA== X-Received: by 2002:a63:441b:0:b0:439:103b:25a4 with SMTP id r27-20020a63441b000000b00439103b25a4mr21064706pga.487.1664226436243; Mon, 26 Sep 2022 14:07:16 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id h6-20020aa79f46000000b00540ffb28da0sm13290247pfr.91.2022.09.26.14.07.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 14:07:15 -0700 (PDT) Date: Mon, 26 Sep 2022 14:07:14 -0700 From: Kees Cook To: Nick Desaulniers Subject: Re: [PATCH v2] overflow: Introduce overflows_type() and castable_to_type() Message-ID: <202209261405.619441AC2F@keescook> References: <20220926191109.1803094-1-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tvrtko Ursulin , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Arnd Bergmann , David Airlie , Tom Rix , Daniel Latypov , llvm@lists.linux.dev, "Gustavo A. R. Silva" , Gwan-gyeong Mun , Nathan Chancellor , linux-sparse@vger.kernel.org, linux-hardening@vger.kernel.org, Rodrigo Vivi , intel-gfx@lists.freedesktop.org, Vitor Massaru Iha , Luc Van Oostenryck Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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? > 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. -- Kees Cook