提交 e8a5f4ae 编写于 作者: T Thomas Gleixner 提交者: Yu Changchun

futex: Simplify fixup_pi_state_owner()

stable inclusion
from linux-4.19.172
commit a4649185a98eb7adbdbdfdbf61237d518861e877
category: bugfix
bugzilla: NA
CVE: CVE-2021-3347

--------------------------------

commit f2dac39d93987f7de1e20b3988c8685523247ae2 upstream

Too many gotos already and an upcoming fix would make it even more
unreadable.
Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
Acked-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: stable@vger.kernel.org
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
Signed-off-by: NYu Changchun <yuchangchun1@huawei.com>
上级 18f6682f
...@@ -2368,18 +2368,13 @@ static void unqueue_me_pi(struct futex_q *q) ...@@ -2368,18 +2368,13 @@ static void unqueue_me_pi(struct futex_q *q)
spin_unlock(q->lock_ptr); spin_unlock(q->lock_ptr);
} }
static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q, static int __fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
struct task_struct *argowner) struct task_struct *argowner)
{ {
u32 uval, uninitialized_var(curval), newval, newtid;
struct futex_pi_state *pi_state = q->pi_state; struct futex_pi_state *pi_state = q->pi_state;
u32 uval, uninitialized_var(curval), newval;
struct task_struct *oldowner, *newowner; struct task_struct *oldowner, *newowner;
u32 newtid; int err = 0;
int ret, err = 0;
lockdep_assert_held(q->lock_ptr);
raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock);
oldowner = pi_state->owner; oldowner = pi_state->owner;
...@@ -2413,14 +2408,12 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q, ...@@ -2413,14 +2408,12 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
* We raced against a concurrent self; things are * We raced against a concurrent self; things are
* already fixed up. Nothing to do. * already fixed up. Nothing to do.
*/ */
ret = 0; return 0;
goto out_unlock;
} }
if (__rt_mutex_futex_trylock(&pi_state->pi_mutex)) { if (__rt_mutex_futex_trylock(&pi_state->pi_mutex)) {
/* We got the lock. pi_state is correct. Tell caller. */ /* We got the lock. pi_state is correct. Tell caller. */
ret = 1; return 1;
goto out_unlock;
} }
/* /*
...@@ -2435,8 +2428,7 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q, ...@@ -2435,8 +2428,7 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
* We raced against a concurrent self; things are * We raced against a concurrent self; things are
* already fixed up. Nothing to do. * already fixed up. Nothing to do.
*/ */
ret = 1; return 1;
goto out_unlock;
} }
newowner = argowner; newowner = argowner;
} }
...@@ -2467,7 +2459,6 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q, ...@@ -2467,7 +2459,6 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
* itself. * itself.
*/ */
pi_state_update_owner(pi_state, newowner); pi_state_update_owner(pi_state, newowner);
raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock);
return argowner == current; return argowner == current;
...@@ -2490,17 +2481,16 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q, ...@@ -2490,17 +2481,16 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
switch (err) { switch (err) {
case -EFAULT: case -EFAULT:
ret = fault_in_user_writeable(uaddr); err = fault_in_user_writeable(uaddr);
break; break;
case -EAGAIN: case -EAGAIN:
cond_resched(); cond_resched();
ret = 0; err = 0;
break; break;
default: default:
WARN_ON_ONCE(1); WARN_ON_ONCE(1);
ret = err;
break; break;
} }
...@@ -2510,17 +2500,26 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q, ...@@ -2510,17 +2500,26 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
/* /*
* Check if someone else fixed it for us: * Check if someone else fixed it for us:
*/ */
if (pi_state->owner != oldowner) { if (pi_state->owner != oldowner)
ret = argowner == current; return argowner == current;
goto out_unlock;
}
if (ret) /* Retry if err was -EAGAIN or the fault in succeeded */
goto out_unlock; if (!err)
goto retry;
goto retry; return err;
}
out_unlock: static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
struct task_struct *argowner)
{
struct futex_pi_state *pi_state = q->pi_state;
int ret;
lockdep_assert_held(q->lock_ptr);
raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock);
ret = __fixup_pi_state_owner(uaddr, q, argowner);
raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock); raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册