linux/mm/kasan
Andrey Konovalov 611806b4bf kasan: fix bug detection via ksize for HW_TAGS mode
The currently existing kasan_check_read/write() annotations are intended
to be used for kernel modules that have KASAN compiler instrumentation
disabled. Thus, they are only relevant for the software KASAN modes that
rely on compiler instrumentation.

However there's another use case for these annotations: ksize() checks
that the object passed to it is indeed accessible before unpoisoning the
whole object. This is currently done via __kasan_check_read(), which is
compiled away for the hardware tag-based mode that doesn't rely on
compiler instrumentation. This leads to KASAN missing detecting some
memory corruptions.

Provide another annotation called kasan_check_byte() that is available
for all KASAN modes. As the implementation rename and reuse
kasan_check_invalid_free(). Use this new annotation in ksize().
To avoid having ksize() as the top frame in the reported stack trace
pass _RET_IP_ to __kasan_check_byte().

Also add a new ksize_uaf() test that checks that a use-after-free is
detected via ksize() itself, and via plain accesses that happen later.

Link: https://linux-review.googlesource.com/id/Iaabf771881d0f9ce1b969f2a62938e99d3308ec5
Link: https://lkml.kernel.org/r/f32ad74a60b28d8402482a38476f02bb7600f620.1610733117.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Reviewed-by: Marco Elver <elver@google.com>
Reviewed-by: Alexander Potapenko <glider@google.com>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Branislav Rankov <Branislav.Rankov@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Evgenii Stepanov <eugenis@google.com>
Cc: Kevin Brodsky <kevin.brodsky@arm.com>
Cc: Peter Collingbourne <pcc@google.com>
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-02-24 13:38:31 -08:00
..
common.c kasan: fix bug detection via ksize for HW_TAGS mode 2021-02-24 13:38:31 -08:00
generic.c kasan: fix bug detection via ksize for HW_TAGS mode 2021-02-24 13:38:31 -08:00
hw_tags.c kasan, arm64: allow using KUnit tests with HW_TAGS mode 2021-02-24 13:38:31 -08:00
init.c kasan: fix incorrect arguments passing in kasan_add_zero_shadow 2021-01-24 10:34:52 -08:00
kasan.h kasan: fix bug detection via ksize for HW_TAGS mode 2021-02-24 13:38:31 -08:00
Makefile kasan, arm64: implement HW_TAGS runtime 2020-12-22 12:55:08 -08:00
quarantine.c kasan: prefix global functions with kasan_ 2021-02-24 13:38:30 -08:00
report.c kasan: add compiler barriers to KUNIT_EXPECT_KASAN_FAIL 2021-02-24 13:38:31 -08:00
report_generic.c kasan: prefix global functions with kasan_ 2021-02-24 13:38:30 -08:00
report_hw_tags.c kasan: prefix global functions with kasan_ 2021-02-24 13:38:30 -08:00
report_sw_tags.c kasan: prefix global functions with kasan_ 2021-02-24 13:38:30 -08:00
shadow.c kasan: add match-all tag tests 2021-02-24 13:38:31 -08:00
sw_tags.c kasan: fix bug detection via ksize for HW_TAGS mode 2021-02-24 13:38:31 -08:00