diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 6fc72730f92d..bdb6a557f69c 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1284,6 +1284,12 @@ static __always_inline bool free_pages_prepare(struct page *page, kernel_init_free_pages(page, 1 << order); kernel_poison_pages(page, 1 << order, 0); + /* + * With hardware tag-based KASAN, memory tags must be set before the + * page becomes unavailable via debug_pagealloc or arch_free_page. + */ + kasan_free_nondeferred_pages(page, order); + /* * arch_free_page() can make the page's contents inaccessible. s390 * does this. So nothing which can access the page's contents should @@ -1294,8 +1300,6 @@ static __always_inline bool free_pages_prepare(struct page *page, if (debug_pagealloc_enabled_static()) kernel_map_pages(page, 1 << order, 0); - kasan_free_nondeferred_pages(page, order); - return true; }