]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/2.6.27.46/futex-handle-user-space-corruption-gracefully.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 2.6.27.46 / futex-handle-user-space-corruption-gracefully.patch
CommitLineData
9242fd55
GKH
1From 51246bfd189064079c54421507236fd2723b18f3 Mon Sep 17 00:00:00 2001
2From: Thomas Gleixner <tglx@linutronix.de>
3Date: Tue, 2 Feb 2010 11:40:27 +0100
4Subject: futex: Handle user space corruption gracefully
5
6From: Thomas Gleixner <tglx@linutronix.de>
7
8commit 51246bfd189064079c54421507236fd2723b18f3 upstream.
9
10If the owner of a PI futex dies we fix up the pi_state and set
11pi_state->owner to NULL. When a malicious or just sloppy programmed
12user space application sets the futex value to 0 e.g. by calling
13pthread_mutex_init(), then the futex can be acquired again. A new
14waiter manages to enqueue itself on the pi_state w/o damage, but on
15unlock the kernel dereferences pi_state->owner and oopses.
16
17Prevent this by checking pi_state->owner in the unlock path. If
18pi_state->owner is not current we know that user space manipulated the
19futex value. Ignore the mess and return -EINVAL.
20
21This catches the above case and also the case where a task hijacks the
22futex by setting the tid value and then tries to unlock it.
23
24Reported-by: Jermome Marchand <jmarchan@redhat.com>
25Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
26Acked-by: Darren Hart <dvhltc@us.ibm.com>
27Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
28Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
29
30---
31 kernel/futex.c | 7 +++++++
32 1 file changed, 7 insertions(+)
33
34--- a/kernel/futex.c
35+++ b/kernel/futex.c
36@@ -647,6 +647,13 @@ static int wake_futex_pi(u32 __user *uad
37 if (!pi_state)
38 return -EINVAL;
39
40+ /*
41+ * If current does not own the pi_state then the futex is
42+ * inconsistent and user space fiddled with the futex value.
43+ */
44+ if (pi_state->owner != current)
45+ return -EINVAL;
46+
47 spin_lock(&pi_state->pi_mutex.wait_lock);
48 new_owner = rt_mutex_next_owner(&pi_state->pi_mutex);
49