Skip to contentSkip to conversation

net: print proper warning on dst underflow

PATCH Applied Jason A. Donenfeld 3 participants 3 messages Sep 24, 2019 – Nov 14, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: print proper warning on dst underflow

Proper warnings with stack traces make it much easier to figure out what's doing the double free and create more meaningful bug reports from users.

---
 net/core/dst.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/dst.c +2 -2
index 1325316d9eab..193af526e908 100644
@@ -172,7 +172,7 @@ void dst_release(struct dst_entry *dst)
 		int newrefcnt;
 
 		newrefcnt = atomic_dec_return(&dst->__refcnt);
-		if (unlikely(newrefcnt < 0))
+		if (WARN_ONCE(newrefcnt < 0, "dst_release underflow"))
 			net_warn_ratelimited("%s: dst:%p refcnt:%d\n",
 					     __func__, dst, newrefcnt);
 		if (!newrefcnt)
@@ -187,7 +187,7 @@ void dst_release_immediate(struct dst_entry *dst)
 		int newrefcnt;
 
 		newrefcnt = atomic_dec_return(&dst->__refcnt);
-		if (unlikely(newrefcnt < 0))
+		if (WARN_ONCE(newrefcnt < 0, "dst_release_immediate underflow"))
 			net_warn_ratelimited("%s: dst:%p refcnt:%d\n",
 					     __func__, dst, newrefcnt);
 		if (!newrefcnt)
Signature · 1 line
2.21.0
#2 lore raw
In reply to Jason A. Donenfeld
Quoted 14 lines · Jason A. Donenfeld

Proper warnings with stack traces make it much easier to figure out what's doing the double free and create more meaningful bug reports from users.

---
 net/core/dst.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/dst.c +0 -0
index 1325316d9eab..193af526e908 100644

net/core/dst.c void dst_release(struct dst_entry *dst) · line 177

Quoted 7 lines
net/core/dst.c +1 -1
@@ -172,7 +172,7 @@ void dst_release(struct dst_entry *dst)
 		int newrefcnt;
 
 		newrefcnt = atomic_dec_return(&dst->__refcnt);
-		if (unlikely(newrefcnt < 0))
+		if (WARN_ONCE(newrefcnt < 0, "dst_release underflow"))
 			net_warn_ratelimited("%s: dst:%p refcnt:%d\n",
 					     __func__, dst, newrefcnt);

Should __refcnt be a refcount_t to gain saturation protection? It seems like going negative is bad...

-Kees

Quoted 13 lines
net/core/dst.c +1 -1
 		if (!newrefcnt)
@@ -187,7 +187,7 @@ void dst_release_immediate(struct dst_entry *dst)
 		int newrefcnt;
 
 		newrefcnt = atomic_dec_return(&dst->__refcnt);
-		if (unlikely(newrefcnt < 0))
+		if (WARN_ONCE(newrefcnt < 0, "dst_release_immediate underflow"))
 			net_warn_ratelimited("%s: dst:%p refcnt:%d\n",
 					     __func__, dst, newrefcnt);
 		if (!newrefcnt)
Signature · 1 line
2.21.0
Signature · 1 line
Kees Cook