kasan: introduce complete_report_info
authorAndrey Konovalov <andreyknvl@google.com>
Mon, 5 Sep 2022 21:05:41 +0000 (23:05 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 3 Oct 2022 21:03:00 +0000 (14:03 -0700)
Introduce a complete_report_info() function that fills in the
first_bad_addr field of kasan_report_info instead of doing it in
kasan_report_*().

This function will be extended in the next patch.

Link: https://lkml.kernel.org/r/8eb1a9bd01f5d31eab4524da54a101b8720b469e.1662411799.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Reviewed-by: Marco Elver <elver@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Evgenii Stepanov <eugenis@google.com>
Cc: Peter Collingbourne <pcc@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/kasan/kasan.h
mm/kasan/report.c

index 4fddfdb08abf1f12307b200889f0d2d6ad0d0a75..7e07115873d3ba46c362660f3b5cf6cede45a737 100644 (file)
@@ -153,12 +153,15 @@ enum kasan_report_type {
 };
 
 struct kasan_report_info {
+       /* Filled in by kasan_report_*(). */
        enum kasan_report_type type;
        void *access_addr;
-       void *first_bad_addr;
        size_t access_size;
        bool is_write;
        unsigned long ip;
+
+       /* Filled in by the common reporting code. */
+       void *first_bad_addr;
 };
 
 /* Do not change the struct layout: compiler ABI. */
index dc38ada86f85db578b7217b6ac67627b56de597d..0c2e7a58095d9d30cc27f2db4384100af4df3c73 100644 (file)
@@ -413,6 +413,17 @@ static void print_report(struct kasan_report_info *info)
        }
 }
 
+static void complete_report_info(struct kasan_report_info *info)
+{
+       void *addr = kasan_reset_tag(info->access_addr);
+
+       if (info->type == KASAN_REPORT_ACCESS)
+               info->first_bad_addr = kasan_find_first_bad_addr(
+                                       info->access_addr, info->access_size);
+       else
+               info->first_bad_addr = addr;
+}
+
 void kasan_report_invalid_free(void *ptr, unsigned long ip, enum kasan_report_type type)
 {
        unsigned long flags;
@@ -430,11 +441,12 @@ void kasan_report_invalid_free(void *ptr, unsigned long ip, enum kasan_report_ty
 
        info.type = type;
        info.access_addr = ptr;
-       info.first_bad_addr = kasan_reset_tag(ptr);
        info.access_size = 0;
        info.is_write = false;
        info.ip = ip;
 
+       complete_report_info(&info);
+
        print_report(&info);
 
        end_report(&flags, ptr);
@@ -463,11 +475,12 @@ bool kasan_report(unsigned long addr, size_t size, bool is_write,
 
        info.type = KASAN_REPORT_ACCESS;
        info.access_addr = ptr;
-       info.first_bad_addr = kasan_find_first_bad_addr(ptr, size);
        info.access_size = size;
        info.is_write = is_write;
        info.ip = ip;
 
+       complete_report_info(&info);
+
        print_report(&info);
 
        end_report(&irq_flags, ptr);