mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Esben Nielsen <nielsen.esben@googlemail.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	StevenRostedt <rostedt@goodmis.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: [-rt] Fix race condition and following BUG in PI-futex
Date: Tue, 1 Aug 2006 19:46:32 +0100 (BST)	[thread overview]
Message-ID: <Pine.LNX.4.64.0608011931560.10605@localhost.localdomain> (raw)

I ran into the bug on 2.6.17-rt8 with the previous posted patches which 
make pthread_timed_lock() work on UP, but the bug is there without the 
patches - I just can't trigger it - and it is also in the mainline kernel.

The problem is that rt_mutex_next_owner() is used unprotected in 
wake_futex_pi(). At least it isn't probably serialiazed against the next 
owner being signalled or getting a timeout. The only lock, which is 
good enough here, is &pi_state->pi_mutex.wait_lock, so I added this 
protection.

Esben

  kernel/futex.c |   12 ++++++++++--
  1 file changed, 10 insertions(+), 2 deletions(-)

Index: linux-2.6.17-rt8/kernel/futex.c
===================================================================
--- linux-2.6.17-rt8.orig/kernel/futex.c
+++ linux-2.6.17-rt8/kernel/futex.c
@@ -565,6 +565,7 @@ static int wake_futex_pi(u32 __user *uad
  	if (!pi_state)
  		return -EINVAL;

+	spin_lock(&pi_state->pi_mutex.wait_lock);
  	new_owner = rt_mutex_next_owner(&pi_state->pi_mutex);

  	/*
@@ -590,15 +591,22 @@ static int wake_futex_pi(u32 __user *uad
  	curval = futex_atomic_cmpxchg_inatomic(uaddr, uval, newval);
  	dec_preempt_count();

-	if (curval == -EFAULT)
+	if (curval == -EFAULT) {
+		spin_unlock(&pi_state->pi_mutex.wait_lock);
  		return -EFAULT;
-	if (curval != uval)
+	}
+	if (curval != uval) {
+		spin_unlock(&pi_state->pi_mutex.wait_lock);
  		return -EINVAL;
+	}

  	list_del_init(&pi_state->owner->pi_state_list);
  	list_add(&pi_state->list, &new_owner->pi_state_list);
  	pi_state->owner = new_owner;
+	atomic_inc(&pi_state->refcount);
+	spin_unlock(&pi_state->pi_mutex.wait_lock);
  	rt_mutex_unlock(&pi_state->pi_mutex);
+	free_pi_state(pi_state);

  	return 0;
  }

             reply	other threads:[~2006-08-01 17:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-01 18:46 Esben Nielsen [this message]
2006-08-01 18:23 ` Steven Rostedt
2006-08-01 20:22   ` Darren Hart
2006-08-01 21:07     ` Steven Rostedt
2006-08-01 23:28       ` Esben Nielsen
2006-08-03  4:48         ` Darren Hart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.0608011931560.10605@localhost.localdomain \
    --to=nielsen.esben@googlemail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®