From 7f998e63df7d6579220d4244da685d3d9cd176d8 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Thu, 12 Aug 2010 21:48:45 -0700 Subject: [PATCH] kernel - Add sysref assertions * Add more checks in the sysref code to detect use-after-free situations. --- sys/sys/sysref2.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sys/sys/sysref2.h b/sys/sys/sysref2.h index ce9bf0871a..1e765cf1b5 100644 --- a/sys/sys/sysref2.h +++ b/sys/sys/sysref2.h @@ -67,6 +67,7 @@ static __inline void sysref_get(struct sysref *sr) { + KKASSERT((sr->flags & SRF_PUTAWAY) == 0); atomic_add_int(&sr->refcnt, 1); } @@ -81,6 +82,7 @@ sysref_put(struct sysref *sr) { int count = sr->refcnt; + KKASSERT((sr->flags & SRF_PUTAWAY) == 0); if (count <= 1 || atomic_cmpset_int(&sr->refcnt, count, count - 1) == 0) _sysref_put(sr); } -- 2.41.0