Re: [PATCH -v4 01/10] futex: Fix potential use-after-free in FUTEX_REQUEUE_PI

From: Darren Hart
Date: Fri Dec 16 2016 - 19:00:01 EST


On Tue, Dec 13, 2016 at 09:36:39AM +0100, 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().

I believe this is unchanged from the previous version I reviewed. My only
comment would be possibly noting in the commit message that in addition to
EFAULT, ENOMEM and EHWPOISON from fixup_owner...fixup_user_fault() will now also
result in the unlock, we saw no reason to handle those cases differently, but in
case someone goes looking for the change, good to have it documented.

This passed my minimal testing (selftests/futex/functional in CI with kvm on a
dual socket Xeon "cpus=20,sockets=2,cores=5,threads=2").

Reviewed-by: Darren Hart <dvhart@xxxxxxxxxxxxxxx>

--
Darren Hart
Intel Open Source Technology Center