Skip to content

Commit f9d79e8

Browse files
xairytorvalds
authored andcommitted
kasan, mm: fix crash with HW_TAGS and DEBUG_PAGEALLOC
Currently, kasan_free_nondeferred_pages()->kasan_free_pages() is called after debug_pagealloc_unmap_pages(). This causes a crash when debug_pagealloc is enabled, as HW_TAGS KASAN can't set tags on an unmapped page. This patch puts kasan_free_nondeferred_pages() before debug_pagealloc_unmap_pages() and arch_free_page(), which can also make the page unavailable. Link: https://lkml.kernel.org/r/24cd7db274090f0e5bc3adcdc7399243668e3171.1614987311.git.andreyknvl@google.com Fixes: 94ab5b6 ("kasan, arm64: enable CONFIG_KASAN_HW_TAGS") Signed-off-by: Andrey Konovalov <andreyknvl@google.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Will Deacon <will.deacon@arm.com> Cc: Vincenzo Frascino <vincenzo.frascino@arm.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com> Cc: Alexander Potapenko <glider@google.com> Cc: Marco Elver <elver@google.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> Cc: Christoph Hellwig <hch@infradead.org> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 96cfe2c commit f9d79e8

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

mm/page_alloc.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,12 @@ static __always_inline bool free_pages_prepare(struct page *page,
12811281

12821282
kernel_poison_pages(page, 1 << order);
12831283

1284+
/*
1285+
* With hardware tag-based KASAN, memory tags must be set before the
1286+
* page becomes unavailable via debug_pagealloc or arch_free_page.
1287+
*/
1288+
kasan_free_nondeferred_pages(page, order);
1289+
12841290
/*
12851291
* arch_free_page() can make the page's contents inaccessible. s390
12861292
* does this. So nothing which can access the page's contents should
@@ -1290,8 +1296,6 @@ static __always_inline bool free_pages_prepare(struct page *page,
12901296

12911297
debug_pagealloc_unmap_pages(page, 1 << order);
12921298

1293-
kasan_free_nondeferred_pages(page, order);
1294-
12951299
return true;
12961300
}
12971301

0 commit comments

Comments
 (0)