🇰🇷 한글 설명
Linux 커널 RISC-V KVM에서 hrtimer 콜백이 vCPU 해제 중 완료되지 않은 상태로 실행되어 use-after-free가 발생할 수 있는 취약점입니다. 수정은 초기화된 타이머에 대해 항상 hrtimer_cancel()을 호출하여 실행 중인 콜백과 동기화하도록 합니다.
💡 쉬운 설명
가상머신의 타이머 처리 중 메모리가 해제된 뒤에도 코드가 그 메모리를 사용할 수 있는 결함입니다. 게스트 시스템이 특정 조건을 만들면 호스트 커널의 메모리 손상으로 이어질 수 있습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
RISC-V: KVM: Synchronize hrtimer callback during teardown
The non-Sstc hrtimer callback clears next_set before its final uses of
the enclosing vCPU. If teardown observes next_set as false while the
callback is still running, kvm_riscv_vcpu_timer_cancel() skips
hrtimer_cancel() and kvm_destroy_vcpus() can free the vCPU before the
callback enters kvm_riscv_vcpu_set_interrupt().
A guest can arm the timer with SBI TIME and request shutdown with SBI
legacy shutdown or SRST. A VMM that honors KVM_EXIT_SYSTEM_EVENT and
destroys the VM supplies the teardown side of the race; no post-launch
host ioctl is needed to arm or request teardown.
On upstream master 62cc90241548, generic KASAN reported:
BUG: KASAN: slab-use-after-free in do_raw_spin_lock
Write of size 4 at addr ff60000005e58898
kvm_riscv_vcpu_set_interrupt
kvm_riscv_vcpu_hrtimer_expired
__hrtimer_run_queues
hrtimer_interrupt
The object was allocated by KVM_CREATE_VCPU and freed concurrently by:
kvm_destroy_vcpus
kvm_arch_destroy_vm
kvm_destroy_vm
__fput
For deterministic validation, I added mdelay(1000) immediately after
the existing next_set = false assignment. This only widens the
existing post-clear callback window. A no-delay trace build naturally
reached the callback-after-teardown-start/before-deinit ordering in 12
of 200 runs, but 1,500 stock-kernel stress iterations did not produce a
KASAN report, so natural reproduction is timing-sensitive.
Always invoke hrtimer_cancel() for an initialized timer. Preserve the
existing -EINVAL result when the timer is no longer set, but only after
synchronizing with a running callback.
With this patch, hrtimer_cancel() blocked for the full widened callback
window before vCPU destruction. KASAN reported no error in 100
fixed-and-widened runs or 200 fix-only timing-sweep runs.
📍 영향받는 시스템
RISC-V 아키텍처에서 KVM을 사용하는 Linux 커널 (수정 전 upstream 커널 및 해당 배포판 커널)
⚔️ 공격 벡터
게스트가 SBI TIME으로 타이머를 설정하고 SBI 셧다운/SRST를 요청하면, VMM이 VM을 파괴하는 과정에서 레이스 컨디션을 유발해 커널 메모리를 손상시킬 수 있습니다.
🛡️ 대응 방법
패치된 Linux 커널 버전으로 업데이트하거나 배포판 보안 업데이트를 적용하고 재부팅합니다.
🔧 검증 코드
출력된 커널 버전을 배포판의 보안 권고문에 명시된 패치 버전과 비교하여, 같거나 높으면 수정된 것입니다. 해당 버전이 아니면 업데이트가 필요합니다.