🇰🇷 한글 설명
Linux 커널의 KVM x86/mmu 구성 요소에서 락리스(lockless) rmap 탐색 과정 중 발생하는 Use-After-Free 취약점입니다. rmap이 비어있을 때 락을 생략하는 과정에서, 데이터가 새로 생성되는 시점과 탐색을 시작하는 시점 사이의 불일치로 인해 잠금 없이 메모리 체인을 추적하게 됩니다. 이로 인해 다른 프로세스가 해당 메모리를 해제할 경우 슬랩(slab) 메모리 사용 후 해제 오류가 발생할 수 있습니다.
💡 쉬운 설명
컴퓨터의 메모리를 관리하는 과정에서, 데이터가 비어있다고 판단해 잠금 장치를 건너뛰었는데 그 사이 데이터가 갑자기 생겨나면서 문제가 발생합니다. 이로 인해 이미 삭제된 메모리 주소를 참조하게 되어 시스템이 충돌하거나 보안 문제가 생길 수 있습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
KVM: x86/mmu: Consume the locked rmap value in the lockless rmap walk
__kvm_rmap_lock() deliberately elides the rmap lock when it observes an
empty rmap. In that case kvm_rmap_lock_readonly() also re-enables
preemption and returns zero, so the caller holds neither the rmap lock
nor a preemption reference. The elision documents the invariant it
relies on:
* Elide the lock if the rmap is empty, as lockless walkers (read-only
* mode) don't need to (and can't) walk an empty rmap, nor can they add
* entries to the rmap. I.e. the only paths that process empty rmaps
* do so while holding mmu_lock for write, and are mutually exclusive.
kvm_rmap_age_gfn_range() ignores the returned value and unconditionally
enters for_each_rmap_spte_lockless(). The iterator started with
rmap_get_first(), which re-reads rmap_head->val rather than using the
value returned by the lock. If a writer populates the rmap between the
lock's read and the iterator's re-read, the aging path walks the newly
installed rmap without holding its lock.
For a KVM_RMAP_MANY rmap this leaves the walker following a
pte_list_desc chain that it never locked. A writer holding mmu_lock for
write may free that chain (e.g. kvm_zap_all_rmap_sptes() on the recycle
path, or any rmap zap) via kmem_cache_free() while the walk is in
progress, giving a slab use-after-free. Nothing serialises the two: the
aging path runs without mmu_lock when CONFIG_KVM_MMU_LOCKLESS_AGING=y,
and the rmap lock that would otherwise exclude the writer was elided.
Because the empty path re-enables preemption, the interval between the
two reads can span an arbitrary scheduling delay.
Fix the class of bug by having the lockless walk consume the value
returned by the lock instead of re-reading the rmap. Split
rmap_get_first() into __rmap_get_first(), which starts an iterator from
an already-read rmap value, and make for_each_rmap_spte_lockless() take
that value and call __rmap_get_first() directly.
kvm_rmap_age_gfn_range() passes the value returned by
kvm_rmap_lock_readonly(): when the lock was elided the value is zero,
__rmap_get_first() returns NULL, and the walk is skipped. No lockless
walker re-reads the rmap, so the lock-elision invariant cannot be
violated, and no lock()-without-paired-unlock() path is added to the
aging code.
📍 영향받는 시스템
Linux kernel (KVM enabled, CONFIG_KVM_MMU_LOCKLESS_AGING=y 설정 시)
⚔️ 공격 벡터
로컬 공격자가 KVM 환경에서 특정 메모리 관리 작업을 유도하여 Use-After-Free를 유발할 수 있음
🛡️ 대응 방법
Linux 커널을 최신 보안 패치가 적용된 버전으로 업데이트하십시오.
🔧 검증 코드
출력된 커널 버전이 해당 취약점이 수정된 패치 버전 이후인지 확인하십시오.