Skip to content

Commit 8a1fc8d

Browse files
Niebelungen-Dgregkh
authored andcommitted
rtmutex: Use waiter::task instead of current in remove_waiter()
commit 3bfdc63 upstream. remove_waiter() is used by the slowlock paths, but it is also used for proxy-lock rollback in rt_mutex_start_proxy_lock() when invoked from futex_requeue(). In the latter case waiter::task is not current, but remove_waiter() operates on current for the dequeue operation. That results in several problems: 1) the rbtree dequeue happens without waiter::task::pi_lock being held 2) the waiter task's pi_blocked_on state is not cleared, which leaves a dangling pointer primed for UAF around. 3) rt_mutex_adjust_prio_chain() operates on the wrong top priority waiter task Use waiter::task instead of current in all related operations in remove_waiter() to cure those problems. [ tglx: Fixup rt_mutex_adjust_prio_chain(), add a comment and amend the changelog ] Fixes: 8161239 ("rtmutex: Simplify PI algorithm and make highest prio task get lock") Reported-by: Yuan Tan <yuantan098@gmail.com> Reported-by: Yifan Wu <yifanwucs@gmail.com> Reported-by: Juefei Pu <tomapufckgml@gmail.com> Reported-by: Xin Liu <bird@lzu.edu.cn> Signed-off-by: Keenan Dong <keenanat2000@gmail.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a954061 commit 8a1fc8d

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

kernel/locking/rtmutex.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,20 +1511,23 @@ static bool rtmutex_spin_on_owner(struct rt_mutex_base *lock,
15111511
*
15121512
* Must be called with lock->wait_lock held and interrupts disabled. It must
15131513
* have just failed to try_to_take_rt_mutex().
1514+
*
1515+
* When invoked from rt_mutex_start_proxy_lock() waiter::task != current !
15141516
*/
15151517
static void __sched remove_waiter(struct rt_mutex_base *lock,
15161518
struct rt_mutex_waiter *waiter)
15171519
{
15181520
bool is_top_waiter = (waiter == rt_mutex_top_waiter(lock));
15191521
struct task_struct *owner = rt_mutex_owner(lock);
1522+
struct task_struct *waiter_task = waiter->task;
15201523
struct rt_mutex_base *next_lock;
15211524

15221525
lockdep_assert_held(&lock->wait_lock);
15231526

1524-
raw_spin_lock(&current->pi_lock);
1525-
rt_mutex_dequeue(lock, waiter);
1526-
current->pi_blocked_on = NULL;
1527-
raw_spin_unlock(&current->pi_lock);
1527+
scoped_guard(raw_spinlock, &waiter_task->pi_lock) {
1528+
rt_mutex_dequeue(lock, waiter);
1529+
waiter_task->pi_blocked_on = NULL;
1530+
}
15281531

15291532
/*
15301533
* Only update priority if the waiter was the highest priority
@@ -1560,7 +1563,7 @@ static void __sched remove_waiter(struct rt_mutex_base *lock,
15601563
raw_spin_unlock_irq(&lock->wait_lock);
15611564

15621565
rt_mutex_adjust_prio_chain(owner, RT_MUTEX_MIN_CHAINWALK, lock,
1563-
next_lock, NULL, current);
1566+
next_lock, NULL, waiter_task);
15641567

15651568
raw_spin_lock_irq(&lock->wait_lock);
15661569
}

0 commit comments

Comments
 (0)