Skip to content

Commit

Permalink
slub: fix SLUB_RESILIENCY_TEST for dynamic kmalloc caches
Browse files Browse the repository at this point in the history
Now that the kmalloc_caches array is dynamically allocated at boot,
SLUB_RESILIENCY_TEST needs to be fixed to pass the correct type.

Acked-by: Christoph Lameter <cl@linux.com>
Signed-off-by: David Rientjes <rientjes@google.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
  • Loading branch information
David Rientjes authored and Pekka Enberg committed Oct 2, 2010
1 parent 8de66a0 commit a016471
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions mm/slub.c
Original file line number Diff line number Diff line change
Expand Up @@ -3498,6 +3498,8 @@ static void resiliency_test(void)
{
u8 *p;

BUILD_BUG_ON(KMALLOC_MIN_SIZE > 16 || SLUB_PAGE_SHIFT < 10);

printk(KERN_ERR "SLUB resiliency testing\n");
printk(KERN_ERR "-----------------------\n");
printk(KERN_ERR "A. Corruption after allocation\n");
Expand All @@ -3507,7 +3509,7 @@ static void resiliency_test(void)
printk(KERN_ERR "\n1. kmalloc-16: Clobber Redzone/next pointer"
" 0x12->0x%p\n\n", p + 16);

validate_slab_cache(kmalloc_caches + 4);
validate_slab_cache(kmalloc_caches[4]);

/* Hmmm... The next two are dangerous */
p = kzalloc(32, GFP_KERNEL);
Expand All @@ -3517,35 +3519,35 @@ static void resiliency_test(void)
printk(KERN_ERR
"If allocated object is overwritten then not detectable\n\n");

validate_slab_cache(kmalloc_caches + 5);
validate_slab_cache(kmalloc_caches[5]);
p = kzalloc(64, GFP_KERNEL);
p += 64 + (get_cycles() & 0xff) * sizeof(void *);
*p = 0x56;
printk(KERN_ERR "\n3. kmalloc-64: corrupting random byte 0x56->0x%p\n",
p);
printk(KERN_ERR
"If allocated object is overwritten then not detectable\n\n");
validate_slab_cache(kmalloc_caches + 6);
validate_slab_cache(kmalloc_caches[6]);

printk(KERN_ERR "\nB. Corruption after free\n");
p = kzalloc(128, GFP_KERNEL);
kfree(p);
*p = 0x78;
printk(KERN_ERR "1. kmalloc-128: Clobber first word 0x78->0x%p\n\n", p);
validate_slab_cache(kmalloc_caches + 7);
validate_slab_cache(kmalloc_caches[7]);

p = kzalloc(256, GFP_KERNEL);
kfree(p);
p[50] = 0x9a;
printk(KERN_ERR "\n2. kmalloc-256: Clobber 50th byte 0x9a->0x%p\n\n",
p);
validate_slab_cache(kmalloc_caches + 8);
validate_slab_cache(kmalloc_caches[8]);

p = kzalloc(512, GFP_KERNEL);
kfree(p);
p[512] = 0xab;
printk(KERN_ERR "\n3. kmalloc-512: Clobber redzone 0xab->0x%p\n\n", p);
validate_slab_cache(kmalloc_caches + 9);
validate_slab_cache(kmalloc_caches[9]);
}
#else
static void resiliency_test(void) {};
Expand Down

0 comments on commit a016471

Please sign in to comment.