Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1533805 > unrolled thread
| Started by | Darren Hart <dvhart@infradead.org> |
|---|---|
| First post | 2016-12-01 06:00 +0100 |
| Last post | 2016-12-01 06:40 +0100 |
| Articles | 2 — 2 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.
Re: [PATCH] futex: Fix potential use-after-free in FUTEX_REQUEUE_PI Darren Hart <dvhart@infradead.org> - 2016-12-01 06:00 +0100
Re: [PATCH] futex: Fix potential use-after-free in FUTEX_REQUEUE_PI Peter Zijlstra <peterz@infradead.org> - 2016-12-01 06:40 +0100
| From | Darren Hart <dvhart@infradead.org> |
|---|---|
| Date | 2016-12-01 06:00 +0100 |
| Subject | Re: [PATCH] futex: Fix potential use-after-free in FUTEX_REQUEUE_PI |
| Message-ID | <sJrDr-7sX-9@gated-at.bofh.it> |
On Thu, Nov 24, 2016 at 04:38:08PM +0100, Peter Zijlstra wrote:
> On Thu, Nov 24, 2016 at 04:19:41PM +0100, Thomas Gleixner wrote:
> > On Thu, 24 Nov 2016, Peter Zijlstra wrote:
> >
> > >
> > > While working on the futex code, I stumbled over this potential
> > > use-after-free scenario.
> > >
> > > pi_mutex is a pointer into pi_state, which we drop the reference on in
> > > unqueue_me_pi(). So any access to that pointer after that is bad.
> > >
> > > Since other sites already do rt_mutex_unlock() with hb->lock held, see
> > > for example futex_lock_pi(), simply move the unlock before
> > > unqueue_me_pi().
> > >
> > > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> > > ---
> > > kernel/futex.c | 22 +++++++++++++---------
> > > 1 file changed, 13 insertions(+), 9 deletions(-)
> > >
> > > diff --git a/kernel/futex.c b/kernel/futex.c
> > > index 2c4be467fecd..d5a81339209f 100644
> > > --- a/kernel/futex.c
> > > +++ b/kernel/futex.c
> > > @@ -2813,7 +2813,6 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
> > > {
> > > struct hrtimer_sleeper timeout, *to = NULL;
> > > struct rt_mutex_waiter rt_waiter;
> > > - struct rt_mutex *pi_mutex = NULL;
> > > struct futex_hash_bucket *hb;
> > > union futex_key key2 = FUTEX_KEY_INIT;
> > > struct futex_q q = futex_q_init;
> > > @@ -2905,6 +2904,8 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
> > > spin_unlock(q.lock_ptr);
> >
> > In this path the fixup can return -EFAIL as well, so it should drop rtmutex
> > too if it owns it. We should move the rtmutex drop into the fixup functions...
>
> Urgh, so would really like to avoid doing that, I'll have to instantly
> drag it back out again :/
Why would you have to drag it back out again? Something else you're working on?
--
Darren Hart
Intel Open Source Technology Center
[toc] | [next] | [standalone]
| From | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| Date | 2016-12-01 06:40 +0100 |
| Message-ID | <sJsg9-7Ys-3@gated-at.bofh.it> |
| In reply to | #1533805 |
On Wed, Nov 30, 2016 at 08:55:30PM -0800, Darren Hart wrote: > On Thu, Nov 24, 2016 at 04:38:08PM +0100, Peter Zijlstra wrote: > > > In this path the fixup can return -EFAIL as well, so it should drop rtmutex > > > too if it owns it. We should move the rtmutex drop into the fixup functions... > > > > Urgh, so would really like to avoid doing that, I'll have to instantly > > drag it back out again :/ > > Why would you have to drag it back out again? Something else you're working on? Yeah, the very reason I've been staring at this mess in the first place :-) So I could point you at the patches; and I will, see: https://lkml.kernel.org/r/20161021122735.GA3117@twins.programming.kicks-ass.net but the TL;DR version is that we must not rt_mutex_unlock() while holding hb->lock, because on RT hb->lock is itself a rt_mutex which gives rise to some very fun prio inversions.
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web