🇰🇷 한글 설명
Linux 커널 x86 FPU 코드에서 fpu_clone() 중 fpu_inherit_perms()가 fpregs_lock 안에서 spin_lock_irq()를 호출하여 PREEMPT_RT 커널에서 잘못된 컨텍스트 sleep 문제가 발생합니다. 수정은 fpregs_lock을 해제한 뒤 권한을 상속하도록 변경하는 것입니다.
💡 쉬운 설명
프로세스를 복제할 때 커널이 잘못된 잠금 순서로 대기하여 실시간(PREEMPT_RT) 커널에서 경고나 오류가 발생할 수 있습니다. 이를 고쳐서 잠금을 더 일찍 풀도록 바꾼 패치입니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
x86/fpu: Drop fpregs lock before inheriting FPU permissions
Mike Galbraith reported the following against an old fork of preempt-rt
but the same issue also applies to the current preempt-rt tree.
BUG: sleeping function called from invalid context at kernel/locking/spinlock_rt.c:46
in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 1, name: systemd
preempt_count: 1, expected: 0
RCU nest depth: 0, expected: 0
Preemption disabled at:
fpu_clone
CPU: 6 PID: 1 Comm: systemd Tainted: G E (unreleased)
Call Trace:
<TASK>
dump_stack_lvl
? fpu_clone
__might_resched
rt_spin_lock
fpu_clone
? copy_thread
? copy_process
? shmem_alloc_inode
? kmem_cache_alloc
? kernel_clone
? __do_sys_clone
? do_syscall_64
? __x64_sys_rt_sigprocmask
? syscall_exit_to_user_mode
? do_syscall_64
? syscall_exit_to_user_mode
? do_syscall_64
? syscall_exit_to_user_mode
? do_syscall_64
? exc_page_fault
? entry_SYSCALL_64_after_hwframe
</TASK>
Mike says:
The splat comes from fpu_inherit_perms() being called under fpregs_lock(),
and us reaching the spin_lock_irq() therein due to fpu_state_size_dynamic()
returning true despite static key __fpu_state_size_dynamic having never
been enabled.
Mike's assessment looks correct. fpregs_lock on a PREEMPT_RT kernel disables
preemption so calling spin_lock_irq() in fpu_inherit_perms() is unsafe. This
problem exists since commit
9e798e9aa14c ("x86/fpu: Prepare fpu_clone() for dynamically enabled features").
Even though the original bug report should not have enabled the paths at
all, the bug still exists.
fpregs_lock is necessary when editing the FPU registers or a task's FP
state but it is not necessary for fpu_inherit_perms(). The only write
of any FP state in fpu_inherit_perms() is for the new child which is
not running yet and cannot context switch or be borrowed by a kernel
thread yet. Hence, fpregs_lock is not protecting anything in the new
child until clone() completes and can be dropped earlier. The siglock
still needs to be acquired by fpu_inherit_perms() as the read of the
parent's permissions has to be serialised.
[ bp: Cleanup splat. ]
📍 영향받는 시스템
PREEMPT_RT 패치가 적용된 x86 Linux 커널 (fpu_clone 관련 커밋 9e798e9aa14c 이후 버전)
⚔️ 공격 벡터
로컬 사용자가 프로세스 생성(clone)을 반복 유발하여 커널 경고 또는 서비스 거부를 일으킬 수 있으나, 공격 실효성은 제한적입니다.
🛡️ 대응 방법
배포판 제공 최신 커널로 업데이트하거나 해당 수정 커밋(fpu_inherit_perms에서 fpregs_lock 해제)이 포함된 커널을 적용합니다.
🔧 검증 코드
출력된 커널 버전이 배포판의 수정 포함 버전(업데이트 날짜/패키지 changelog 기준)보다 최신인지 확인하고, 실시간 커널이라면 uname -v에 PREEMPT_RT 표시 여부를 함께 점검합니다.