Skip to content

Commit acb35b1

Browse files
xairytorvalds
authored andcommitted
kasan, mm: fix resetting page_alloc tags for HW_TAGS
A previous commit added resetting KASAN page tags to kernel_init_free_pages() to avoid false-positives due to accesses to metadata with the hardware tag-based mode. That commit did reset page tags before the metadata access, but didn't restore them after. As the result, KASAN fails to detect bad accesses to page_alloc allocations on some configurations. Fix this by recovering the tag after the metadata access. Link: https://lkml.kernel.org/r/02b5bcd692e912c27d484030f666b350ad7e4ae4.1611074450.git.andreyknvl@google.com Fixes: aa1ef4d ("kasan, mm: reset tags when accessing metadata") Signed-off-by: Andrey Konovalov <andreyknvl@google.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Alexander Potapenko <glider@google.com> Cc: Marco Elver <elver@google.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Will Deacon <will.deacon@arm.com> Cc: Vincenzo Frascino <vincenzo.frascino@arm.com> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com> Cc: Peter Collingbourne <pcc@google.com> Cc: Evgenii Stepanov <eugenis@google.com> Cc: Branislav Rankov <Branislav.Rankov@arm.com> Cc: Kevin Brodsky <kevin.brodsky@arm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent ce5716c commit acb35b1

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

mm/page_alloc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,8 +1207,10 @@ static void kernel_init_free_pages(struct page *page, int numpages)
12071207
/* s390's use of memset() could override KASAN redzones. */
12081208
kasan_disable_current();
12091209
for (i = 0; i < numpages; i++) {
1210+
u8 tag = page_kasan_tag(page + i);
12101211
page_kasan_tag_reset(page + i);
12111212
clear_highpage(page + i);
1213+
page_kasan_tag_set(page + i, tag);
12121214
}
12131215
kasan_enable_current();
12141216
}

0 commit comments

Comments
 (0)