• Feng Tang's avatar
    mm/slub, kunit: Add a test case for kmalloc redzone check · 6cd6d33c
    Feng Tang authored
    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 120ee599 ("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: default avatarVlastimil Babka <vbabka@suse.cz>
    Signed-off-by: default avatarFeng Tang <feng.tang@intel.com>
    Reviewed-by: default avatarHyeonggon Yoo <42.hyeyoo@gmail.com>
    Signed-off-by: default avatarVlastimil Babka <vbabka@suse.cz>
    6cd6d33c
slab.h 23.5 KB