Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1382866 > unrolled thread

Re: [PATCH] kernel/futex: handle the case where we got a "late" waiter

Started byDavidlohr Bueso <dave@stgolabs.net>
First post2016-04-20 00:30 +0200
Last post2016-04-20 09:40 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH] kernel/futex: handle the case where we got a "late"  waiter Davidlohr Bueso <dave@stgolabs.net> - 2016-04-20 00:30 +0200
    Re: [PATCH] kernel/futex: handle the case where we got a "late"  waiter Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-04-20 09:10 +0200
    Re: [PATCH] kernel/futex: handle the case where we got a "late"  waiter Thomas Gleixner <tglx@linutronix.de> - 2016-04-20 09:40 +0200

#1382866 — Re: [PATCH] kernel/futex: handle the case where we got a "late" waiter

FromDavidlohr Bueso <dave@stgolabs.net>
Date2016-04-20 00:30 +0200
SubjectRe: [PATCH] kernel/futex: handle the case where we got a "late" waiter
Message-ID<rpMjE-5XD-1@gated-at.bofh.it>
On Fri, 15 Apr 2016, Sebastian Andrzej Siewior wrote:

>futex_unlock_pi() gets uval before taking the hb lock. Now imagine
>someone in futex_lock_pi() took the lock. While futex_unlock_pi() waits
>for the hb lock, the LOCK_PI sets FUTEX_WAITERS and drops the lock.
>Now, futex_unlock_pi() figures out that there is waiter and invokes
>wake_futex_pi() with the old uval which does not yet have FUTEX_WAITERS
>set. This flaw lets cmpxchg_futex_value_locked() fail and return -EINVAL.

Hmm but if we're calling futex_unlock_pi() in the first place, doesn't that
indicate that the uval already has FUTEX_WAITERS and therefore failed the
TID->0 transition in userland? That or the thread is bogusly unlocking a
lock that it doesn't own.

This is of course different than the requeue_pi case which can specify
set_waiters but also gets the value via get_futex_value_locked().

Is this a real issue or did you find it by code inspection?

Thanks,
Davidlohr

[toc] | [next] | [standalone]


#1383088

FromSebastian Andrzej Siewior <bigeasy@linutronix.de>
Date2016-04-20 09:10 +0200
Message-ID<rpUqR-3QU-1@gated-at.bofh.it>
In reply to#1382866
On 04/20/2016 12:27 AM, Davidlohr Bueso wrote:
> On Fri, 15 Apr 2016, Sebastian Andrzej Siewior wrote:
> 
>> futex_unlock_pi() gets uval before taking the hb lock. Now imagine
>> someone in futex_lock_pi() took the lock. While futex_unlock_pi() waits
>> for the hb lock, the LOCK_PI sets FUTEX_WAITERS and drops the lock.
>> Now, futex_unlock_pi() figures out that there is waiter and invokes
>> wake_futex_pi() with the old uval which does not yet have FUTEX_WAITERS
>> set. This flaw lets cmpxchg_futex_value_locked() fail and return -EINVAL.
> 
> Hmm but if we're calling futex_unlock_pi() in the first place, doesn't that
> indicate that the uval already has FUTEX_WAITERS and therefore failed the
> TID->0 transition in userland? That or the thread is bogusly unlocking a
> lock that it doesn't own.

I hacked a testing tool which always did the syscall for LOCK_PI /
UNLOCK_PI and this popped up.

> 
> This is of course different than the requeue_pi case which can specify
> set_waiters but also gets the value via get_futex_value_locked().
> 
> Is this a real issue or did you find it by code inspection?

real issue.
	https://breakpoint.cc/mass-futex2-rl.c

> Thanks,
> Davidlohr

Sebastian

[toc] | [prev] | [next] | [standalone]


#1383110

FromThomas Gleixner <tglx@linutronix.de>
Date2016-04-20 09:40 +0200
Message-ID<rpUTT-43d-5@gated-at.bofh.it>
In reply to#1382866
On Tue, 19 Apr 2016, Davidlohr Bueso wrote:
> On Fri, 15 Apr 2016, Sebastian Andrzej Siewior wrote:
> 
> > futex_unlock_pi() gets uval before taking the hb lock. Now imagine
> > someone in futex_lock_pi() took the lock. While futex_unlock_pi() waits
> > for the hb lock, the LOCK_PI sets FUTEX_WAITERS and drops the lock.
> > Now, futex_unlock_pi() figures out that there is waiter and invokes
> > wake_futex_pi() with the old uval which does not yet have FUTEX_WAITERS
> > set. This flaw lets cmpxchg_futex_value_locked() fail and return -EINVAL.
> 
> Hmm but if we're calling futex_unlock_pi() in the first place, doesn't that
> indicate that the uval already has FUTEX_WAITERS and therefore failed the
> TID->0 transition in userland? That or the thread is bogusly unlocking a
> lock that it doesn't own.

It can be called unconditionally w/o trying the TID->0 transition in user
space first and we should handle that case.
 
Thanks,

	tglx

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web