diff options
| author | Narayana Murty N <nnmlinux@linux.ibm.com> | 2026-11-06 13:37:43 +0530 |
|---|---|---|
| committer | Madhavan Srinivasan <maddy@linux.ibm.com> | 2026-11-21 13:16:10 +0530 |
| commit | bd6d2f87c2239d10bf5f37ab52b3968565528417 (patch) | |
| tree | 03d72117af0f87ca528e57db32136a2d9a9dc2ce /rust/kernel/alloc | |
| parent | 0e3d5c0408262aef599df888e9bde88d0337c1dc (diff) | |
KVM: PPC: Fix TOCTOU kernel stack disclosure via kvm_run->mmio.len
struct kvm_run is mmap'd and writable by host userspace at any time.
kvmppc_complete_mmio_load() re-reads run->mmio.len from the shared page
on the KVM_RUN completion path. A malicious userspace can:
1. Trigger a guest MMIO load; the kernel sets a valid run->mmio.len
(1, 2, 4, or 8) and exits with mmio_needed=1.
2. Rewrite run->mmio.len to an invalid value (0, 3, 5, 6, or 7)
before the next KVM_RUN ioctl.
3. On re-entry, kvm_arch_vcpu_ioctl_run() calls
kvmppc_complete_mmio_load() unconditionally.
4. No switch case matches the tampered length, so 'gpr' remains
uninitialised on the kernel stack.
5. The uninitialised value is written into a guest GPR and is
subsequently readable by the attacker via KVM_GET_REGS or
KVM_GET_ONE_REG, disclosing kernel stack contents (CWE-457/200).
The same issue affects every site that advances paddr_accessed or
passes the length to the VSX/VMX repeat-load/store helpers, since all
of them re-read run->mmio.len from the shared mapping.
Fix by introducing vcpu->arch.mmio_len, a kernel-private u8 field that
is written once in __kvmppc_handle_load() and kvmppc_handle_store()
alongside the other vcpu->arch.mmio_* fields and never touched by
userspace. All consumption sites are updated to use vcpu->arch.mmio_len:
- kvmppc_complete_mmio_load(): reads vcpu->arch.mmio_len; validates
it is exactly one of {1,2,4,8} (EMULATE_FAIL otherwise); initialises
gpr = 0 before the switch so no uninitialised value can escape even
if future code changes introduce a new path. Return type changed
from void to int (EMULATE_DONE / EMULATE_FAIL) so callers can
propagate failures.
- kvm_arch_vcpu_ioctl_run(): checks the return value and exits with
KVM_EXIT_INTERNAL_ERROR / KVM_INTERNAL_ERROR_EMULATION on failure,
matching the VSX/VMX error paths already in place.
run->internal.ndata is initialised to 0 so the union field does
not carry stale mmio data. Clear mmio_needed before completing an
in-kernel MMIO load or a userspace MMIO load on KVM_RUN re-entry,
so a completion failure cannot leave stale pending-MMIO state.
- kvmppc_handle_vsx_load(), kvmppc_handle_vsx_store(),
kvmppc_handle_vmx_load(), kvmppc_handle_vmx_store(): paddr_accessed
increments use vcpu->arch.mmio_len.
- kvmppc_emulate_mmio_vsx_loadstore() and
kvmppc_emulate_mmio_vmx_loadstore() use vcpu->arch.mmio_len for the
paddr_accessed increment and for the length passed to the load/store
helpers.
Fixes: bbf45ba57eae ("KVM: ppc: PowerPC 440 KVM implementation")
Tested-by: R Nageswara Sastry <rnsastry@linux.ibm.com>
Signed-off-by: Narayana Murty N <nnmlinux@linux.ibm.com>
Signed-off-by: Gautam Menghani <gautam@linux.ibm.com>
Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com>
Diffstat (limited to 'rust/kernel/alloc')
0 files changed, 0 insertions, 0 deletions
