lkml.org 
[lkml]   [2021]   [Sep]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [patch 9/9] mm/vmalloc: add __alloc_size attributes for better bounds checking
    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@linux-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...

    -Kees

    --
    Kees Cook

    \
     
     \ /
      Last update: 2021-09-22 01:38    [W:3.816 / U:0.464 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site