Re: [PATCH] tty: add lockdep annotations
From: Eric Dumazet
Date: Sat Jun 02 2012 - 03:55:57 EST
From: Eric Dumazet <edumazet@xxxxxxxxxx>
On Sat, 2012-06-02 at 09:17 +0200, Eric Dumazet wrote:
>
> Here is the patch I am currently testing (need to boot the machine ~50
> times to make sure it is the right fix)
Seems good, but am still doing reboots to make sure.
We should add a debugging code to kref to catch poisoned refcounts...
Something like :
[PATCH] kref: detects poisoned refcounts
Catch kref_get() done on freed memory, if slub/slab are poisoning the
freed area.
Signed-off-by: Eric Dumazet <edumazet@xxxxxxxxxx>
---
include/linux/kref.h | 2 ++
include/linux/poison.h | 3 +++
2 files changed, 5 insertions(+)
diff --git a/include/linux/kref.h b/include/linux/kref.h
index 9c07dce..d8e90a1 100644
--- a/include/linux/kref.h
+++ b/include/linux/kref.h
@@ -18,6 +18,7 @@
#include <linux/bug.h>
#include <linux/atomic.h>
#include <linux/kernel.h>
+#include <linux/poison.h>
struct kref {
atomic_t refcount;
@@ -39,6 +40,7 @@ static inline void kref_init(struct kref *kref)
static inline void kref_get(struct kref *kref)
{
WARN_ON(!atomic_read(&kref->refcount));
+ WARN_ON(atomic_read(&kref->refcount) == POISON_FREE_INT);
atomic_inc(&kref->refcount);
}
diff --git a/include/linux/poison.h b/include/linux/poison.h
index 2110a81..2947582 100644
--- a/include/linux/poison.h
+++ b/include/linux/poison.h
@@ -48,6 +48,9 @@
#define POISON_FREE 0x6b /* for use-after-free poisoning */
#define POISON_END 0xa5 /* end-byte of poisoning */
+#define POISON_FREE_SHORT ((POISON_FREE << 8) + POISON_FREE)
+#define POISON_FREE_INT ((POISON_FREE_SHORT << 16) + POISON_FREE_SHORT)
+
/********** arch/$ARCH/mm/init.c **********/
#define POISON_FREE_INITMEM 0xcc
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/