]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
dda05adb33f90ff4896677fffab0cb020c7d0c0c
[thirdparty/kernel/stable-queue.git] /
1 From e9c243a5a6de0be8e584c604d353412584b592f8 Mon Sep 17 00:00:00 2001
2 From: Thomas Gleixner <tglx@linutronix.de>
3 Date: Tue, 3 Jun 2014 12:27:06 +0000
4 Subject: futex-prevent-requeue-pi-on-same-futex.patch futex: Forbid uaddr == uaddr2 in futex_requeue(..., requeue_pi=1)
5
6 From: Thomas Gleixner <tglx@linutronix.de>
7
8 commit e9c243a5a6de0be8e584c604d353412584b592f8 upstream.
9
10 If uaddr == uaddr2, then we have broken the rule of only requeueing from
11 a non-pi futex to a pi futex with this call. If we attempt this, then
12 dangling pointers may be left for rt_waiter resulting in an exploitable
13 condition.
14
15 This change brings futex_requeue() in line with futex_wait_requeue_pi()
16 which performs the same check as per commit 6f7b0a2a5c0f ("futex: Forbid
17 uaddr == uaddr2 in futex_wait_requeue_pi()")
18
19 [ tglx: Compare the resulting keys as well, as uaddrs might be
20 different depending on the mapping ]
21
22 Fixes CVE-2014-3153.
23
24 Reported-by: Pinkie Pie
25 Signed-off-by: Will Drewry <wad@chromium.org>
26 Signed-off-by: Kees Cook <keescook@chromium.org>
27 Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
28 Reviewed-by: Darren Hart <dvhart@linux.intel.com>
29 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
30 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
31
32 ---
33 kernel/futex.c | 25 +++++++++++++++++++++++++
34 1 file changed, 25 insertions(+)
35
36 --- a/kernel/futex.c
37 +++ b/kernel/futex.c
38 @@ -1428,6 +1428,13 @@ static int futex_requeue(u32 __user *uad
39
40 if (requeue_pi) {
41 /*
42 + * Requeue PI only works on two distinct uaddrs. This
43 + * check is only valid for private futexes. See below.
44 + */
45 + if (uaddr1 == uaddr2)
46 + return -EINVAL;
47 +
48 + /*
49 * requeue_pi requires a pi_state, try to allocate it now
50 * without any locks in case it fails.
51 */
52 @@ -1465,6 +1472,15 @@ retry:
53 if (unlikely(ret != 0))
54 goto out_put_key1;
55
56 + /*
57 + * The check above which compares uaddrs is not sufficient for
58 + * shared futexes. We need to compare the keys:
59 + */
60 + if (requeue_pi && match_futex(&key1, &key2)) {
61 + ret = -EINVAL;
62 + goto out_put_keys;
63 + }
64 +
65 hb1 = hash_futex(&key1);
66 hb2 = hash_futex(&key2);
67
68 @@ -2511,6 +2527,15 @@ static int futex_wait_requeue_pi(u32 __u
69 if (ret)
70 goto out_key2;
71
72 + /*
73 + * The check above which compares uaddrs is not sufficient for
74 + * shared futexes. We need to compare the keys:
75 + */
76 + if (match_futex(&q.key, &key2)) {
77 + ret = -EINVAL;
78 + goto out_put_keys;
79 + }
80 +
81 /* Queue the futex_q, drop the hb lock, wait for wakeup. */
82 futex_wait_queue_me(hb, &q, to);
83