kasan: simplify kasan_find_first_bad_addr call sites

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>
This commit is contained in:
Andrey Konovalov 2022-03-24 18:12:46 -07:00 committed by Linus Torvalds
parent 9d7b7dd946
commit b91328002d
4 changed files with 10 additions and 4 deletions

View File

@ -444,10 +444,7 @@ static void __kasan_report(void *addr, size_t size, bool is_write,
start_report(&flags, true); start_report(&flags, true);
info.access_addr = addr; info.access_addr = addr;
if (addr_has_metadata(addr)) info.first_bad_addr = kasan_find_first_bad_addr(addr, size);
info.first_bad_addr = kasan_find_first_bad_addr(addr, size);
else
info.first_bad_addr = addr;
info.access_size = size; info.access_size = size;
info.is_write = is_write; info.is_write = is_write;
info.ip = ip; info.ip = ip;

View File

@ -34,8 +34,12 @@ void *kasan_find_first_bad_addr(void *addr, size_t size)
{ {
void *p = addr; void *p = addr;
if (!addr_has_metadata(p))
return p;
while (p < addr + size && !(*(u8 *)kasan_mem_to_shadow(p))) while (p < addr + size && !(*(u8 *)kasan_mem_to_shadow(p)))
p += KASAN_GRANULE_SIZE; p += KASAN_GRANULE_SIZE;
return p; return p;
} }

View File

@ -17,6 +17,7 @@
void *kasan_find_first_bad_addr(void *addr, size_t size) 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); return kasan_reset_tag(addr);
} }

View File

@ -36,8 +36,12 @@ void *kasan_find_first_bad_addr(void *addr, size_t size)
void *p = kasan_reset_tag(addr); void *p = kasan_reset_tag(addr);
void *end = p + size; void *end = p + size;
if (!addr_has_metadata(p))
return p;
while (p < end && tag == *(u8 *)kasan_mem_to_shadow(p)) while (p < end && tag == *(u8 *)kasan_mem_to_shadow(p))
p += KASAN_GRANULE_SIZE; p += KASAN_GRANULE_SIZE;
return p; return p;
} }