The patch titled Subject: kasan, slub: move kasan_poison_slab hook before page_address has been added to the -mm tree. Its filename is kasan-slub-move-kasan_poison_slab-hook-before-page_address.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/kasan-slub-move-kasan_poison_slab-hook-before-page_address.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/kasan-slub-move-kasan_poison_slab-hook-before-page_address.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Andrey Konovalov <andreyknvl@xxxxxxxxxx> Subject: kasan, slub: move kasan_poison_slab hook before page_address With tag based KASAN page_address() looks at the page flags to see whether the resulting pointer needs to have a tag set. Since we don't want to set a tag when page_address() is called on SLAB pages, we call page_kasan_tag_reset() in kasan_poison_slab(). However in allocate_slab() page_address() is called before kasan_poison_slab(). Fix it by changing the order. Link: http://lkml.kernel.org/r/cd895d627465a3f1c712647072d17f10883be2a1.1549921721.git.andreyknvl@xxxxxxxxxx Signed-off-by: Andrey Konovalov <andreyknvl@xxxxxxxxxx> Cc: Alexander Potapenko <glider@xxxxxxxxxx> Cc: Andrey Ryabinin <aryabinin@xxxxxxxxxxxxx> Cc: Catalin Marinas <catalin.marinas@xxxxxxx> Cc: Christoph Lameter <cl@xxxxxxxxx> Cc: David Rientjes <rientjes@xxxxxxxxxx> Cc: Dmitry Vyukov <dvyukov@xxxxxxxxxx> Cc: Evgeniy Stepanov <eugenis@xxxxxxxxxx> Cc: Joonsoo Kim <iamjoonsoo.kim@xxxxxxx> Cc: Kostya Serebryany <kcc@xxxxxxxxxx> Cc: Pekka Enberg <penberg@xxxxxxxxxx> Cc: Qian Cai <cai@xxxxxx> Cc: Vincenzo Frascino <vincenzo.frascino@xxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- --- a/mm/slub.c~kasan-slub-move-kasan_poison_slab-hook-before-page_address +++ a/mm/slub.c @@ -1642,12 +1642,15 @@ static struct page *allocate_slab(struct if (page_is_pfmemalloc(page)) SetPageSlabPfmemalloc(page); + kasan_poison_slab(page); + start = page_address(page); - if (unlikely(s->flags & SLAB_POISON)) + if (unlikely(s->flags & SLAB_POISON)) { + metadata_access_enable(); memset(start, POISON_INUSE, PAGE_SIZE << order); - - kasan_poison_slab(page); + metadata_access_disable(); + } shuffle = shuffle_freelist(s, page); _ Patches currently in -mm which might be from andreyknvl@xxxxxxxxxx are kasan-fix-assigning-tags-twice.patch kasan-kmemleak-pass-tagged-pointers-to-kmemleak.patch kmemleak-account-for-tagged-pointers-when-calculating-pointer-range.patch kasan-slub-move-kasan_poison_slab-hook-before-page_address.patch kasan-slub-fix-conflicts-with-config_slab_freelist_hardened.patch