CVE-2021-47230 in Linuxinfo

Summary

by MITRE • 05/21/2024

In the Linux kernel, the following vulnerability has been resolved:

KVM: x86: Immediately reset the MMU context when the SMM flag is cleared

Immediately reset the MMU context when the vCPU's SMM flag is cleared so that the SMM flag in the MMU role is always synchronized with the vCPU's flag. If RSM fails (which isn't correctly emulated), KVM will bail without calling post_leave_smm() and leave the MMU in a bad state.

The bad MMU role can lead to a NULL pointer dereference when grabbing a shadow page's rmap for a page fault as the initial lookups for the gfn will happen with the vCPU's SMM flag (=0), whereas the rmap lookup will use the shadow page's SMM flag, which comes from the MMU (=1). SMM has an entirely different set of memslots, and so the initial lookup can find a memslot (SMM=0) and then explode on the rmap memslot lookup (SMM=1).

general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] PREEMPT SMP KASAN
KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
CPU: 1 PID: 8410 Comm: syz-executor382 Not tainted 5.13.0-rc5-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 RIP: 0010:__gfn_to_rmap arch/x86/kvm/mmu/mmu.c:935 [inline]
RIP: 0010:gfn_to_rmap+0x2b0/0x4d0 arch/x86/kvm/mmu/mmu.c:947 Code: 80 3c 20 00 74 08 4c 89 ff e8 f1 79 a9 00 4c 89 fb 4d 8b 37 44 RSP: 0018:ffffc90000ffef98 EFLAGS: 00010246 RAX: 0000000000000000 RBX: ffff888015b9f414 RCX: ffff888019669c40 RDX: 0000000000000000 RSI: 0000000000000001 RDI: 0000000000000001 RBP: 0000000000000001 R08: ffffffff811d9cdb R09: ffffed10065a6002 R10: ffffed10065a6002 R11: 0000000000000000 R12: dffffc0000000000 R13: 0000000000000003 R14: 0000000000000001 R15: 0000000000000000 FS: 000000000124b300(0000) GS:ffff8880b9b00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000000 CR3: 0000000028e31000 CR4: 00000000001526e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: rmap_add arch/x86/kvm/mmu/mmu.c:965 [inline]
mmu_set_spte+0x862/0xe60 arch/x86/kvm/mmu/mmu.c:2604 __direct_map arch/x86/kvm/mmu/mmu.c:2862 [inline]
direct_page_fault+0x1f74/0x2b70 arch/x86/kvm/mmu/mmu.c:3769 kvm_mmu_do_page_fault arch/x86/kvm/mmu.h:124 [inline]
kvm_mmu_page_fault+0x199/0x1440 arch/x86/kvm/mmu/mmu.c:5065 vmx_handle_exit+0x26/0x160 arch/x86/kvm/vmx/vmx.c:6122 vcpu_enter_guest+0x3bdd/0x9630 arch/x86/kvm/x86.c:9428 vcpu_run+0x416/0xc20 arch/x86/kvm/x86.c:9494 kvm_arch_vcpu_ioctl_run+0x4e8/0xa40 arch/x86/kvm/x86.c:9722 kvm_vcpu_ioctl+0x70f/0xbb0 arch/x86/kvm/../../../virt/kvm/kvm_main.c:3460 vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:1069 [inline]
__se_sys_ioctl+0xfb/0x170 fs/ioctl.c:1055 do_syscall_64+0x3f/0xb0 arch/x86/entry/common.c:47 entry_SYSCALL_64_after_hwframe+0x44/0xae RIP: 0033:0x440ce9

If you want to get the best quality for vulnerability data then you always have to consider VulDB.

Analysis

by VulDB Data Team • 05/21/2024

The vulnerability described in CVE-2021-47230 resides within the Linux kernel's KVM (Kernel-based Virtual Machine) subsystem, specifically affecting the x86 architecture implementation. This flaw manifests when handling the SMM (System Management Mode) flag within virtual CPU contexts, leading to a critical synchronization issue between the virtual CPU's SMM flag and the MMU (Memory Management Unit) context. The problem occurs during the transition out of SMM mode, where the kernel fails to properly reset the MMU context when the SMM flag is cleared, resulting in a mismatch between the virtual CPU's state and the MMU's internal state. This misalignment creates a dangerous condition where the MMU retains stale information about SMM status, which can lead to unpredictable behavior and system instability.

The technical root cause of this vulnerability stems from the improper handling of the SMM flag during virtual machine execution. When a virtual CPU executes the RSM (Return from System Management Mode) instruction, the kernel should ensure that the MMU context is immediately reset to reflect the new SMM flag state. However, if the RSM instruction fails to execute correctly or is not properly emulated, the kernel exits without invoking the necessary cleanup function post_leave_smm(). This leaves the MMU in an inconsistent state where the MMU role still indicates SMM mode while the virtual CPU's flag has been cleared. The mismatch becomes particularly problematic during page fault handling, as the system performs lookups using different SMM contexts, creating a scenario where the initial gfn (guest frame number) lookup operates under SMM=0 conditions while the rmap lookup uses SMM=1 conditions. This fundamental inconsistency can result in a NULL pointer dereference, as demonstrated in the kernel crash trace showing the error occurring in the __gfn_to_rmap function within the mmu.c file.

The operational impact of this vulnerability extends beyond simple system crashes, potentially enabling privilege escalation and denial of service attacks within virtualized environments. When the MMU context becomes corrupted due to the SMM flag desynchronization, any attempt to access memory mappings during page fault handling can trigger the NULL pointer dereference, leading to kernel panics and system instability. The vulnerability specifically affects KVM implementations running on x86 architectures and poses a significant risk to virtualized systems where multiple VMs share the same host kernel. The crash pattern described in the kernel logs reveals a general protection fault occurring at a non-canonical address, indicating that the system attempted to access invalid memory locations due to the corrupted MMU state. This type of vulnerability can be exploited by malicious guests to crash the host system or potentially escalate privileges, making it particularly dangerous in multi-tenant cloud environments where VM isolation is critical.

Mitigation strategies for CVE-2021-47230 focus on ensuring proper synchronization between virtual CPU flags and MMU contexts during SMM transitions. The fix implemented in the kernel involves immediately resetting the MMU context when the SMM flag is cleared, preventing the state desynchronization that leads to the NULL pointer dereference. This solution aligns with the principle of maintaining consistent internal state within virtualization layers and follows the ATT&CK framework's guidance on maintaining system integrity during privilege transitions. System administrators should prioritize applying the kernel patches that address this vulnerability, particularly in environments running KVM-based virtualization where multiple VMs may be present. The fix also emphasizes the importance of proper error handling in virtualization code, specifically around instruction emulation and state management during sensitive transitions like SMM entry and exit. Organizations should monitor their virtualized infrastructure for any signs of instability or unexpected crashes that could indicate exploitation attempts, while also ensuring that all virtualization components are updated to versions containing the relevant security patches. This vulnerability demonstrates the critical need for rigorous testing of virtualization features, particularly those involving system-level modes like SMM, to prevent subtle state management issues from becoming exploitable security flaws.

Reservation

04/10/2024

Disclosure

05/21/2024

Moderation

accepted

CPE

ready

EPSS

0.00232

KEV

no

Activities

very low

Sources

Interested in the pricing of exploits?

See the underground prices here!