]> www.infradead.org Git - users/jedix/linux-maple.git/commit
slab: Mark large folios for debugging purposes
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Mon, 3 Mar 2025 17:28:05 +0000 (17:28 +0000)
committerVlastimil Babka <vbabka@suse.cz>
Tue, 4 Mar 2025 07:57:48 +0000 (08:57 +0100)
commita6687c8ff613fc13a71ce1390593ba8d27c52db9
tree4b9ec270e691d5f2e76485eb5294661c3d919eea
parent7e384dbb57e2c3cef7e70d4913b0cc4caedf0a1f
slab: Mark large folios for debugging purposes

If a user calls p = kmalloc(1024); kfree(p); kfree(p); and 'p' was the
only object in the slab, we may free the slab after the first call to
kfree().  If we do, we clear PGTY_slab and the second call to kfree()
will call free_large_kmalloc().  That will leave a trace in the logs
("object pointer: 0x%p"), but otherwise proceed to free the memory,
which is likely to corrupt the page allocator's metadata.

Allocate a new page type for large kmalloc and mark the memory with it
while it's allocated.  That lets us detect this double-free and return
without harming any data structures.

Reported-by: Hannes Reinecke <hare@suse.com>
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
include/linux/page-flags.h
mm/slub.c