Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rtmutex: Use waiter::task instead of current in remove_waiter()

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: 8161239a8bcc ("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

authored by

Keenan Dong and committed by
Thomas Gleixner
3bfdc639 c1f49dea

+8 -5
+8 -5
kernel/locking/rtmutex.c
··· 1544 1544 * 1545 1545 * Must be called with lock->wait_lock held and interrupts disabled. It must 1546 1546 * have just failed to try_to_take_rt_mutex(). 1547 + * 1548 + * When invoked from rt_mutex_start_proxy_lock() waiter::task != current ! 1547 1549 */ 1548 1550 static void __sched remove_waiter(struct rt_mutex_base *lock, 1549 1551 struct rt_mutex_waiter *waiter) ··· 1553 1551 { 1554 1552 bool is_top_waiter = (waiter == rt_mutex_top_waiter(lock)); 1555 1553 struct task_struct *owner = rt_mutex_owner(lock); 1554 + struct task_struct *waiter_task = waiter->task; 1556 1555 struct rt_mutex_base *next_lock; 1557 1556 1558 1557 lockdep_assert_held(&lock->wait_lock); 1559 1558 1560 - raw_spin_lock(&current->pi_lock); 1561 - rt_mutex_dequeue(lock, waiter); 1562 - current->pi_blocked_on = NULL; 1563 - raw_spin_unlock(&current->pi_lock); 1559 + scoped_guard(raw_spinlock, &waiter_task->pi_lock) { 1560 + rt_mutex_dequeue(lock, waiter); 1561 + waiter_task->pi_blocked_on = NULL; 1562 + } 1564 1563 1565 1564 /* 1566 1565 * Only update priority if the waiter was the highest priority ··· 1597 1594 raw_spin_unlock_irq(&lock->wait_lock); 1598 1595 1599 1596 rt_mutex_adjust_prio_chain(owner, RT_MUTEX_MIN_CHAINWALK, lock, 1600 - next_lock, NULL, current); 1597 + next_lock, NULL, waiter_task); 1601 1598 1602 1599 raw_spin_lock_irq(&lock->wait_lock); 1603 1600 }