Skip to content

Commit a710122

Browse files
xairytorvalds
authored andcommitted
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. [andreyknvl@google.com: fix compilation error when CONFIG_SLUB_DEBUG=n] Link: http://lkml.kernel.org/r/ac27cc0bbaeb414ed77bcd6671a877cf3546d56e.1550066133.git.andreyknvl@google.com Link: http://lkml.kernel.org/r/cd895d627465a3f1c712647072d17f10883be2a1.1549921721.git.andreyknvl@google.com Signed-off-by: Andrey Konovalov <andreyknvl@google.com> Cc: Alexander Potapenko <glider@google.com> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Christoph Lameter <cl@linux.com> Cc: David Rientjes <rientjes@google.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Evgeniy Stepanov <eugenis@google.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: Kostya Serebryany <kcc@google.com> Cc: Pekka Enberg <penberg@kernel.org> Cc: Qian Cai <cai@lca.pw> Cc: Vincenzo Frascino <vincenzo.frascino@arm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent a2f7757 commit a710122

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

mm/slub.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,16 @@ static void setup_object_debug(struct kmem_cache *s, struct page *page,
10751075
init_tracking(s, object);
10761076
}
10771077

1078+
static void setup_page_debug(struct kmem_cache *s, void *addr, int order)
1079+
{
1080+
if (!(s->flags & SLAB_POISON))
1081+
return;
1082+
1083+
metadata_access_enable();
1084+
memset(addr, POISON_INUSE, PAGE_SIZE << order);
1085+
metadata_access_disable();
1086+
}
1087+
10781088
static inline int alloc_consistency_checks(struct kmem_cache *s,
10791089
struct page *page,
10801090
void *object, unsigned long addr)
@@ -1330,6 +1340,8 @@ slab_flags_t kmem_cache_flags(unsigned int object_size,
13301340
#else /* !CONFIG_SLUB_DEBUG */
13311341
static inline void setup_object_debug(struct kmem_cache *s,
13321342
struct page *page, void *object) {}
1343+
static inline void setup_page_debug(struct kmem_cache *s,
1344+
void *addr, int order) {}
13331345

13341346
static inline int alloc_debug_processing(struct kmem_cache *s,
13351347
struct page *page, void *object, unsigned long addr) { return 0; }
@@ -1643,12 +1655,11 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
16431655
if (page_is_pfmemalloc(page))
16441656
SetPageSlabPfmemalloc(page);
16451657

1646-
start = page_address(page);
1658+
kasan_poison_slab(page);
16471659

1648-
if (unlikely(s->flags & SLAB_POISON))
1649-
memset(start, POISON_INUSE, PAGE_SIZE << order);
1660+
start = page_address(page);
16501661

1651-
kasan_poison_slab(page);
1662+
setup_page_debug(s, start, order);
16521663

16531664
shuffle = shuffle_freelist(s, page);
16541665

0 commit comments

Comments
 (0)