Skip to content

Commit

Permalink
slub: Bug on free of non-slab objects
Browse files Browse the repository at this point in the history
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 <levente@leventepolyak.net>
Signed-off-by: Thibaut Sautereau <thibaut.sautereau@ssi.gouv.fr>
  • Loading branch information
tsautereau-anssi authored and anthraxx committed Mar 6, 2024
1 parent 0b86eb7 commit 0e1f4db
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mm/slab_common.c
Expand Up @@ -920,8 +920,12 @@ void free_large_kmalloc(struct folio *folio, void *object)
{
unsigned int order = folio_order(folio);

#ifdef CONFIG_BUG_ON_DATA_CORRUPTION
BUG_ON(order == 0);
#else
if (WARN_ON_ONCE(order == 0))
pr_warn_once("object pointer: 0x%p\n", object);
#endif

kmemleak_free(object);
kasan_kfree_large(object);
Expand Down

0 comments on commit 0e1f4db

Please sign in to comment.