source: trunk/server/common/patches/cve-2014-3153-1.patch @ 2557

Last change on this file since 2557 was 2557, checked in by achernya, 10 years ago
Kernel patches against cve-2014-3153 (old, uncommitted changes)
File size: 2.6 KB
RevLine 
[2557]1From b58623fb64ff0454ec20bce7a02275a20c23086d Mon Sep 17 00:00:00 2001
2From: Thomas Gleixner <tglx@linutronix.de>
3Date: Tue, 3 Jun 2014 12:27:06 +0000
4Subject: [PATCH 1/4] futex-prevent-requeue-pi-on-same-futex.patch futex:
5 Forbid uaddr == uaddr2 in futex_requeue(...,
6 requeue_pi=1)
7
8commit e9c243a5a6de0be8e584c604d353412584b592f8 upstream.
9
10If uaddr == uaddr2, then we have broken the rule of only requeueing from
11a non-pi futex to a pi futex with this call.  If we attempt this, then
12dangling pointers may be left for rt_waiter resulting in an exploitable
13condition.
14
15This change brings futex_requeue() in line with futex_wait_requeue_pi()
16which performs the same check as per commit 6f7b0a2a5c0f ("futex: Forbid
17uaddr == 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
22Fixes CVE-2014-3153.
23
24Reported-by: Pinkie Pie
25Signed-off-by: Will Drewry <wad@chromium.org>
26Signed-off-by: Kees Cook <keescook@chromium.org>
27Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
28Reviewed-by: Darren Hart <dvhart@linux.intel.com>
29Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
30Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
31---
32 kernel/futex.c |   25 +++++++++++++++++++++++++
33 1 file changed, 25 insertions(+)
34
35diff --git a/kernel/futex.c b/kernel/futex.c
36index 58743c0..93e522f 100644
37--- a/kernel/futex.c
38+++ b/kernel/futex.c
39@@ -1293,6 +1293,13 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags,
40 
41        if (requeue_pi) {
42                /*
43+                * Requeue PI only works on two distinct uaddrs. This
44+                * check is only valid for private futexes. See below.
45+                */
46+               if (uaddr1 == uaddr2)
47+                       return -EINVAL;
48+
49+               /*
50                 * requeue_pi requires a pi_state, try to allocate it now
51                 * without any locks in case it fails.
52                 */
53@@ -1330,6 +1337,15 @@ retry:
54        if (unlikely(ret != 0))
55                goto out_put_key1;
56 
57+       /*
58+        * The check above which compares uaddrs is not sufficient for
59+        * shared futexes. We need to compare the keys:
60+        */
61+       if (requeue_pi && match_futex(&key1, &key2)) {
62+               ret = -EINVAL;
63+               goto out_put_keys;
64+       }
65+
66        hb1 = hash_futex(&key1);
67        hb2 = hash_futex(&key2);
68 
69@@ -2360,6 +2376,15 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
70        if (ret)
71                goto out_key2;
72 
73+       /*
74+        * The check above which compares uaddrs is not sufficient for
75+        * shared futexes. We need to compare the keys:
76+        */
77+       if (match_futex(&q.key, &key2)) {
78+               ret = -EINVAL;
79+               goto out_put_keys;
80+       }
81+
82        /* Queue the futex_q, drop the hb lock, wait for wakeup. */
83        futex_wait_queue_me(hb, &q, to);
84 
85--
861.7.10.4
87
Note: See TracBrowser for help on using the repository browser.