]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
futex: Ensure that futex address is aligned in handle_futex_death()
authorChen Jie <chenjie6@huawei.com>
Fri, 15 Mar 2019 03:44:38 +0000 (03:44 +0000)
committerThomas Gleixner <tglx@linutronix.de>
Fri, 22 Mar 2019 12:05:26 +0000 (13:05 +0100)
The futex code requires that the user space addresses of futexes are 32bit
aligned. sys_futex() checks this in futex_get_keys() but the robust list
code has no alignment check in place.

As a consequence the kernel crashes on architectures with strict alignment
requirements in handle_futex_death() when trying to cmpxchg() on an
unaligned futex address which was retrieved from the robust list.

[ tglx: Rewrote changelog, proper sizeof() based alignement check and add
   comment ]

Fixes: 0771dfefc9e5 ("[PATCH] lightweight robust futexes: core")
Signed-off-by: Chen Jie <chenjie6@huawei.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: <dvhart@infradead.org>
Cc: <peterz@infradead.org>
Cc: <zengweilin@huawei.com>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/1552621478-119787-1-git-send-email-chenjie6@huawei.com
kernel/futex.c

index c3b73b0311bc7c79d4b8a34d344cc943d6511b32..9e40cf7be60662f0fb8f6c61a6066532954b3fb1 100644 (file)
@@ -3436,6 +3436,10 @@ static int handle_futex_death(u32 __user *uaddr, struct task_struct *curr, int p
 {
        u32 uval, uninitialized_var(nval), mval;
 
+       /* Futex address must be 32bit aligned */
+       if ((((unsigned long)uaddr) % sizeof(*uaddr)) != 0)
+               return -1;
+
 retry:
        if (get_user(uval, uaddr))
                return -1;