Skip to content

Commit c1b5cc2

Browse files
tsautereau-anssianthraxx
authored andcommitted
slub: Bug on free of non-slab objects
Before commit d0fe47c ("slub: add back check for free nonslab objects"), freeing a non-slab object used to trigger a BUG if CONFIG_DEBUG_VM was enabled. Now it only warns, which I think is not enough for such a memory corruption. Let's restore the previous behaviour, but tie it to CONFIG_BUG_ON_DATA_CORRUPTION as suggested by Levente. After page folios were introduced in v5.17, this patch was adapted to trigger a bug when the order of the folio is zero instead of when the page is not a compound page, which is not equivalent but respects the semantics of the conversion to page folios and follows the change made to the WARN_ON_ONCE beneath. Suggested-by: Levente Polyak <[email protected]> Signed-off-by: Thibaut Sautereau <[email protected]>
1 parent 52b72d2 commit c1b5cc2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

mm/slab_common.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,8 +901,12 @@ void free_large_kmalloc(struct folio *folio, void *object)
901901
{
902902
unsigned int order = folio_order(folio);
903903

904+
#ifdef CONFIG_BUG_ON_DATA_CORRUPTION
905+
BUG_ON(order == 0);
906+
#else
904907
if (WARN_ON_ONCE(order == 0))
905908
pr_warn_once("object pointer: 0x%p\n", object);
909+
#endif
906910

907911
kmemleak_free(object);
908912
kasan_kfree_large(object);

0 commit comments

Comments
 (0)