[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <af3c775a1515f97c8dbe6a6651bd6e4b6986e8cd.camel@perches.com>
Date: Tue, 21 Sep 2021 16:45:44 -0700
From: Joe Perches <joe@...ches.com>
To: Kees Cook <keescook@...omium.org>, linux-kernel@...r.kernel.org
Cc: Andrew Morton <akpm@...ux-foundation.org>, apw@...onical.com,
Christoph Lameter <cl@...ux.com>,
Daniel Micay <danielmicay@...il.com>,
Dennis Zhou <dennis@...nel.org>, dwaipayanray1@...il.com,
Joonsoo Kim <iamjoonsoo.kim@....com>,
Linux-MM <linux-mm@...ck.org>,
Lukas Bulwahn <lukas.bulwahn@...il.com>,
mm-commits@...r.kernel.org, Nathan Chancellor <nathan@...nel.org>,
Nick Desaulniers <ndesaulniers@...gle.com>,
Miguel Ojeda <ojeda@...nel.org>,
Pekka Enberg <penberg@...nel.org>,
David Rientjes <rientjes@...gle.com>,
Tejun Heo <tj@...nel.org>, Vlastimil Babka <vbabka@...e.cz>
Subject: Re: [patch 9/9] mm/vmalloc: add __alloc_size attributes for better
bounds checking
On Tue, 2021-09-21 at 16:37 -0700, Kees Cook wrote:
> On Fri, Sep 10, 2021 at 10:23:48AM -0700, Linus Torvalds wrote:
> > On Thu, Sep 9, 2021 at 8:10 PM Andrew Morton <akpm@...ux-foundation.org> wrote:
> > >
> > > +__alloc_size(1)
> > > extern void *vmalloc(unsigned long size);
> > [...]
> >
> > All of these are added in the wrong place - inconsistent with the very
> > compiler documentation the patches add.
> >
> > The function attributes are generally added _after_ the function,
> > although admittedly we've been quite confused here before.
> >
> > But the very compiler documentation you point to in the patch that
> > adds these macros gives that as the examples both for gcc and clang:
> >
> > + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-alloc_005fsize-function-attribute
> > + * clang: https://clang.llvm.org/docs/AttributeReference.html#alloc-size
> >
> > and honestly I think that is the preferred format because this is
> > about the *function*, not about the return type.
> >
> > Do both placements work? Yes.
>
> I'm cleaning this up now, and have discovered that the reason for the
> before-function placement is consistency with static inlines. If I do this:
>
> static __always_inline void * kmalloc(size_t size, gfp_t flags) __alloc_size(1)
> {
> ...
> }
>
> GCC is very angry:
>
> ./include/linux/slab.h:519:1: error: attributes should be specified before the declarator in a function definition
> 519 | static __always_inline void *kmalloc_large(size_t size, gfp_t flags) __alloc_size(1)
> | ^~~~~~
>
> It's happy if I treat it as a "return type attribute" in the ordering,
> though:
>
> static __always_inline void * __alloc_size(1) kmalloc(size_t size, gfp_t flags)
>
> I'll do that unless you have a preference for somewhere else...
_please_ put it before the return type on a separate line.
[__attributes]
[static inline const] <return type> function(<args...>)
Powered by blists - more mailing lists