Skip to content

KVM: x86: Fix mostly theoretical undefined behavior

Sean Christopherson kvm lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 5 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2KVM: x86: Swap order of CPUID entry "index" vs. "significant flag" checksarch/x86/kvm/cpuid.c+2 -21 reply
2/2KVM: x86: Manually retrieve CPUID.0x1 when getting FMS for RESET/INITarch/x86/kvm/x86.c+5 -64 replies

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchJim Mattson
1/2R-b
2/2R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/2] KVM: x86: Fix mostly theoretical undefined behavior

Fix a mostly theoretical undefined behavior bug due to consuming uninitialized data when searching for a matching CPUID entry during vCPU RESET/INIT. The bug is mostly theoretical because it requires very aggressive inlining from the compiler, as well as deliberate "sabotage" from the compiler (which _is_ allowed by the C standard) in the face of known uninitialized data.

Patch 1, the "fix" that is tagged for stable, is all kinds of gross in that it doesn't directly address uninitialized data, and instead tweaks a low level CPUID helper to avoid consuming the uninitialized data. I went that route for the fix so that the fix would be easily/directy consumable downstream, as porting the fix from v5.15-rcN to literally any other buggy kernel would require hand coding the fix due to refactoring and code movement across files.

Patch 2 directly addresses the uninitialized data.

If patch 1 is unpalatable, an alternative would be to do a bit of merge magic and feed in a fix to initialize "dummy" in svm.c, which was the only buggy path prior to v5.15-rcN. However, KVM lived from 2012-2020 with what's effectively the behavior after applying patch 1, and no one noticed that the behavior was broken in 2020 until v5.15-rc1 introduced the bad behavior to VMX, i.e. opened up the validation surface to bots that presumably run the majority of their cycles on Intel CPUs.

Sean Christopherson (2):
KVM: x86: Swap order of CPUID entry "index" vs. "significant flag"
checks
KVM: x86: Manually retrieve CPUID.0x1 when getting FMS for RESET/INIT

 arch/x86/kvm/cpuid.c |  4 ++--
 arch/x86/kvm/x86.c   | 11 +++++------
 2 files changed, 7 insertions(+), 8 deletions(-)
Signature · 1 line
2.33.0.685.g46640cef36-goog