mm/slub, kunit: Add a test case for kmalloc redzone check
authorFeng Tang <feng.tang@intel.com>
Wed, 30 Nov 2022 08:54:51 +0000 (16:54 +0800)
committerVlastimil Babka <vbabka@suse.cz>
Wed, 30 Nov 2022 23:06:45 +0000 (00:06 +0100)
commit6cd6d33ca41ff4af21bc25c331ab34b50b4a9c8c
tree190a4544f6be91cbf4647162b652b5b0b05a883b
parent4d9dd4b0ce88072ca2368dfdd5c92bc078366e1e
mm/slub, kunit: Add a test case for kmalloc redzone check

kmalloc redzone check for slub has been merged, and it's better to add
a kunit case for it, which is inspired by a real-world case as described
in commit 120ee599b5bf ("staging: octeon-usb: prevent memory corruption"):

"
  octeon-hcd will crash the kernel when SLOB is used. This usually happens
  after the 18-byte control transfer when a device descriptor is read.
  The DMA engine is always transferring full 32-bit words and if the
  transfer is shorter, some random garbage appears after the buffer.
  The problem is not visible with SLUB since it rounds up the allocations
  to word boundary, and the extra bytes will go undetected.
"

To avoid interrupting the normal functioning of kmalloc caches, a
kmem_cache mimicing kmalloc cache is created with similar flags, and
kmalloc_trace() is used to really test the orig_size and redzone setup.

Suggested-by: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Feng Tang <feng.tang@intel.com>
Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
lib/slub_kunit.c
mm/slab.h