Skip to contentSkip to conversation

futex: check for NULL keys in match_futex

PATCH In review Darren Hart 1 participant 2 messages Oct 14, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 futex: check for NULL keys in match_futex

From: Darren Hart <[email protected]>

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.

Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
CC Eric Dumazet <[email protected]>
CC Dinakar Guniguntala <[email protected]>
CC John Stultz <[email protected]>

---

kernel/futex.c | 3 ++-

1 files changed, 2 insertions(+), 1 deletions(-)
kernel/futex.c +0 -0
index 4949d33..5971730 100644
@@ -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);
}
Signature · 3 lines
Darren Hart
IBM Linux Technology Center
Real-Time Linux Team
#1 lore raw

[tip:core/urgent] futex: Check for NULL keys in match_futex

Commit-ID:  2bc872036e1c5948b5b02942810bbdd8dbdb9812
Gitweb:     http://git.kernel.org/tip/2bc872036e1c5948b5b02942810bbdd8dbdb9812
Author:     Darren Hart <[email protected]>
AuthorDate: Wed, 14 Oct 2009 10:12:39 -0700
Committer:  Thomas Gleixner <[email protected]>
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.

Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
CC Eric Dumazet <[email protected]>
CC Dinakar Guniguntala <[email protected]>
CC John Stultz <[email protected]>

LKML-Reference: <[email protected]>

---
 kernel/futex.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
kernel/futex.c +2 -1
index 5c88839..06938e5 100644
@@ -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);
 }