linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kref: Avoid null pointer dereference after WARN
@ 2017-06-27  3:52 Kees Cook
  2017-06-27  7:06 ` Greg Kroah-Hartman
  2017-06-28 11:57 ` Greg Kroah-Hartman
  0 siblings, 2 replies; 10+ messages in thread
From: Kees Cook @ 2017-06-27  3:52 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Ingo Molnar, Peter Zijlstra, Jason A. Donenfeld,
	Thomas Hellstrom, Andi Kleen, Daniel Micay, linux-kernel

From: Daniel Micay <danielmicay@gmail.com>

The WARN_ON() checking for a NULL release pointer should be a BUG()
since continuing with a NULL release pointer will lead to a NULL
pointer dereference anyway.

The kref_put() case is extracted from PaX, and Kees Cook noted it should
be extended to the other two cases.

Signed-off-by: Daniel Micay <danielmicay@gmail.com>
[kees: clarify commit log]
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 include/linux/kref.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/kref.h b/include/linux/kref.h
index f4156f88f557..82a2c225eae3 100644
--- a/include/linux/kref.h
+++ b/include/linux/kref.h
@@ -66,7 +66,7 @@ static inline void kref_get(struct kref *kref)
  */
 static inline int kref_put(struct kref *kref, void (*release)(struct kref *kref))
 {
-	WARN_ON(release == NULL);
+	BUG_ON(release == NULL);
 
 	if (refcount_dec_and_test(&kref->refcount)) {
 		release(kref);
@@ -79,7 +79,7 @@ static inline int kref_put_mutex(struct kref *kref,
 				 void (*release)(struct kref *kref),
 				 struct mutex *lock)
 {
-	WARN_ON(release == NULL);
+	BUG_ON(release == NULL);
 
 	if (refcount_dec_and_mutex_lock(&kref->refcount, lock)) {
 		release(kref);
@@ -92,7 +92,7 @@ static inline int kref_put_lock(struct kref *kref,
 				void (*release)(struct kref *kref),
 				spinlock_t *lock)
 {
-	WARN_ON(release == NULL);
+	BUG_ON(release == NULL);
 
 	if (refcount_dec_and_lock(&kref->refcount, lock)) {
 		release(kref);

-- 
Kees Cook
Pixel Security

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-07-05 15:37 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-27  3:52 [PATCH] kref: Avoid null pointer dereference after WARN Kees Cook
2017-06-27  7:06 ` Greg Kroah-Hartman
2017-06-27 11:00   ` Jason A. Donenfeld
2017-06-27 14:49     ` Andi Kleen
2017-06-27 19:11       ` Jason A. Donenfeld
2017-06-27 19:29         ` Andi Kleen
2017-06-28 11:26           ` Michal Hocko
2017-06-27 18:34   ` Kees Cook
2017-07-05 15:37   ` Peter Zijlstra
2017-06-28 11:57 ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).