kunit/overflow: Fix DEFINE_FLEX tests for counted_by
authorKees Cook <kees@kernel.org>
Tue, 4 Mar 2025 17:28:48 +0000 (09:28 -0800)
committerKees Cook <kees@kernel.org>
Wed, 5 Mar 2025 03:31:35 +0000 (19:31 -0800)
commit04e403e6627d8513d14f3236e52068837eabd2a5
tree0106b5df03e10816f05bd6df95720e8b3f9b73ac
parentba6be7ba2d3fe146aae2e7ff1b28d111beaa7e31
kunit/overflow: Fix DEFINE_FLEX tests for counted_by

Unfortunately, __builtin_dynamic_object_size() does not take into account
flexible array sizes, even when they are sized by __counted_by. As a
result, the size tests for the flexible arrays need to be separated to
get an accurate check of the compiler's behavior. While at it, fully test
sizeof, __struct_size (bdos(..., 0)), and __member_size (bdos(..., 1)).

I still think this is a compiler design issue, but there's not much to
be done about it currently beyond adjusting these tests. GCC and Clang
agree on this behavior at least. :)

Reported-by: "Thomas Weißschuh" <linux@weissschuh.net>
Closes: https://lore.kernel.org/lkml/e1a1531d-6968-4ae8-a3b5-5ea0547ec4b3@t-8ch.de/
Fixes: 9dd5134c6158 ("kunit/overflow: Adjust for __counted_by with DEFINE_RAW_FLEX()")
Signed-off-by: Kees Cook <kees@kernel.org>
lib/tests/overflow_kunit.c