]> Git Repo - linux.git/commit - kernel/futex.c
futex: Fix more put_pi_state() vs. exit_pi_state_list() races
authorPeter Zijlstra <[email protected]>
Tue, 31 Oct 2017 10:18:53 +0000 (11:18 +0100)
committerIngo Molnar <[email protected]>
Wed, 1 Nov 2017 08:05:00 +0000 (09:05 +0100)
commit153fbd1226fb30b8630802aa5047b8af5ef53c9f
tree7ef6b0bf8b61afee4dd6ddc430ee3f512a1ba828
parent5f479447d983111c039f1d6d958553c1ad1b2ff1
futex: Fix more put_pi_state() vs. exit_pi_state_list() races

Dmitry (through syzbot) reported being able to trigger the WARN in
get_pi_state() and a use-after-free on:

raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock);

Both are due to this race:

  exit_pi_state_list() put_pi_state()

  lock(&curr->pi_lock)
  while() {
pi_state = list_first_entry(head);
hb = hash_futex(&pi_state->key);
unlock(&curr->pi_lock);

dec_and_test(&pi_state->refcount);

lock(&hb->lock)
lock(&pi_state->pi_mutex.wait_lock) // uaf if pi_state free'd
lock(&curr->pi_lock);

....

unlock(&curr->pi_lock);
get_pi_state(); // WARN; refcount==0

The problem is we take the reference count too late, and don't allow it
being 0. Fix it by using inc_not_zero() and simply retrying the loop
when we fail to get a refcount. In that case put_pi_state() should
remove the entry from the list.

Reported-by: Dmitry Vyukov <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Reviewed-by: Thomas Gleixner <[email protected]>
Cc: Gratian Crisan <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: [email protected]
Cc: syzbot <bot+2af19c9e1ffe4d4ee1d16c56ae7580feaee75765@syzkaller.appspotmail.com>
Cc: [email protected]
Cc: <[email protected]>
Fixes: c74aef2d06a9 ("futex: Fix pi_state->owner serialization")
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
kernel/futex.c
This page took 0.054686 seconds and 4 git commands to generate.