Skip to content
/ linux Public
forked from torvalds/linux

Commit

Permalink
kasan: simplify kasan_find_first_bad_addr call sites
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Alexander Potapenko <[email protected]>
Cc: Andrey Ryabinin <[email protected]>
Cc: Dmitry Vyukov <[email protected]>
Cc: Marco Elver <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
xairy authored and torvalds committed Mar 25, 2022
1 parent 9d7b7dd commit b913280
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
5 changes: 1 addition & 4 deletions mm/kasan/report.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions mm/kasan/report_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions mm/kasan/report_hw_tags.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 4 additions & 0 deletions mm/kasan/report_sw_tags.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit b913280

Please sign in to comment.