* [PATCH] futex: Fix handling of bad requeue syscall pairing
@ 2009-08-07 21:45 Darren Hart
2009-08-07 22:20 ` [PATCH V2] " Darren Hart
0 siblings, 1 reply; 4+ messages in thread
From: Darren Hart @ 2009-08-07 21:45 UTC (permalink / raw)
To: lkml, , linux-rt-users
Cc: Thomas Gleixner, Peter Zijlstra, Steven Rostedt, Ingo Molnar,
John Kacur, Eric Dumazet, Dinakar Guniguntala, John Stultz
From: Darren Hart <dvhltc@us.ibm.com>
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.
Signed-off-by: Darren Hart <dvhltc@us.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@elte.hu>
CC: Eric Dumazet <eric.dumazet@gmail.com>
CC: John Kacur <jkacur@redhat.com>
CC: Dinakar Guniguntala <dino@in.ibm.com>
CC: John Stultz <johnstul@us.ibm.com>
---
kernel/futex.c | 11 +++++++++--
1 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/kernel/futex.c b/kernel/futex.c
index 578c7b7..d806d6c 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -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
--
Darren Hart
IBM Linux Technology Center
Real-Time Linux Team
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH V2] futex: Fix handling of bad requeue syscall pairing
2009-08-07 21:45 [PATCH] futex: Fix handling of bad requeue syscall pairing Darren Hart
@ 2009-08-07 22:20 ` Darren Hart
2009-08-10 15:27 ` Peter Zijlstra
2009-08-10 18:42 ` [tip:core/urgent] " tip-bot for Darren Hart
0 siblings, 2 replies; 4+ messages in thread
From: Darren Hart @ 2009-08-07 22:20 UTC (permalink / raw)
To: lkml, , linux-rt-users
Cc: Thomas Gleixner, Peter Zijlstra, Steven Rostedt, Ingo Molnar,
John Kacur, Eric Dumazet, Dinakar Guniguntala, John Stultz
From: Darren Hart <dvhltc@us.ibm.com>
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.
Signed-off-by: Darren Hart <dvhltc@us.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.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 | 11 +++++++++--
1 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/kernel/futex.c b/kernel/futex.c
index df30983..4705d89 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -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
--
Darren Hart
IBM Linux Technology Center
Real-Time Linux Team
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH V2] futex: Fix handling of bad requeue syscall pairing
2009-08-07 22:20 ` [PATCH V2] " Darren Hart
@ 2009-08-10 15:27 ` Peter Zijlstra
2009-08-10 18:42 ` [tip:core/urgent] " tip-bot for Darren Hart
1 sibling, 0 replies; 4+ messages in thread
From: Peter Zijlstra @ 2009-08-10 15:27 UTC (permalink / raw)
To: Darren Hart
Cc: lkml,, linux-rt-users, Thomas Gleixner, Steven Rostedt,
Ingo Molnar, John Kacur, Eric Dumazet, Dinakar Guniguntala,
John Stultz
On Fri, 2009-08-07 at 15:20 -0700, Darren Hart wrote:
> From: Darren Hart <dvhltc@us.ibm.com>
>
> 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.
>
> Signed-off-by: Darren Hart <dvhltc@us.ibm.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra <peterz@infradead.org>
> Cc: Steven Rostedt <rostedt@goodmis.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 | 11 +++++++++--
> 1 files changed, 9 insertions(+), 2 deletions(-)
>
>
> diff --git a/kernel/futex.c b/kernel/futex.c
> index df30983..4705d89 100644
> --- a/kernel/futex.c
> +++ b/kernel/futex.c
> @@ -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
^ permalink raw reply [flat|nested] 4+ messages in thread* [tip:core/urgent] futex: Fix handling of bad requeue syscall pairing
2009-08-07 22:20 ` [PATCH V2] " Darren Hart
2009-08-10 15:27 ` Peter Zijlstra
@ 2009-08-10 18:42 ` tip-bot for Darren Hart
1 sibling, 0 replies; 4+ messages in thread
From: tip-bot for Darren Hart @ 2009-08-10 18:42 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, dvhltc, hpa, mingo, johnstul, eric.dumazet, jkacur,
peterz, dino, rostedt, tglx, mingo
Commit-ID: 392741e0a4e17c82e3978b7fcbf04291294dc0a1
Gitweb: http://git.kernel.org/tip/392741e0a4e17c82e3978b7fcbf04291294dc0a1
Author: Darren Hart <dvhltc@us.ibm.com>
AuthorDate: Fri, 7 Aug 2009 15:20:48 -0700
Committer: Ingo Molnar <mingo@elte.hu>
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.
Signed-off-by: Darren Hart <dvhltc@us.ibm.com>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: John Kacur <jkacur@redhat.com>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Dinakar Guniguntala <dino@in.ibm.com>
Cc: John Stultz <johnstul@linux.vnet.ibm.com>
LKML-Reference: <4A7CA8C0.7010809@us.ibm.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
kernel/futex.c | 11 +++++++++--
1 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/kernel/futex.c b/kernel/futex.c
index 8cc3ee1..e18cfbd 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -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
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-08-10 18:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-07 21:45 [PATCH] futex: Fix handling of bad requeue syscall pairing Darren Hart
2009-08-07 22:20 ` [PATCH V2] " Darren Hart
2009-08-10 15:27 ` Peter Zijlstra
2009-08-10 18:42 ` [tip:core/urgent] " tip-bot for Darren Hart
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.