Skip to content

KVM: SEV: only access GHCB fields once

Paolo Bonzini kvm lkml stable 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 5 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3KVM: SEV: snapshot the GHCB before accessing itarch/x86/kvm/svm/sev.c arch/x86/kvm/svm/svm.h+61 -341 reply
2/3KVM: SEV: only access GHCB fields oncearch/x86/kvm/svm/sev.c+14 -111 reply
3/3KVM: SEV: remove ghcb variable declarationsarch/x86/kvm/svm/sev.c+12 -181 reply

Reviews trailers per patch

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

PatchPeter GondaTom Lendacky
SeriesT-b
1/3R-b
2/3R-b
3/3R-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/3] KVM: SEV: only access GHCB fields once

The VMGEXIT handler has a time-of-check/time-of-use vulnerability; due to a double fetch, the guest can exploit a race condition to invoke the VMGEXIT handler recursively. It is extremely difficult to reliably win the race ~100 consecutive times in order to cause an overflow, and the impact is usually mitigated by CONFIG_VMAP_STACK, but it ought to be fixed anyway.

One way to do so could be to snapshot the whole GHCB, but this is relatively expensive. Instead, because the VMGEXIT handler already syncs the GHCB to internal KVM state, this series makes sure that the GHCB is not read outside sev_es_sync_from_ghcb().

Patch 1 adds caching for fields that currently are not snapshotted in host memory; patch 2 ensures that the cached fields are always used, thus fixing the race. Finally patch 3 removes some local variables that are prone to incorrect use, to avoid reintroducing the race in other places.

Please review!

Paolo

Paolo Bonzini (3):
KVM: SEV: snapshot the GHCB before accessing it
KVM: SEV: only access GHCB fields once
KVM: SEV: remove ghcb variable declarations

 arch/x86/kvm/svm/sev.c | 124 ++++++++++++++++++++---------------------
 arch/x86/kvm/svm/svm.h |  26 +++++++++
 2 files changed, 87 insertions(+), 63 deletions(-)
Signature · 1 line
2.39.0