Skip to content

Commit 1ed7ce5

Browse files
shakeelbtorvalds
authored andcommitted
slub: fix kmalloc_pagealloc_invalid_free unit test
The unit test kmalloc_pagealloc_invalid_free makes sure that for the higher order slub allocation which goes to page allocator, the free is called with the correct address i.e. the virtual address of the head page. Commit f227f0f ("slub: fix unreclaimable slab stat for bulk free") unified the free code paths for page allocator based slub allocations but instead of using the address passed by the caller, it extracted the address from the page. Thus making the unit test kmalloc_pagealloc_invalid_free moot. So, fix this by using the address passed by the caller. Should we fix this? I think yes because dev expect kasan to catch these type of programming bugs. Link: https://lkml.kernel.org/r/[email protected] Fixes: f227f0f ("slub: fix unreclaimable slab stat for bulk free") Signed-off-by: Shakeel Butt <[email protected]> Reported-by: Nathan Chancellor <[email protected]> Tested-by: Nathan Chancellor <[email protected]> Acked-by: Roman Gushchin <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Muchun Song <[email protected]> Cc: Christoph Lameter <[email protected]> Cc: Pekka Enberg <[email protected]> Cc: David Rientjes <[email protected]> Cc: Joonsoo Kim <[email protected]> Cc: Vlastimil Babka <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 340caf1 commit 1ed7ce5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

mm/slub.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3236,12 +3236,12 @@ struct detached_freelist {
32363236
struct kmem_cache *s;
32373237
};
32383238

3239-
static inline void free_nonslab_page(struct page *page)
3239+
static inline void free_nonslab_page(struct page *page, void *object)
32403240
{
32413241
unsigned int order = compound_order(page);
32423242

32433243
VM_BUG_ON_PAGE(!PageCompound(page), page);
3244-
kfree_hook(page_address(page));
3244+
kfree_hook(object);
32453245
mod_lruvec_page_state(page, NR_SLAB_UNRECLAIMABLE_B, -(PAGE_SIZE << order));
32463246
__free_pages(page, order);
32473247
}
@@ -3282,7 +3282,7 @@ int build_detached_freelist(struct kmem_cache *s, size_t size,
32823282
if (!s) {
32833283
/* Handle kalloc'ed objects */
32843284
if (unlikely(!PageSlab(page))) {
3285-
free_nonslab_page(page);
3285+
free_nonslab_page(page, object);
32863286
p[size] = NULL; /* mark object processed */
32873287
return size;
32883288
}
@@ -4258,7 +4258,7 @@ void kfree(const void *x)
42584258

42594259
page = virt_to_head_page(x);
42604260
if (unlikely(!PageSlab(page))) {
4261-
free_nonslab_page(page);
4261+
free_nonslab_page(page, object);
42624262
return;
42634263
}
42644264
slab_free(page->slab_cache, page, object, NULL, 1, _RET_IP_);

0 commit comments

Comments
 (0)