Skip to main content

CVE-2021-47465: Vulnerability in Linux Linux

High
VulnerabilityCVE-2021-47465cvecve-2021-47465
Published: Wed May 22 2024 (05/22/2024, 06:23:25 UTC)
Source: CVE
Vendor/Project: Linux
Product: Linux

Description

In the Linux kernel, the following vulnerability has been resolved: KVM: PPC: Book3S HV: Fix stack handling in idle_kvm_start_guest() In commit 10d91611f426 ("powerpc/64s: Reimplement book3s idle code in C") kvm_start_guest() became idle_kvm_start_guest(). The old code allocated a stack frame on the emergency stack, but didn't use the frame to store anything, and also didn't store anything in its caller's frame. idle_kvm_start_guest() on the other hand is written more like a normal C function, it creates a frame on entry, and also stores CR/LR into its callers frame (per the ABI). The problem is that there is no caller frame on the emergency stack. The emergency stack for a given CPU is allocated with: paca_ptrs[i]->emergency_sp = alloc_stack(limit, i) + THREAD_SIZE; So emergency_sp actually points to the first address above the emergency stack allocation for a given CPU, we must not store above it without first decrementing it to create a frame. This is different to the regular kernel stack, paca->kstack, which is initialised to point at an initial frame that is ready to use. idle_kvm_start_guest() stores the backchain, CR and LR all of which write outside the allocation for the emergency stack. It then creates a stack frame and saves the non-volatile registers. Unfortunately the frame it creates is not large enough to fit the non-volatiles, and so the saving of the non-volatile registers also writes outside the emergency stack allocation. The end result is that we corrupt whatever is at 0-24 bytes, and 112-248 bytes above the emergency stack allocation. In practice this has gone unnoticed because the memory immediately above the emergency stack happens to be used for other stack allocations, either another CPUs mc_emergency_sp or an IRQ stack. See the order of calls to irqstack_early_init() and emergency_stack_init(). The low addresses of another stack are the top of that stack, and so are only used if that stack is under extreme pressue, which essentially never happens in practice - and if it did there's a high likelyhood we'd crash due to that stack overflowing. Still, we shouldn't be corrupting someone else's stack, and it is purely luck that we aren't corrupting something else. To fix it we save CR/LR into the caller's frame using the existing r1 on entry, we then create a SWITCH_FRAME_SIZE frame (which has space for pt_regs) on the emergency stack with the backchain pointing to the existing stack, and then finally we switch to the new frame on the emergency stack.

AI-Powered Analysis

AILast updated: 07/03/2025, 05:13:18 UTC

Technical Analysis

CVE-2021-47465 is a high-severity vulnerability in the Linux kernel specifically affecting the KVM (Kernel-based Virtual Machine) implementation on PowerPC (PPC) Book3S hypervisor (HV) architectures. The issue arises from improper stack handling in the function idle_kvm_start_guest(), which was introduced as a replacement for kvm_start_guest() in commit 10d91611f426. The vulnerability stems from the misuse of the emergency stack allocated per CPU. Unlike the regular kernel stack, the emergency stack pointer (emergency_sp) points just above the allocated stack memory and requires careful frame creation before storing data. idle_kvm_start_guest() incorrectly stores critical registers such as the condition register (CR) and link register (LR) into the caller’s frame on the emergency stack without properly creating a frame first. Furthermore, the stack frame created is too small to hold all non-volatile registers, causing writes beyond the allocated emergency stack boundaries. This results in corruption of memory regions adjacent to the emergency stack, specifically 0-24 bytes and 112-248 bytes above the allocated stack. Although this corruption has gone unnoticed due to the adjacent memory typically being used by other stacks (e.g., IRQ stacks or other CPUs’ emergency stacks), it poses a risk of unpredictable behavior, data corruption, or system crashes under certain conditions. The fix involves correctly saving CR/LR into the caller’s frame using the existing stack pointer on entry, creating an adequately sized SWITCH_FRAME_SIZE frame on the emergency stack with proper backchain linkage, and switching to this new frame to prevent out-of-bounds writes. This vulnerability requires local privileges with low complexity to exploit and does not require user interaction. It impacts the integrity and availability of affected systems but does not directly affect confidentiality. The CVSS v3.1 score is 7.1 (high), reflecting these factors.

Potential Impact

For European organizations running Linux on PowerPC Book3S HV platforms with KVM enabled, this vulnerability could lead to system instability, data corruption, or denial of service due to stack corruption in critical hypervisor code. Organizations relying on virtualization for critical infrastructure, cloud services, or embedded systems using affected Linux kernel versions may experience unexpected crashes or compromised system integrity. While exploitation requires local access with some privileges, insider threats or compromised accounts could leverage this flaw to disrupt services or escalate issues within virtualized environments. The impact on availability is significant, and integrity breaches could affect workloads running on the affected hypervisor. Given the niche architecture (PowerPC Book3S), the threat is more relevant to specialized environments such as telecommunications, industrial control systems, or research institutions using PPC-based servers or appliances. European entities in these sectors should be particularly vigilant. The lack of known exploits in the wild reduces immediate risk but does not eliminate the need for prompt remediation.

Mitigation Recommendations

1. Apply the official Linux kernel patches that address CVE-2021-47465 as soon as they are available from trusted sources or Linux distributions maintaining PPC kernel branches. 2. For organizations using custom or embedded Linux kernels on PPC Book3S HV platforms, backport the fix from commit 10d91611f426 or later stable releases to ensure proper emergency stack handling. 3. Restrict local access to systems running affected kernels to trusted personnel only, minimizing the risk of exploitation by unprivileged users. 4. Monitor system logs and kernel crash reports for anomalies related to stack corruption or unexpected KVM guest failures. 5. Implement strict privilege separation and use security modules (e.g., SELinux, AppArmor) to limit the ability of local users to execute or influence hypervisor code paths. 6. Conduct thorough testing of updated kernels in staging environments before deployment to production to ensure stability and compatibility. 7. Maintain up-to-date inventory of systems running PPC Book3S HV kernels to prioritize patching and risk assessment.

Need more detailed analysis?Get Pro

Technical Details

Data Version
5.1
Assigner Short Name
Linux
Date Reserved
2024-05-22T06:20:56.198Z
Cisa Enriched
true
Cvss Version
3.1
State
PUBLISHED

Threat ID: 682d9833c4522896dcbe91ff

Added to database: 5/21/2025, 9:09:07 AM

Last enriched: 7/3/2025, 5:13:18 AM

Last updated: 8/7/2025, 2:46:29 AM

Views: 14

Actions

PRO

Updates to AI analysis are available only with a Pro account. Contact root@offseq.com for access.

Please log in to the Console to use AI analysis features.

Need enhanced features?

Contact root@offseq.com for Pro access with improved analysis and higher rate limits.

Latest Threats