[PATCH] rtmutex: Initialize waiter::ww_ctx in rt_mutex_init_waiter()

From: Sebastian Chlad

Date: Sat Dec 05 2026 - 03:48:34 EST


rt_mutex_init_waiter() does not initialize waiter::ww_ctx. Only
__rt_mutex_slowlock_locked() sets it after initializing the waiter. The
futex PI code uses on-stack waiters in futex_lock_pi() and
futex_wait_requeue_pi(), which are set up by rt_mutex_init_waiter()
alone, so their ww_ctx holds stale stack contents.

On PREEMPT_RT, rt_mutex_adjust_prio_chain() relies on ww_ctx in two
places:

- [3] disables deadlock detection when the waiter the walked task is
blocked on has a ww_ctx,
- [6] converts a detected -EDEADLK into 0 when the original waiter has
a ww_ctx.

With a stale non-NULL ww_ctx the futex PI deadlock detection, which is
enforced with RT_MUTEX_FULL_CHAINWALK, silently fails. The caller gets
success instead of -EDEADLK and both tasks stay blocked forever.

This was observed with the LTP ghostlock test (CVE-2026-43499) on a
PREEMPT_RT kernel. It sets up a 2-task cycle and requeues the waiter
with FUTEX_CMP_REQUEUE_PI onto a PI futex whose owner is blocked on a
PI futex held by the waiter. The syscall returns 1 instead of -EDEADLK.

In this case [3] clears detect_deadlock due to the stale ww_ctx and,
as both tasks have the same priority, the walk terminates at the
following equal priority check before it can reach the deadlock
detection. [6] reads the same stale field and is affected in the same
way.

Initialize ww_ctx to NULL in rt_mutex_init_waiter(). The ww_mutex slow
path keeps setting it after the initialization, so its behaviour does
not change.

Fixes: 6467822b8cc9 ("locking/rtmutex: Prevent spurious EDEADLK return caused by ww_mutexes")
Fixes: a055fcc132d4 ("locking/rtmutex: Return success on deadlock for ww_mutex waiters")
Signed-off-by: Sebastian Chlad <sebastianchlad@xxxxxxxxx>
---
kernel/locking/rtmutex_common.h | 1 +
1 file changed, 1 insertion(+)

diff --git a/kernel/locking/rtmutex_common.h b/kernel/locking/rtmutex_common.h
index c38b7bdea7b3..1f56d40c3e66 100644
--- a/kernel/locking/rtmutex_common.h
+++ b/kernel/locking/rtmutex_common.h
@@ -218,6 +218,7 @@ static inline void rt_mutex_init_waiter(struct rt_mutex_waiter *waiter)
RB_CLEAR_NODE(&waiter->tree.entry);
waiter->wake_state = TASK_NORMAL;
waiter->task = NULL;
+ waiter->ww_ctx = NULL;
}

static inline void rt_mutex_init_rtlock_waiter(struct rt_mutex_waiter *waiter)
--
2.51.0