]>
Commit | Line | Data |
---|---|---|
9242fd55 GKH |
1 | From 51246bfd189064079c54421507236fd2723b18f3 Mon Sep 17 00:00:00 2001 |
2 | From: Thomas Gleixner <tglx@linutronix.de> | |
3 | Date: Tue, 2 Feb 2010 11:40:27 +0100 | |
4 | Subject: futex: Handle user space corruption gracefully | |
5 | ||
6 | From: Thomas Gleixner <tglx@linutronix.de> | |
7 | ||
8 | commit 51246bfd189064079c54421507236fd2723b18f3 upstream. | |
9 | ||
10 | If the owner of a PI futex dies we fix up the pi_state and set | |
11 | pi_state->owner to NULL. When a malicious or just sloppy programmed | |
12 | user space application sets the futex value to 0 e.g. by calling | |
13 | pthread_mutex_init(), then the futex can be acquired again. A new | |
14 | waiter manages to enqueue itself on the pi_state w/o damage, but on | |
15 | unlock the kernel dereferences pi_state->owner and oopses. | |
16 | ||
17 | Prevent this by checking pi_state->owner in the unlock path. If | |
18 | pi_state->owner is not current we know that user space manipulated the | |
19 | futex value. Ignore the mess and return -EINVAL. | |
20 | ||
21 | This catches the above case and also the case where a task hijacks the | |
22 | futex by setting the tid value and then tries to unlock it. | |
23 | ||
24 | Reported-by: Jermome Marchand <jmarchan@redhat.com> | |
25 | Signed-off-by: Thomas Gleixner <tglx@linutronix.de> | |
26 | Acked-by: Darren Hart <dvhltc@us.ibm.com> | |
27 | Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl> | |
28 | Signed-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 |