]> www.infradead.org Git - users/jedix/linux-maple.git/commit
futex: Handle unlock_pi race gracefully
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Fri, 15 Apr 2016 12:35:39 +0000 (14:35 +0200)
committerDhaval Giani <dhaval.giani@oracle.com>
Fri, 20 Jan 2017 22:21:50 +0000 (17:21 -0500)
commit036e7f17854a404bc8c39d495584de7dfd89bc1b
treedf37c0330bbeb655755df26d34b95392b14f25b7
parente4a0b40e0937a4c08a2626561aa64636dddb41a9
futex: Handle unlock_pi race gracefully

Orabug: 25227131

[ Upstream commit 89e9e66ba1b3bde9d8ea90566c2aee20697ad681 ]

If userspace calls UNLOCK_PI unconditionally without trying the TID -> 0
transition in user space first then the user space value might not have the
waiters bit set. This opens the following race:

CPU0                 CPU1
uval = get_user(futex)
    lock(hb)
lock(hb)
    futex |= FUTEX_WAITERS
    ....
    unlock(hb)

cmpxchg(futex, uval, newval)

So the cmpxchg fails and returns -EINVAL to user space, which is wrong because
the futex value is valid.

To handle this (yes, yet another) corner case gracefully, check for a flag
change and retry.

[ tglx: Massaged changelog and slightly reworked implementation ]

Fixes: ccf9e6a80d9e ("futex: Make unlock_pi more robust")
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: stable@vger.kernel.org
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Darren Hart <dvhart@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1460723739-5195-1-git-send-email-bigeasy@linutronix.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
(cherry picked from commit 28f83d2daecd97392c9a0580c00853a19a76a8bc)

Signed-off-by: Dhaval Giani <dhaval.giani@oracle.com>
kernel/futex.c