Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Sat, 15 Aug 2020 10:11:13 -0700
From: Kees Cook <keescook@...omium.org>
To: Rasmus Villemoes <linux@...musvillemoes.dk>
Cc: "Gustavo A. R. Silva" <gustavoars@...nel.org>,
	Jason Gunthorpe <jgg@...pe.ca>, Leon Romanovsky <leon@...nel.org>,
	Matthew Wilcox <willy@...radead.org>, linux-kernel@...r.kernel.org,
	kernel-hardening@...ts.openwall.com
Subject: Re: [PATCH] overflow: Add __must_check attribute to check_*() helpers

On Thu, Aug 13, 2020 at 08:39:44AM +0200, Rasmus Villemoes wrote:
> On 12/08/2020 23.51, Kees Cook wrote:
> > Since the destination variable of the check_*_overflow() helpers will
> > contain a wrapped value on failure, it would be best to make sure callers
> > really did check the return result of the helper. Adjust the macros to use
> > a bool-wrapping static inline that is marked with __must_check. This means
> > the macros can continue to have their type-agnostic behavior while gaining
> > the function attribute (that cannot be applied directly to macros).
> > 
> > Suggested-by: Rasmus Villemoes <linux@...musvillemoes.dk>
> > Signed-off-by: Kees Cook <keescook@...omium.org>
> > ---
> >  include/linux/overflow.h | 51 +++++++++++++++++++++++-----------------
> >  1 file changed, 30 insertions(+), 21 deletions(-)
> > 
> > diff --git a/include/linux/overflow.h b/include/linux/overflow.h
> > index 93fcef105061..ef7d538c2d08 100644
> > --- a/include/linux/overflow.h
> > +++ b/include/linux/overflow.h
> > @@ -43,6 +43,16 @@
> >  #define is_non_negative(a) ((a) > 0 || (a) == 0)
> >  #define is_negative(a) (!(is_non_negative(a)))
> >  
> > +/*
> > + * Allows to effectively us apply __must_check to a macro so we can have
> 
> word ordering?

This and the __must_check-bool() renaming now done and sent in v2.
Thanks!

> Sorry, I meant to send this before your cooking was done but forgot
> about it again. Not a big deal, but it occurred to me it might be better
> to rename the existing check_*_overflow to __check_*_overflow (in both
> branches of the COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW), and then
> 
> #define check_*_overflow(a, b, d)
> __must_check_bool(__check_*_overflow(a, b, d))

At the end of the day, I'd rather not have a way to ignore the overflow
in this way -- I'd rather have a set of wrap_mul_overflow() helpers
instead. Then we've got proper annotation of the expectation (and a
place for function attributes to be added to tell sanitizers to ignore
overflow).

-- 
Kees Cook

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.