Skip to contentSkip to conversation

futex: Fix handling of bad requeue syscall pairing

PATCH Superseded Darren Hart 2 participants 4 messages Aug 7, 2009 – Aug 10, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 futex: Fix handling of bad requeue syscall pairing

From: Darren Hart <[email protected]>

If futex_requeue(requeue_pi=1) finds a futex_q that was created by a call other than futex_wait_requeue_pi(), the q.rt_waiter will be null. If so, this will result in an oops from the following call graph:

futex_requeue()
rt_mutex_start_proxy_lock()
task_blocks_on_rt_mutex()

     waiter->task dereference
       OOPS

We currently WARN_ON() if this is detected, clearly this is inadequate. If we detect a mis-pairing in futex_requeue(), bail out, sending -EINVAL to user-space.

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

---

kernel/futex.c | 11 +++++++++--

1 files changed, 9 insertions(+), 2 deletions(-)
kernel/futex.c +0 -0
index 578c7b7..d806d6c 100644
@@ -1306,8 +1306,15 @@ retry_private:
		if (!match_futex(&this->key, &key1))
			continue;

- WARN_ON(!requeue_pi && this->rt_waiter);
- WARN_ON(requeue_pi && !this->rt_waiter);
+ /*
+ * FUTEX_WAIT_REQEUE_PI and FUTEX_CMP_REQUEUE_PI should always
+ * be paired with each other and no other futex ops.
+ */
+ if (requeue_pi && !this->rt_waiter ||
+ !requeue_pi && this->rt_waiter) {
+ ret = -EINVAL;
+ break;
+ }

		/*
		 * Wake nr_wake waiters.  For requeue_pi, if we acquired the
Signature · 3 lines
Darren Hart
IBM Linux Technology Center
Real-Time Linux Team
#1 lore raw

PATCH v2 1/1 futex: Fix handling of bad requeue syscall pairing

From: Darren Hart <[email protected]>

If futex_requeue(requeue_pi=1) finds a futex_q that was created by a call other the futex_wait_requeue_pi(), the q.rt_waiter may be null. If so, this will result in an oops from the following call graph:

futex_requeue()
rt_mutex_start_proxy_lock()
task_blocks_on_rt_mutex()

     waiter->task dereference
       OOPS

We currently WARN_ON() if this is detected, clearly this is inadequate. If we detect a mispairing in futex_requeue(), bail out, seding -EINVAL to user-space.

V2: Fix parenthesis warnings.

Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Steven Rostedt <[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 | 11 +++++++++--

1 files changed, 9 insertions(+), 2 deletions(-)
kernel/futex.c +0 -0
index df30983..4705d89 100644
@@ -1306,8 +1306,15 @@ retry_private:
		if (!match_futex(&this->key, &key1))
			continue;

- WARN_ON(!requeue_pi && this->rt_waiter);
- WARN_ON(requeue_pi && !this->rt_waiter);
+ /*
+ * FUTEX_WAIT_REQEUE_PI and FUTEX_CMP_REQUEUE_PI should always
+ * be paired with each other and no other futex ops.
+ */
+ if ((requeue_pi && !this->rt_waiter) ||
+ (!requeue_pi && this->rt_waiter)) {
+ ret = -EINVAL;
+ break;
+ }

		/*
		 * Wake nr_wake waiters.  For requeue_pi, if we acquired the
Signature · 3 lines
Darren Hart
IBM Linux Technology Center
Real-Time Linux Team
Acked-by on v2 1/1
#2 lore raw
Quoted 12 lines · Darren Hart

From: Darren Hart <[email protected]>

If futex_requeue(requeue_pi=1) finds a futex_q that was created by a call other the futex_wait_requeue_pi(), the q.rt_waiter may be null. If so, this will result in an oops from the following call graph:

futex_requeue()
rt_mutex_start_proxy_lock()

    task_blocks_on_rt_mutex()
      waiter->task dereference
        OOPS
Quoted 8 lines

We currently WARN_ON() if this is detected, clearly this is inadequate. If we detect a mispairing in futex_requeue(), bail out, seding -EINVAL to user-space.

V2: Fix parenthesis warnings.

Cc Thomas Gleixner <[email protected]>
Quoted 33 lines
Cc Steven Rostedt <[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 |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
kernel/futex.c +9 -2
index df30983..4705d89 100644
@@ -1306,8 +1306,15 @@ retry_private:
 		if (!match_futex(&this->key, &key1))
 			continue;
 
-		WARN_ON(!requeue_pi && this->rt_waiter);
-		WARN_ON(requeue_pi && !this->rt_waiter);
+		/*
+		 * FUTEX_WAIT_REQEUE_PI and FUTEX_CMP_REQUEUE_PI should always
+		 * be paired with each other and no other futex ops.
+		 */
+		if ((requeue_pi && !this->rt_waiter) ||
+		    (!requeue_pi && this->rt_waiter)) {
+			ret = -EINVAL;
+			break;
+		}
 
 		/*
 		 * Wake nr_wake waiters.  For requeue_pi, if we acquired the
#3 lore raw
In reply to Darren Hart
Commit-ID:  392741e0a4e17c82e3978b7fcbf04291294dc0a1
Gitweb:     http://git.kernel.org/tip/392741e0a4e17c82e3978b7fcbf04291294dc0a1
Author:     Darren Hart <[email protected]>
AuthorDate: Fri, 7 Aug 2009 15:20:48 -0700
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 10 Aug 2009 20:38:11 +0200

futex: Fix handling of bad requeue syscall pairing

If futex_requeue(requeue_pi=1) finds a futex_q that was created by a call other the futex_wait_requeue_pi(), the q.rt_waiter may be null. If so, this will result in an oops from the following call graph:

futex_requeue()
rt_mutex_start_proxy_lock()

    task_blocks_on_rt_mutex()
      waiter->task dereference
        OOPS

We currently WARN_ON() if this is detected, clearly this is inadequate. If we detect a mispairing in futex_requeue(), bail out, seding -EINVAL to user-space.

V2: Fix parenthesis warnings.

Cc Steven Rostedt <[email protected]>
Cc John Kacur <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Dinakar Guniguntala <[email protected]>
Cc John Stultz <[email protected]>

LKML-Reference: <[email protected]>

---
 kernel/futex.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
kernel/futex.c +9 -2
index 8cc3ee1..e18cfbd 100644
@@ -1256,8 +1256,15 @@ retry_private:
 		if (!match_futex(&this->key, &key1))
 			continue;
 
-		WARN_ON(!requeue_pi && this->rt_waiter);
-		WARN_ON(requeue_pi && !this->rt_waiter);
+		/*
+		 * FUTEX_WAIT_REQEUE_PI and FUTEX_CMP_REQUEUE_PI should always
+		 * be paired with each other and no other futex ops.
+		 */
+		if ((requeue_pi && !this->rt_waiter) ||
+		    (!requeue_pi && this->rt_waiter)) {
+			ret = -EINVAL;
+			break;
+		}
 
 		/*
 		 * Wake nr_wake waiters.  For requeue_pi, if we acquired the