linux-stable/mm/kasan
Arnd Bergmann d0ef28a906 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:11:11 +02:00
..
Makefile kasan: test: fix test for new meminstrinsic instrumentation 2023-03-02 21:54:22 -08:00
common.c kasan: use internal prototypes matching gcc-13 builtins 2023-06-09 16:25:19 -07:00
generic.c kasan: fix type cast in memory_is_poisoned_n 2023-07-08 09:29:32 -07:00
hw_tags.c kasan: hw_tags: avoid invalid virt_to_page() 2023-05-02 17:23:27 -07:00
init.c kasan: Add (pmd|pud)_init for LoongArch zero_(pud|p4d)_populate process 2023-09-06 22:54:16 +08:00
kasan.h Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2023-10-05 13:16:47 -07:00
kasan_test.c kasan/test: avoid gcc warning for intentional overflow 2024-04-03 15:11:11 +02:00
kasan_test_module.c kasan: unify printk prefixes 2023-10-18 14:34:15 -07:00
quarantine.c kasan: unify printk prefixes 2023-10-18 14:34:15 -07:00
report.c kasan: use unchecked __memset internally 2023-10-18 14:34:15 -07:00
report_generic.c kasan: unify printk prefixes 2023-10-18 14:34:15 -07:00
report_hw_tags.c kasan: use internal prototypes matching gcc-13 builtins 2023-06-09 16:25:19 -07:00
report_sw_tags.c kasan: use internal prototypes matching gcc-13 builtins 2023-06-09 16:25:19 -07:00
report_tags.c kasan: infer allocation size by scanning metadata 2023-02-09 16:51:40 -08:00
shadow.c kasan: use unchecked __memset internally 2023-10-18 14:34:15 -07:00
sw_tags.c kasan: use internal prototypes matching gcc-13 builtins 2023-06-09 16:25:19 -07:00
tags.c kasan,kmsan: remove __GFP_KSWAPD_RECLAIM usage from kasan/kmsan 2023-06-23 16:59:26 -07:00