public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: dsterba@suse.cz, Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>,
	Matthew Wilcox <willy@infradead.org>,
	linux-kernel@vger.kernel.org,
	kernel-hardening@lists.openwall.com
Subject: Re: [PATCH v2] overflow: Add __must_check attribute to check_*() helpers
Date: Mon, 17 Aug 2020 12:36:51 -0700	[thread overview]
Message-ID: <202008171235.816B3AD@keescook> (raw)
In-Reply-To: <20200817090854.GA2026@twin.jikos.cz>

On Mon, Aug 17, 2020 at 11:08:54AM +0200, David Sterba wrote:
> On Sat, Aug 15, 2020 at 10:09:24AM -0700, Kees Cook wrote:
> > +static inline bool __must_check __must_check_overflow(bool overflow)
> > +{
> > +	return unlikely(overflow);
> 
> How does the 'unlikely' hint propagate through return? It is in a static
> inline so compiler has complete information in order to use it, but I'm
> curious if it actually does.

It may not -- it depends on how the compiler decides to deal with it. :)

> In case the hint gets dropped, the fix would probably be
> 
> #define check_add_overflow(a, b, d) unlikely(__must_check_overflow(({	\
>  	typeof(a) __a = (a);			\
>  	typeof(b) __b = (b);			\
>  	typeof(d) __d = (d);			\
>  	(void) (&__a == &__b);			\
>  	(void) (&__a == __d);			\
>  	__builtin_add_overflow(__a, __b, __d);	\
> })))

Unfortunately not, as the unlikely() ends up eating the __must_check
attribute. :(

-- 
Kees Cook

  parent reply	other threads:[~2020-08-17 19:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-15 17:09 [PATCH v2] overflow: Add __must_check attribute to check_*() helpers Kees Cook
2020-08-17  9:08 ` David Sterba
2020-08-17  9:33   ` Rasmus Villemoes
2020-08-17 19:36   ` Kees Cook [this message]
2020-08-18  6:27     ` Leon Romanovsky

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=202008171235.816B3AD@keescook \
    --to=keescook@chromium.org \
    --cc=dsterba@suse.cz \
    --cc=gustavoars@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=willy@infradead.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