public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] futex: check for NULL keys in match_futex
@ 2009-10-14 17:12 Darren Hart
  2009-10-14 20:11 ` [tip:core/urgent] futex: Check " tip-bot for Darren Hart
  0 siblings, 1 reply; 2+ messages in thread
From: Darren Hart @ 2009-10-14 17:12 UTC (permalink / raw)
  To: lkml, 
  Cc: Thomas Gleixner, Peter Zijlstra, Ingo Molnar, Eric Dumazet,
	Dinakar Guniguntala, John Stultz

From: Darren Hart <dvhltc@us.ibm.com>

If userspace tries to perform a requeue_pi on a non-requeue_pi waiter, it
will find the futex_q->requeue_pi_key to be NULL and OOPS.  Check for NULL
in match_futex().  This results in cleaner code than checking at each call
site.  While match_futex(NULL, NULL) returning false is a little odd, it
will OOPS as it is today.  This approach catches all possible call sites
as well.

Signed-off-by: Darren Hart <dvhltc@us.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@elte.hu>
CC: Eric Dumazet <eric.dumazet@gmail.com>
CC: Dinakar Guniguntala <dino@in.ibm.com>
CC: John Stultz <johnstul@us.ibm.com>
---

 kernel/futex.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/kernel/futex.c b/kernel/futex.c
index 4949d33..5971730 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -150,7 +150,8 @@ static struct futex_hash_bucket *hash_futex(union futex_key *key)
  */
 static inline int match_futex(union futex_key *key1, union futex_key *key2)
 {
-	return (key1->both.word == key2->both.word
+	return (key1 && key2
+		&& key1->both.word == key2->both.word
 		&& key1->both.ptr == key2->both.ptr
 		&& key1->both.offset == key2->both.offset);
 }
-- 
Darren Hart
IBM Linux Technology Center
Real-Time Linux Team

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

* [tip:core/urgent] futex: Check for NULL keys in match_futex
  2009-10-14 17:12 [PATCH] futex: check for NULL keys in match_futex Darren Hart
@ 2009-10-14 20:11 ` tip-bot for Darren Hart
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot for Darren Hart @ 2009-10-14 20:11 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, dvhltc, hpa, mingo, eric.dumazet, johnstul, peterz,
	dino, tglx, mingo

Commit-ID:  2bc872036e1c5948b5b02942810bbdd8dbdb9812
Gitweb:     http://git.kernel.org/tip/2bc872036e1c5948b5b02942810bbdd8dbdb9812
Author:     Darren Hart <dvhltc@us.ibm.com>
AuthorDate: Wed, 14 Oct 2009 10:12:39 -0700
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 14 Oct 2009 22:00:14 +0200

futex: Check for NULL keys in match_futex

If userspace tries to perform a requeue_pi on a non-requeue_pi waiter,
it will find the futex_q->requeue_pi_key to be NULL and OOPS.

Check for NULL in match_futex() instead of doing explicit NULL pointer
checks on all call sites.  While match_futex(NULL, NULL) returning
false is a little odd, it's still correct as we expect valid key
references.

Signed-off-by: Darren Hart <dvhltc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@elte.hu>
CC: Eric Dumazet <eric.dumazet@gmail.com>
CC: Dinakar Guniguntala <dino@in.ibm.com>
CC: John Stultz <johnstul@us.ibm.com>
Cc: stable@kernel.org
LKML-Reference: <4AD60687.10306@us.ibm.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 kernel/futex.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/kernel/futex.c b/kernel/futex.c
index 5c88839..06938e5 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -150,7 +150,8 @@ static struct futex_hash_bucket *hash_futex(union futex_key *key)
  */
 static inline int match_futex(union futex_key *key1, union futex_key *key2)
 {
-	return (key1->both.word == key2->both.word
+	return (key1 && key2
+		&& key1->both.word == key2->both.word
 		&& key1->both.ptr == key2->both.ptr
 		&& key1->both.offset == key2->both.offset);
 }

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

end of thread, other threads:[~2009-10-14 20:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-14 17:12 [PATCH] futex: check for NULL keys in match_futex Darren Hart
2009-10-14 20:11 ` [tip:core/urgent] futex: Check " tip-bot for Darren Hart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox