<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/kernel/futex.c, branch linux-2.6.31.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-2.6.31.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-2.6.31.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2010-04-01T22:55:26Z</updated>
<entry>
<title>futex_lock_pi() key refcnt fix</title>
<updated>2010-04-01T22:55:26Z</updated>
<author>
<name>Mikael Pettersson</name>
</author>
<published>2010-01-23T21:36:29Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=b2547d0901583d4cb381a66a771087dd29174faf'/>
<id>urn:sha1:b2547d0901583d4cb381a66a771087dd29174faf</id>
<content type='text'>
commit 5ecb01cfdf96c5f465192bdb2a4fd4a61a24c6cc upstream.

This fixes a futex key reference count bug in futex_lock_pi(),
where a key's reference count is incremented twice but decremented
only once, causing the backing object to not be released.

If the futex is created in a temporary file in an ext3 file system,
this bug causes the file's inode to become an "undead" orphan,
which causes an oops from a BUG_ON() in ext3_put_super() when the
file system is unmounted. glibc's test suite is known to trigger this,
see &lt;http://bugzilla.kernel.org/show_bug.cgi?id=14256&gt;.

The bug is a regression from 2.6.28-git3, namely Peter Zijlstra's
38d47c1b7075bd7ec3881141bb3629da58f88dab "[PATCH] futex: rely on
get_user_pages() for shared futexes". That commit made get_futex_key()
also increment the reference count of the futex key, and updated its
callers to decrement the key's reference count before returning.
Unfortunately the normal exit path in futex_lock_pi() wasn't corrected:
the reference count is incremented by get_futex_key() and queue_lock(),
but the normal exit path only decrements once, via unqueue_me_pi().
The fix is to put_futex_key() after unqueue_me_pi(), since 2.6.31
this is easily done by 'goto out_put_key' rather than 'goto out'.

Signed-off-by: Mikael Pettersson &lt;mikpe@it.uu.se&gt;
Acked-by: Peter Zijlstra &lt;a.p.zijlstra@chello.nl&gt;
Acked-by: Darren Hart &lt;dvhltc@us.ibm.com&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;

</content>
</entry>
<entry>
<title>futex: Handle user space corruption gracefully</title>
<updated>2010-04-01T22:55:26Z</updated>
<author>
<name>Thomas Gleixner</name>
</author>
<published>2010-02-02T10:40:27Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=b17fccf557c60799e5d3881a5c83da4a34869a10'/>
<id>urn:sha1:b17fccf557c60799e5d3881a5c83da4a34869a10</id>
<content type='text'>
commit 51246bfd189064079c54421507236fd2723b18f3 upstream.

If the owner of a PI futex dies we fix up the pi_state and set
pi_state-&gt;owner to NULL. When a malicious or just sloppy programmed
user space application sets the futex value to 0 e.g. by calling
pthread_mutex_init(), then the futex can be acquired again. A new
waiter manages to enqueue itself on the pi_state w/o damage, but on
unlock the kernel dereferences pi_state-&gt;owner and oopses.

Prevent this by checking pi_state-&gt;owner in the unlock path. If
pi_state-&gt;owner is not current we know that user space manipulated the
futex value. Ignore the mess and return -EINVAL.

This catches the above case and also the case where a task hijacks the
futex by setting the tid value and then tries to unlock it.

Reported-by: Jermome Marchand &lt;jmarchan@redhat.com&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Acked-by: Darren Hart &lt;dvhltc@us.ibm.com&gt;
Acked-by: Peter Zijlstra &lt;a.p.zijlstra@chello.nl&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;

</content>
</entry>
<entry>
<title>futex: Handle futex value corruption gracefully</title>
<updated>2010-04-01T22:55:26Z</updated>
<author>
<name>Thomas Gleixner</name>
</author>
<published>2010-02-03T08:33:05Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=4f7ce5b4140026b628cdc8ec983616efba2f1cd0'/>
<id>urn:sha1:4f7ce5b4140026b628cdc8ec983616efba2f1cd0</id>
<content type='text'>
commit 59647b6ac3050dd964bc556fe6ef22f4db5b935c upstream.

The WARN_ON in lookup_pi_state which complains about a mismatch
between pi_state-&gt;owner-&gt;pid and the pid which we retrieved from the
user space futex is completely bogus.

The code just emits the warning and then continues despite the fact
that it detected an inconsistent state of the futex. A conveniant way
for user space to spam the syslog.

Replace the WARN_ON by a consistency check. If the values do not match
return -EINVAL and let user space deal with the mess it created.

This also fixes the missing task_pid_vnr() when we compare the
pi_state-&gt;owner pid with the futex value.

Reported-by: Jermome Marchand &lt;jmarchan@redhat.com&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Acked-by: Darren Hart &lt;dvhltc@us.ibm.com&gt;
Acked-by: Peter Zijlstra &lt;a.p.zijlstra@chello.nl&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;

</content>
</entry>
<entry>
<title>futex: Take mmap_sem for get_user_pages in fault_in_user_writeable</title>
<updated>2009-12-18T21:43:21Z</updated>
<author>
<name>Andi Kleen</name>
</author>
<published>2009-12-08T12:19:42Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=7098a7420bc7c75253d785119d91be6ab15e18e5'/>
<id>urn:sha1:7098a7420bc7c75253d785119d91be6ab15e18e5</id>
<content type='text'>
commit 722d0172377a5697919b9f7e5beb95165b1dec4e upstream.

get_user_pages() must be called with mmap_sem held.

Signed-off-by: Andi Kleen &lt;ak@linux.intel.com&gt;
Cc: Andrew Morton &lt;akpm@linuxfoundation.org&gt;
Cc: Nick Piggin &lt;npiggin@suse.de&gt;
Cc: Darren Hart &lt;dvhltc@us.ibm.com&gt;
Cc: Peter Zijlstra &lt;peterz@infradead.org&gt;
LKML-Reference: &lt;20091208121942.GA21298@basil.fritz.box&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;

</content>
</entry>
<entry>
<title>futex: Fix spurious wakeup for requeue_pi really</title>
<updated>2009-11-10T00:21:54Z</updated>
<author>
<name>Thomas Gleixner</name>
</author>
<published>2009-10-28T19:26:48Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=fc7df048bf93e52c04f4c39104a5a388b73725b8'/>
<id>urn:sha1:fc7df048bf93e52c04f4c39104a5a388b73725b8</id>
<content type='text'>
commit 11df6dddcbc38affb7473aad3d962baf8414a947 upstream.

The requeue_pi path doesn't use unqueue_me() (and the racy lock_ptr ==
NULL test) nor does it use the wake_list of futex_wake() which where
the reason for commit 41890f2 (futex: Handle spurious wake up)

See debugging discussing on LKML Message-ID: &lt;4AD4080C.20703@us.ibm.com&gt;

The changes in this fix to the wait_requeue_pi path were considered to
be a likely unecessary, but harmless safety net. But it turns out that
due to the fact that for unknown $@#!*( reasons EWOULDBLOCK is defined
as EAGAIN we built an endless loop in the code path which returns
correctly EWOULDBLOCK.

Spurious wakeups in wait_requeue_pi code path are unlikely so we do
the easy solution and return EWOULDBLOCK^WEAGAIN to user space and let
it deal with the spurious wakeup.

Cc: Darren Hart &lt;dvhltc@us.ibm.com&gt;
Cc: Peter Zijlstra &lt;peterz@infradead.org&gt;
Cc: Eric Dumazet &lt;eric.dumazet@gmail.com&gt;
Cc: John Stultz &lt;johnstul@linux.vnet.ibm.com&gt;
Cc: Dinakar Guniguntala &lt;dino@in.ibm.com&gt;
LKML-Reference: &lt;4AE23C74.1090502@us.ibm.com&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;

</content>
</entry>
<entry>
<title>futex: Move drop_futex_key_refs out of spinlock'ed region</title>
<updated>2009-11-10T00:21:53Z</updated>
<author>
<name>Darren Hart</name>
</author>
<published>2009-10-15T22:30:48Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=81e6fd571d574da95cf977ff3266d95a802b1820'/>
<id>urn:sha1:81e6fd571d574da95cf977ff3266d95a802b1820</id>
<content type='text'>
commit 89061d3d58e1f0742139605dc6a7950aa1ecc019 upstream.

When requeuing tasks from one futex to another, the reference held
by the requeued task to the original futex location needs to be
dropped eventually.

Dropping the reference may ultimately lead to a call to
"iput_final" and subsequently call into filesystem- specific code -
which may be non-atomic.

It is therefore safer to defer this drop operation until after the
futex_hash_bucket spinlock has been dropped.

Originally-From: Helge Bahmann &lt;hcb@chaoticmind.net&gt;
Signed-off-by: Darren Hart &lt;dvhltc@us.ibm.com&gt;
Cc: Peter Zijlstra &lt;peterz@infradead.org&gt;
Cc: Eric Dumazet &lt;eric.dumazet@gmail.com&gt;
Cc: Dinakar Guniguntala &lt;dino@in.ibm.com&gt;
Cc: John Stultz &lt;johnstul@linux.vnet.ibm.com&gt;
Cc: Sven-Thorsten Dietrich &lt;sdietrich@novell.com&gt;
Cc: John Kacur &lt;jkacur@redhat.com&gt;
LKML-Reference: &lt;4AD7A298.5040802@us.ibm.com&gt;
Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;

</content>
</entry>
<entry>
<title>futex: Check for NULL keys in match_futex</title>
<updated>2009-11-10T00:21:52Z</updated>
<author>
<name>Darren Hart</name>
</author>
<published>2009-10-14T17:12:39Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=6d57fbdd82f6012a4d451bacd75451928cbc29be'/>
<id>urn:sha1:6d57fbdd82f6012a4d451bacd75451928cbc29be</id>
<content type='text'>
commit 2bc872036e1c5948b5b02942810bbdd8dbdb9812 upstream.

If userspace tries to perform a requeue_pi on a non-requeue_pi waiter,
it will find the futex_q-&gt;requeue_pi_key to be NULL and OOPS.

Check for NULL in match_futex() instead of doing explicit NULL pointer
checks on all call sites.  While match_futex(NULL, NULL) returning
false is a little odd, it's still correct as we expect valid key
references.

Signed-off-by: Darren Hart &lt;dvhltc@us.ibm.com&gt;
Cc: Peter Zijlstra &lt;peterz@infradead.org&gt;
Cc: Ingo Molnar &lt;mingo@elte.hu&gt;
CC: Eric Dumazet &lt;eric.dumazet@gmail.com&gt;
CC: Dinakar Guniguntala &lt;dino@in.ibm.com&gt;
CC: John Stultz &lt;johnstul@us.ibm.com&gt;
LKML-Reference: &lt;4AD60687.10306@us.ibm.com&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;

</content>
</entry>
<entry>
<title>futex: Handle spurious wake up</title>
<updated>2009-11-10T00:21:51Z</updated>
<author>
<name>Thomas Gleixner</name>
</author>
<published>2009-10-13T18:40:43Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=e68e25e608880c149c2080930295227a79ceb5ac'/>
<id>urn:sha1:e68e25e608880c149c2080930295227a79ceb5ac</id>
<content type='text'>
commit d58e6576b0deec6f0b9ff8450fe282da18c50883 upstream.

The futex code does not handle spurious wake up in futex_wait and
futex_wait_requeue_pi.

The code assumes that any wake up which was not caused by futex_wake /
requeue or by a timeout was caused by a signal wake up and returns one
of the syscall restart error codes.

In case of a spurious wake up the signal delivery code which deals
with the restart error codes is not invoked and we return that error
code to user space. That causes applications which actually check the
return codes to fail. Blaise reported that on preempt-rt a python test
program run into a exception trap. -rt exposed that due to a built in
spurious wake up accelerator :)

Solve this by checking signal_pending(current) in the wake up path and
handle the spurious wake up case w/o returning to user space.

Reported-by: Blaise Gassend &lt;blaise@willowgarage.com&gt;
Debugged-by: Darren Hart &lt;dvhltc@us.ibm.com&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Cc: Peter Zijlstra &lt;peterz@infradead.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;

</content>
</entry>
<entry>
<title>futex: Fix wakeup race by setting TASK_INTERRUPTIBLE before queue_me()</title>
<updated>2009-10-22T22:11:52Z</updated>
<author>
<name>Darren Hart</name>
</author>
<published>2009-09-22T05:30:38Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=eb20f6f5ae9b4198039f30d9177baf226488c15c'/>
<id>urn:sha1:eb20f6f5ae9b4198039f30d9177baf226488c15c</id>
<content type='text'>
commit 0729e196147692d84d4c099fcff056eba2ed61d8 upstream.

PI futexes do not use the same plist_node_empty() test for wakeup.
It was possible for the waiter (in futex_wait_requeue_pi()) to set
TASK_INTERRUPTIBLE after the waker assigned the rtmutex to the
waiter. The waiter would then note the plist was not empty and call
schedule(). The task would not be found by any subsequeuent futex
wakeups, resulting in a userspace hang.

By moving the setting of TASK_INTERRUPTIBLE to before the call to
queue_me(), the race with the waker is eliminated. Since we no
longer call get_user() from within queue_me(), there is no need to
delay the setting of TASK_INTERRUPTIBLE until after the call to
queue_me().

The FUTEX_LOCK_PI operation is not affected as futex_lock_pi()
relies entirely on the rtmutex code to handle schedule() and
wakeup.  The requeue PI code is affected because the waiter starts
as a non-PI waiter and is woken on a PI futex.

Remove the crusty old comment about holding spinlocks() across
get_user() as we no longer do that. Correct the locking statement
with a description of why the test is performed.

Signed-off-by: Darren Hart &lt;dvhltc@us.ibm.com&gt;
Acked-by: Peter Zijlstra &lt;peterz@infradead.org&gt;
Cc: Steven Rostedt &lt;rostedt@goodmis.org&gt;
Cc: Eric Dumazet &lt;eric.dumazet@gmail.com&gt;
Cc: Dinakar Guniguntala &lt;dino@in.ibm.com&gt;
Cc: John Stultz &lt;johnstul@us.ibm.com&gt;
LKML-Reference: &lt;20090922053038.8717.97838.stgit@Aeon&gt;
Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;

</content>
</entry>
<entry>
<title>futex: Detect mismatched requeue targets</title>
<updated>2009-10-22T22:11:52Z</updated>
<author>
<name>Darren Hart</name>
</author>
<published>2009-08-14T00:36:53Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=e43391f135ddf1cefc305bed9ce18d34b07bdcdd'/>
<id>urn:sha1:e43391f135ddf1cefc305bed9ce18d34b07bdcdd</id>
<content type='text'>
commit 84bc4af59081ee974dd80210e694ab59ebe51ce8 upstream.

There is currently no check to ensure that userspace uses the same
futex requeue target (uaddr2) in futex_requeue() that the waiter used
in futex_wait_requeue_pi().  A mismatch here could very unexpected
results as the waiter assumes it either wakes on uaddr1 or uaddr2. We
could detect this on wakeup in the waiter, but the cleanup is more
intense after the improper requeue has occured.

This patch stores the waiter's expected requeue target in a new
requeue_pi_key pointer in the futex_q which futex_requeue() checks
prior to attempting to do a proxy lock acquistion or a requeue when
requeue_pi=1. If they don't match, return -EINVAL from futex_requeue,
aborting the requeue of any remaining waiters.

Signed-off-by: Darren Hart &lt;dvhltc@us.ibm.com&gt;
Cc: Peter Zijlstra &lt;peterz@infradead.org&gt;
Cc: Eric Dumazet &lt;eric.dumazet@gmail.com&gt;
Cc: John Kacur &lt;jkacur@redhat.com&gt;
Cc: Dinakar Guniguntala &lt;dino@in.ibm.com&gt;
Cc: John Stultz &lt;johnstul@us.ibm.com&gt;
LKML-Reference: &lt;20090814003650.14634.63916.stgit@Aeon&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;

</content>
</entry>
</feed>
