From 80fcd42def1ed62df2d8533fa010985d4e7e4097 Mon Sep 17 00:00:00 2001 From: Andrey Konovalov Date: Thu, 24 Mar 2022 18:12:31 -0700 Subject: [PATCH] BACKPORT: kasan: simplify kasan_update_kunit_status() and call sites (Backport: fix conflicts with d9f210a14db5, which drops the KUNIT ifdefs.) - Rename kasan_update_kunit_status() to update_kunit_status() (the function is static). - Move the IS_ENABLED(CONFIG_KUNIT) to the function's definition instead of duplicating it at call sites. - Obtain and check current->kunit_test within the function. Link: https://lkml.kernel.org/r/dac26d811ae31856c3d7666de0b108a3735d962d.1646237226.git.andreyknvl@google.com Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko Cc: Andrey Ryabinin Cc: Dmitry Vyukov Cc: Marco Elver Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Bug: 254721825 (cherry picked from commit 3784c299eafc6dd1ca5a23f4020f18ca565e07af) Change-Id: I3024e0390d7fdb95ad763aa02666a156e4083c3e Signed-off-by: Andrey Konovalov --- mm/kasan/report.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 123d1ae441bb..25c57923574a 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -347,21 +347,26 @@ static bool report_enabled(void) return !test_and_set_bit(KASAN_BIT_REPORTED, &kasan_flags); } -static void kasan_update_kunit_status(struct kunit *cur_test, bool sync) +static void update_kunit_status(bool sync) { + struct kunit *test; struct kunit_resource *resource; struct kunit_kasan_status *status; - resource = kunit_find_named_resource(cur_test, "kasan_status"); + test = current->kunit_test; + if (!test) + return; + resource = kunit_find_named_resource(test, "kasan_status"); if (!resource) { - kunit_set_failure(cur_test); + kunit_set_failure(test); return; } status = (struct kunit_kasan_status *)resource->data; WRITE_ONCE(status->report_found, true); WRITE_ONCE(status->sync_fault, sync); + kunit_put_resource(resource); } @@ -372,8 +377,7 @@ void kasan_report_invalid_free(void *object, unsigned long ip) object = kasan_reset_tag(object); - if (current->kunit_test) - kasan_update_kunit_status(current->kunit_test, true); + update_kunit_status(true); start_report(&flags); pr_err("BUG: KASAN: double-free or invalid-free in %pS\n", (void *)ip); @@ -389,8 +393,7 @@ void kasan_report_async(void) { unsigned long flags; - if (current->kunit_test) - kasan_update_kunit_status(current->kunit_test, false); + update_kunit_status(false); start_report(&flags); pr_err("BUG: KASAN: invalid-access\n"); @@ -409,8 +412,7 @@ static void __kasan_report(unsigned long addr, size_t size, bool is_write, void *untagged_addr; unsigned long flags; - if (current->kunit_test) - kasan_update_kunit_status(current->kunit_test, true); + update_kunit_status(true); disable_trace_on_warning();