test_sev() launched the guest while discarding the launch measurement and left a TODO to validate it. A full attestation-style validation is not possible from the selftest because userspace does not possess the transport keys the PSP uses to derive the measurement, so recomputing the expected value cannot be done here.
Capture the measurement returned by KVM_SEV_LAUNCH_MEASURE for SEV and SEV-ES guests and assert that it is not all zeros, which catches a PSP or plumbing failure that silently leaves the buffer untouched. SNP does not return a measurement through this path, so it is skipped. Signed-off-by: Hemanth Selam <[email protected]> --- .../selftests/kvm/x86/sev_smoke_test.c | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/x86/sev_smoke_test.c b/tools/testing/selftests/kvm/x86/sev_smoke_test.c index 6b2cbe2a90b7..9ce465b4a770 100644 --- a/tools/testing/selftests/kvm/x86/sev_smoke_test.c +++ b/tools/testing/selftests/kvm/x86/sev_smoke_test.c @@ -150,16 +150,35 @@ static void test_sync_vmsa(u32 type, u64 policy) kvm_vm_free(vm); } +static bool is_measurement_nonzero(const u8 *measurement, size_t len) +{ + size_t i; + + for (i = 0; i < len; i++) + if (measurement[i]) + return true; + + return false; +} + static void test_sev(void *guest_code, u32 type, u64 policy) { + u8 measurement[256]; struct kvm_vcpu *vcpu; struct kvm_vm *vm; struct ucall uc; vm = vm_sev_create_with_one_vcpu(type, guest_code, &vcpu); - /* TODO: Validate the measurement is as expected. */ - vm_sev_launch(vm, policy, NULL); + /* Sanity check the measurement; SNP has no measurement here. */ + if (is_sev_snp_vm(vm)) { + vm_sev_launch(vm, policy, NULL); + } else { + memset(measurement, 0, sizeof(measurement)); + vm_sev_launch(vm, policy, measurement); + TEST_ASSERT(is_measurement_nonzero(measurement, sizeof(measurement)), + "SEV launch measurement is unexpectedly all zeros"); + } for (;;) { vcpu_run(vcpu); -- 2.43.7

