linux-stable/mm/kasan
Arnd Bergmann 03b821647b kasan/test: avoid gcc warning for intentional overflow
[ Upstream commit e10aea105e ]

The out-of-bounds test allocates an object that is three bytes too short
in order to validate the bounds checking.  Starting with gcc-14, this
causes a compile-time warning as gcc has grown smart enough to understand
the sizeof() logic:

mm/kasan/kasan_test.c: In function 'kmalloc_oob_16':
mm/kasan/kasan_test.c:443:14: error: allocation of insufficient size '13' for type 'struct <anonymous>' with size '16' [-Werror=alloc-size]
  443 |         ptr1 = kmalloc(sizeof(*ptr1) - 3, GFP_KERNEL);
      |              ^

Hide the actual computation behind a RELOC_HIDE() that ensures
the compiler misses the intentional bug.

Link: https://lkml.kernel.org/r/20240212111609.869266-1-arnd@kernel.org
Fixes: 3f15801cdc ("lib: add kasan test module")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Marco Elver <elver@google.com>
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-04-03 15:19:27 +02:00
..
Makefile kasan: move tests to mm/kasan/ 2022-10-03 14:03:02 -07:00
common.c kasan: fix Oops due to missing calls to kasan_arch_is_ready() 2023-02-22 12:59:46 +01:00
generic.c kasan: fix Oops due to missing calls to kasan_arch_is_ready() 2023-02-22 12:59:46 +01:00
hw_tags.c kasan: hw_tags: avoid invalid virt_to_page() 2023-05-11 23:03:39 +09:00
init.c
kasan.h kasan: add kasan_tag_mismatch prototype 2023-07-23 13:49:32 +02:00
kasan_test.c kasan/test: avoid gcc warning for intentional overflow 2024-04-03 15:19:27 +02:00
kasan_test_module.c kasan: move tests to mm/kasan/ 2022-10-03 14:03:02 -07:00
quarantine.c kasan: give better names to shadow values 2022-05-13 07:20:19 -07:00
report.c kasan: disable kasan_non_canonical_hook() for HW tags 2024-01-01 12:38:52 +00:00
report_generic.c kasan: better invalid/double-free report header 2022-10-03 14:03:02 -07:00
report_hw_tags.c kasan: simplify kasan_find_first_bad_addr call sites 2022-03-24 19:06:49 -07:00
report_sw_tags.c kasan: simplify kasan_find_first_bad_addr call sites 2022-03-24 19:06:49 -07:00
report_tags.c kasan: better invalid/double-free report header 2022-10-03 14:03:02 -07:00
shadow.c kasan: fix Oops due to missing calls to kasan_arch_is_ready() 2023-02-22 12:59:46 +01:00
sw_tags.c kasan: support kasan.stacktrace for SW_TAGS 2022-10-03 14:03:01 -07:00
tags.c kasan: dynamically allocate stack ring entries 2022-10-03 14:03:02 -07:00