kasan: test: Silence allocation warnings from GCC 12
authorKees Cook <keescook@chromium.org>
Sun, 13 Feb 2022 18:26:25 +0000 (10:26 -0800)
committerKees Cook <keescook@chromium.org>
Mon, 14 Feb 2022 00:48:25 +0000 (16:48 -0800)
commit9622c0be0973f236c8413f936d0d14af5ea2a71e
tree57e7cf136b6712620415b5e1f8dd9fe1b879e528
parent48f4900c115a99dd83e1c17347ff040ca2fdf165
kasan: test: Silence allocation warnings from GCC 12

GCC 12 is able to see more problems with allocation sizes at compile
time, so these must be silenced so the runtime checks will still be
available. Use OPTIMIZER_HIDE_VAR() to silence the new warning:

lib/test_kasan.c: In function 'ksize_uaf':
lib/test_kasan.c:781:61: warning: array subscript 120 is outside array bounds of 'void[120]' [-Warray-bounds]
  781 |         KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[size]);
      |                                       ~~~~~~~~~~~~~~~~~~~~~~^~~~~~
lib/test_kasan.c:96:9: note: in definition of macro 'KUNIT_EXPECT_KASAN_FAIL'
   96 |         expression;                                                     \
      |         ^~~~~~~~~~
In function 'kmalloc',
    inlined from 'ksize_uaf' at lib/test_kasan.c:775:8:
./include/linux/slab.h:581:24: note: at offset 120 into object of size 120 allocated by 'kmem_cache_alloc_trace'
  581 |                 return kmem_cache_alloc_trace(
      |                        ^~~~~~~~~~~~~~~~~~~~~~~
  582 |                                 kmalloc_caches[kmalloc_type(flags)][index],
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  583 |                                 flags, size);
      |                                 ~~~~~~~~~~~~

Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: kasan-dev@googlegroups.com
Signed-off-by: Kees Cook <keescook@chromium.org>
lib/test_kasan.c