Skip to content

futex/requeue: Fix requeue PI races

Yao Kai lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 5 repliesIn review
  2. v12 patches 12 repliesSuperseded

Changes in v2 from the cover letter

- Replace the scheduler helper split in patch 1 with rt_mutex_pre_schedule()/rt_mutex_post_schedule() directly around rt_mutex_wait_proxy_lock().
- Expand patch 2's comment and changelog to explain why the saved-task wakeup covers rcuwait without losing a wakeup.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2futex/requeue: Fix rtmutex schedule preparation for requeue PIkernel/futex/requeue.c+8 -05 replies
2/2futex/requeue: Prevent rcuwait use-after-free during requeue PIkernel/futex/requeue.c+10 -20 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/2] futex/requeue: Fix requeue PI races

Hi,

This series fixes two independent issues in the requeue PI wait path.

Patch 1 restores rtmutex scheduling preparation when the temporary removal of futex_q during requeue causes futex_do_wait() to skip schedule(), while the proxy waiter still has to block on the target rtmutex.

Patch 2 prevents the requeue side from accessing the waiter's stack-based futex_q after publishing Q_REQUEUE_PI_LOCKED. The saved-task wakeup in requeue_pi_wake_futex() also covers a waiter blocked in the rcuwait synchronization path.

Changes since v1:
- Replace the scheduler helper split in patch 1 with rt_mutex_pre_schedule()/rt_mutex_post_schedule() directly around rt_mutex_wait_proxy_lock().
- Expand patch 2's comment and changelog to explain why the saved-task wakeup covers rcuwait without losing a wakeup.

Thanks to Sebastian for the review and for suggesting the simpler fix for patch 1.

v1:
https://lore.kernel.org/r/[email protected]

Testing:
- Build-tested with non-RT and PREEMPT_RT configurations.
- The original rt_mutex_schedule() warning reproducer no longer triggers the warning.
- The original PREEMPT_RT KASAN reproducer no longer reports an invalid access.
- The futex requeue PI selftests and stress tests pass.

Yao

Yao Kai (2):
futex/requeue: Fix rtmutex schedule preparation for requeue PI futex/requeue: Prevent rcuwait use-after-free during requeue PI

 kernel/futex/requeue.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0