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

From
Miguel Ojeda <hidden>
Date
2021-08-19 00:05:01
Also in
linux-hardening, linux-kbuild, lkml
Reply to
Kees Cook, 2021-08-18
On Wed, Aug 18, 2021 at 11:40 PM Kees Cook [off-list ref] 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.)
Thanks!

Reviewed-by: Miguel Ojeda <ojeda@kernel.org>

Cheers,
Miguel
Thread (20 messages) 20 messages, 7 authors, last reply 2021-09-22
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help