🇰🇷 한글 설명
Linux 커널의 PREEMPT_RT 환경에서 FUTEX_CMP_REQUEUE_PI 호출 시 rcuwait 사용 후 해제(use-after-free) 취약점이 발생할 수 있습니다. 대기 중인 작업이 조기에 깨어날 경우, 재큐(requeue) 작업이 이미 해제된 스택 메모리에 접근하여 KASAN slab-out-of-bounds 오류를 유발합니다.
💡 쉬운 설명
리눅스 운영체제의 핵심 기능 중 하나인 '대기 시스템'에서 작업이 끝난 뒤 사라진 메모리 공간을 다시 사용하려고 시도할 때 발생하는 오류입니다. 이로 인해 시스템이 충돌하거나 예상치 못한 동작을 할 수 있습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
futex: Prevent rcuwait use-after-free during requeue PI
On PREEMPT_RT, FUTEX_CMP_REQUEUE_PI can trigger a KASAN report
(slab-out-of-bounds) in futex_requeue_pi_complete() invocation of
rcuwait_wake_up().
The futex_q used by futex_wait_requeue_pi() is allocated on the waiter's
stack. An early wakeup can race with a PI requeue as follows:
waiter requeue task
------ ------------
futex_wait_requeue_pi()
futex_do_wait()
schedule()
futex_requeue
futex_proxy_trylock_atomic()
futex_requeue_pi_prepare()
Q_REQUEUE_PI_NONE -> Q_REQUEUE_PI_IN_PROGRESS
* timeout/ signal wakes waiter *
futex_requeue_pi_wakeup_sync()
Q_REQUEUE_PI_IN_PROGRESS -> Q_REQUEUE_PI_WAIT
requeue_pi_wake_futex
futex_requeue_pi_complete()
cmpxchg Q_REQUEUE_PI_WAIT -> Q_REQUEUE_PI_LOCKED
rcuwait_wait_event()
if (atomic_read(&q->requeue_state) != Q_REQUEUE_PI_WAIT)
break /* no schedule() */
/* q.pi_state->owner == current */
futex_private_hash_put()
/* return from syscall */
rcuwait_wake_up(&q->requeue_wait)
/* q is gone */
futex_requeue_pi_complete() publishes Q_REQUEUE_PI_LOCKED before
calling rcuwait_wake_up(). The waiter observes this state in
rcuwait_wait_event() before invoking schedule() in rcuwait_wait_event().
Here, the waiter is free leave the syscall before requeue task can
complete the wake.
To address this race skip rcuwait_wake_up() in the Q_REQUEUE_PI_LOCKED
case.
This state is only published by requeue_pi_wake_futex(), which saves
q->task before futex_requeue_pi_complete() and wakes the waiter via
wake_up_state().
This wake is intended to wake the waiter from its futex_do_wait() sleep.
If the waiter is still sleeping there, it can not get into the
Q_REQUEUE_PI_WAIT state (and require this removed wake).
Should the waiter be woken up from futex_do_wait() by other means (as in
this example) and sleep in futex_requeue_pi_wakeup_sync() then the
wake_up_state() from requeue_pi_wake_futex() will wake it, too.
Should the waiter task terminate before wake_up_state() had a chance to
wake the task then the task pointer does not become invalid because the
futex_hash_bucket::lock is held and the task pointer is RCU protected.
[bigeasy: Updated comment and commit message]
📍 영향받는 시스템
PREEMPT_RT 패치가 적용된 Linux Kernel (특정 버전 미만)
⚔️ 공격 벡터
특수하게 설계된 futex 시스템 콜을 사용하여 대기자와 재큐 작업 간의 타이밍 경쟁 상태(Race Condition)를 유도
🛡️ 대응 방법
Linux 커널을 최신 보안 패치가 적용된 버전으로 업데이트하여 rcuwait_wake_up() 호출 로직을 수정해야 함
🔧 검증 코드
출력 결과에서 커널 버전과 PREEMPT_RT 설정 활성화 여부를 확인하여 취약한 환경인지 판단합니다.
uname -a && grep -i 'PREEMPT_RT' /boot/config-$(uname -r) 2>/dev/null