kasan: simplify kasan_find_first_bad_addr call sites
authorAndrey Konovalov <andreyknvl@google.com>
Fri, 25 Mar 2022 01:12:46 +0000 (18:12 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 25 Mar 2022 02:06:49 +0000 (19:06 -0700)
Move the addr_has_metadata() check into kasan_find_first_bad_addr().

Link: https://lkml.kernel.org/r/a49576f7a23283d786ba61579cb0c5057e8f0b9b.1646237226.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Marco Elver <elver@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/kasan/report.c
mm/kasan/report_generic.c
mm/kasan/report_hw_tags.c
mm/kasan/report_sw_tags.c

index bb4c29b439b1cd88d14cab22c3b6f723a4bb73b5..a0d4a9d3f93337adf1c244e05ad8dc7b0c7f446e 100644 (file)
@@ -444,10 +444,7 @@ static void __kasan_report(void *addr, size_t size, bool is_write,
        start_report(&flags, true);
 
        info.access_addr = addr;
-       if (addr_has_metadata(addr))
-               info.first_bad_addr = kasan_find_first_bad_addr(addr, size);
-       else
-               info.first_bad_addr = addr;
+       info.first_bad_addr = kasan_find_first_bad_addr(addr, size);
        info.access_size = size;
        info.is_write = is_write;
        info.ip = ip;
index 7e03cca569a7ebf3a61860e12ac7c069d072792f..182239ca184cdb5cd939aae02e455acd044c0b38 100644 (file)
@@ -34,8 +34,12 @@ void *kasan_find_first_bad_addr(void *addr, size_t size)
 {
        void *p = addr;
 
+       if (!addr_has_metadata(p))
+               return p;
+
        while (p < addr + size && !(*(u8 *)kasan_mem_to_shadow(p)))
                p += KASAN_GRANULE_SIZE;
+
        return p;
 }
 
index 5dbbbb930e7a7a9fd5dda6999833a32cfcdb4be7..f3d3be614e4b084eef9cda4cc57d35d18775b4e2 100644 (file)
@@ -17,6 +17,7 @@
 
 void *kasan_find_first_bad_addr(void *addr, size_t size)
 {
+       /* Return the same value regardless of whether addr_has_metadata(). */
        return kasan_reset_tag(addr);
 }
 
index 7271f0988fc0d41fea06fca3668c3ed297ed5424..7a26397297edb133e4aa8a20986d2c924fe40fdb 100644 (file)
@@ -36,8 +36,12 @@ void *kasan_find_first_bad_addr(void *addr, size_t size)
        void *p = kasan_reset_tag(addr);
        void *end = p + size;
 
+       if (!addr_has_metadata(p))
+               return p;
+
        while (p < end && tag == *(u8 *)kasan_mem_to_shadow(p))
                p += KASAN_GRANULE_SIZE;
+
        return p;
 }