Re: [PATCH v2 1/7] Compiler Attributes: Add __alloc_size() for better bounds checking

From: Miguel Ojeda
Date: Wed Aug 18 2021 - 20:05:01 EST

On Wed, Aug 18, 2021 at 11:40 PM Kees Cook <keescook@xxxxxxxxxxxx> wrote:
> GCC and Clang can use the "alloc_size" attribute to better inform the
> results of __builtin_object_size() (for compile-time constant values).
> Clang can additionally use alloc_size to inform the results of
> __builtin_dynamic_object_size() (for run-time values).
> Because GCC sees the frequent use of struct_size() as an allocator size
> argument, and notices it can return SIZE_MAX (the overflow indication),
> it complains about these call sites may overflow (since SIZE_MAX is
> greater than the default -Walloc-size-larger-than=PTRDIFF_MAX). This
> isn't helpful since we already know a SIZE_MAX will be caught at run-time
> (this was an intentional design). Instead, just disable this check as
> it is both a false positive and redundant. (Clang does not have this
> warning option.)


Reviewed-by: Miguel Ojeda <ojeda@xxxxxxxxxx>