public inbox for linux-hardening@vger.kernel.org
 help / color / mirror / Atom feed
From: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
To: Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>, keescook@chromium.org
Cc: luc.vanoostenryck@gmail.com, nathan@kernel.org,
	ndesaulniers@google.com, trix@redhat.com, dlatypov@google.com,
	vitor@massaru.org, gustavoars@kernel.org,
	linux-hardening@vger.kernel.org, llvm@lists.linux.dev,
	jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com,
	rodrigo.vivi@intel.com, tvrtko.ursulin@linux.intel.com,
	airlied@linux.ie, daniel@ffwll.ch, linux-kernel@vger.kernel.org,
	intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	linux-sparse@vger.kernel.org, arnd@kernel.org,
	mchehab@kernel.org, mauro.chehab@linux.intel.com
Subject: Re: [PATCH v5] overflow: Introduce overflows_type() and castable_to_type()
Date: Wed, 2 Nov 2022 12:52:32 +0100	[thread overview]
Message-ID: <307b90cb-b80d-6ce3-14ae-4a0b2ee5e447@prevas.dk> (raw)
In-Reply-To: <20221024201125.1416422-1-gwan-gyeong.mun@intel.com>

On 24/10/2022 22.11, Gwan-gyeong Mun wrote:
> From: Kees Cook <keescook@chromium.org>
> 
> Implement a robust overflows_type() macro to test if a variable or
> constant value would overflow another variable or type. This can be
> used as a constant expression for static_assert() (which requires a
> constant expression[1][2]) when used on constant values. This must be
> constructed manually, since __builtin_add_overflow() does not produce
> a constant expression[3].
> 
> Additionally adds castable_to_type(), similar to __same_type(), but for
> checking if a constant value would overflow if cast to a given type.
> 

> +#define __overflows_type_constexpr(x, T) (			\
> +	is_unsigned_type(typeof(x)) ?				\
> +		(x) > type_max(typeof(T)) ? 1 : 0		\
> +	: is_unsigned_type(typeof(T)) ?				\
> +		(x) < 0 || (x) > type_max(typeof(T)) ? 1 : 0	\
> +		: (x) < type_min(typeof(T)) ||			\
> +		  (x) > type_max(typeof(T)) ? 1 : 0)
> +

Can't all these instances of "foo ? 1 : 0" be simplified to "foo"? That
would improve the readability of this thing somewhat IMO.

Rasmus


  parent reply	other threads:[~2022-11-02 11:52 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-26 19:11 [PATCH v2] overflow: Introduce overflows_type() and castable_to_type() Kees Cook
2022-09-26 20:17 ` Nick Desaulniers
2022-09-26 21:07   ` Kees Cook
2022-09-27  6:45     ` Arnd Bergmann
2022-09-27  8:29 ` Gwan-gyeong Mun
2022-09-28  8:19 ` Gwan-gyeong Mun
2022-10-13  6:49 ` [PATCH v3] " Gwan-gyeong Mun
2022-10-13  8:12   ` Jani Nikula
2022-10-21  8:33 ` [PATCH v4] " Gwan-gyeong Mun
2022-10-21 16:06   ` Nathan Chancellor
2022-10-24 20:11 ` [PATCH v5] " Gwan-gyeong Mun
2022-10-29  5:55   ` Gwan-gyeong Mun
2022-10-29  7:32     ` Kees Cook
2022-10-29  8:01       ` Gwan-gyeong Mun
2022-11-01 23:06         ` Kees Cook
2022-11-02 11:27           ` Gwan-gyeong Mun
2022-11-02 11:52   ` Rasmus Villemoes [this message]
2022-11-02 19:33     ` Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=307b90cb-b80d-6ce3-14ae-4a0b2ee5e447@prevas.dk \
    --to=rasmus.villemoes@prevas.dk \
    --cc=airlied@linux.ie \
    --cc=arnd@kernel.org \
    --cc=daniel@ffwll.ch \
    --cc=dlatypov@google.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gustavoars@kernel.org \
    --cc=gwan-gyeong.mun@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=keescook@chromium.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=luc.vanoostenryck@gmail.com \
    --cc=mauro.chehab@linux.intel.com \
    --cc=mchehab@kernel.org \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=trix@redhat.com \
    --cc=tvrtko.ursulin@linux.intel.com \
    --cc=vitor@massaru.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox