diff options
author | Pekka Enberg <penberg@cs.helsinki.fi> | 2006-06-23 05:03:24 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-06-23 10:42:49 -0400 |
commit | 58ce1fd5805647a58a050bbbbd2252ea5ecb47b3 (patch) | |
tree | 639aa44f21d0176c771b8b6e76d9c7ce9e2d1d19 | |
parent | b344e05c585406904c70865e531e02467c4c7931 (diff) |
[PATCH] slab: redzone double-free detection
At present our slab debugging tells us that it detected a double-free or
corruption - it does not distinguish between them. Sometimes it's useful
to be able to differentiate between these two types of information.
Add double-free detection to redzone verification when freeing an object.
As explained by Manfred, when we are freeing an object, both redzones
should be RED_ACTIVE. However, if both are RED_INACTIVE, we are trying to
free an object that was already free'd.
Signed-off-by: Manfred Spraul <manfred@colorfullife.com>
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r-- | mm/slab.c | 32 |
1 files changed, 23 insertions, 9 deletions
@@ -2636,6 +2636,28 @@ static void kfree_debugcheck(const void *objp) | |||
2636 | } | 2636 | } |
2637 | } | 2637 | } |
2638 | 2638 | ||
2639 | static inline void verify_redzone_free(struct kmem_cache *cache, void *obj) | ||
2640 | { | ||
2641 | unsigned long redzone1, redzone2; | ||
2642 | |||
2643 | redzone1 = *dbg_redzone1(cache, obj); | ||
2644 | redzone2 = *dbg_redzone2(cache, obj); | ||
2645 | |||
2646 | /* | ||
2647 | * Redzone is ok. | ||
2648 | */ | ||
2649 | if (redzone1 == RED_ACTIVE && redzone2 == RED_ACTIVE) | ||
2650 | return; | ||
2651 | |||
2652 | if (redzone1 == RED_INACTIVE && redzone2 == RED_INACTIVE) | ||
2653 | slab_error(cache, "double free detected"); | ||
2654 | else | ||
2655 | slab_error(cache, "memory outside object was overwritten"); | ||
2656 | |||
2657 | printk(KERN_ERR "%p: redzone 1:0x%lx, redzone 2:0x%lx.\n", | ||
2658 | obj, redzone1, redzone2); | ||
2659 | } | ||
2660 | |||
2639 | static void *cache_free_debugcheck(struct kmem_cache *cachep, void *objp, | 2661 | static void *cache_free_debugcheck(struct kmem_cache *cachep, void *objp, |
2640 | void *caller) | 2662 | void *caller) |
2641 | { | 2663 | { |
@@ -2659,15 +2681,7 @@ static void *cache_free_debugcheck(struct kmem_cache *cachep, void *objp, | |||
2659 | slabp = page_get_slab(page); | 2681 | slabp = page_get_slab(page); |
2660 | 2682 | ||
2661 | if (cachep->flags & SLAB_RED_ZONE) { | 2683 | if (cachep->flags & SLAB_RED_ZONE) { |
2662 | if (*dbg_redzone1(cachep, objp) != RED_ACTIVE || | 2684 | verify_redzone_free(cachep, objp); |
2663 | *dbg_redzone2(cachep, objp) != RED_ACTIVE) { | ||
2664 | slab_error(cachep, "double free, or memory outside" | ||
2665 | " object was overwritten"); | ||
2666 | printk(KERN_ERR "%p: redzone 1:0x%lx, " | ||
2667 | "redzone 2:0x%lx.\n", | ||
2668 | objp, *dbg_redzone1(cachep, objp), | ||
2669 | *dbg_redzone2(cachep, objp)); | ||
2670 | } | ||
2671 | *dbg_redzone1(cachep, objp) = RED_INACTIVE; | 2685 | *dbg_redzone1(cachep, objp) = RED_INACTIVE; |
2672 | *dbg_redzone2(cachep, objp) = RED_INACTIVE; | 2686 | *dbg_redzone2(cachep, objp) = RED_INACTIVE; |
2673 | } | 2687 | } |