From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F3EF39C00E for ; Thu, 9 Jul 2026 16:48:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783615686; cv=none; b=LTKxnYyTCOl98czijDX6wWUp5oP57gOSRpABZy1QrJ6tLB3epfbN7SVqG4vT5lcZzvhDK/2k3lwkAxgUF0WS+n/aXL+dzqRI/zFSo+A5j71wo5/yPOCjhIuWh8bIZDr3mfEmjNmKPwIa99OeBKKpK+3nnbzGzp9O7d9yKNHkxvM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783615686; c=relaxed/simple; bh=+W/qQ2Hv4LdS1GgtpOiv5LgnBmpcq9nVszsYmmeLclI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jxb2AAfD06lxBTM2Zdi2sKa33LDuH1RZbFbJInWHS3HXvdOEIVe/+tezzW2TwM49aU8OLuYDMNLgbUOx25VmY57cZN22G9sNuN5svPKqK0s0KO2G3Jt3ImqD1hhh3ce0XxZqHCVclGrtJ0U371cOk3LbdODpA74WIgg0A6wzYbc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Vc5axp2J; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Vc5axp2J" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-8487088510aso1338b3a.0 for ; Thu, 09 Jul 2026 09:48:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783615684; x=1784220484; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=xJW2ZcrjPjx/PI62Gs3l5SSes4AcJMYW3LZ2O4zfkV4=; b=Vc5axp2JZk25IGW5hdAOhxMPu8lHl8k1x3r8+8Y6gsUe+A9tQMHU/VgOR/81b3BpAv dwMSJ4BeqIjOdicjpGdCPS6s1VhUyOCRuN03OLOMc5esDjrSRbHcDwtxHlO1s1940nRY z5WXE6LLPFoO+FnBrxmsKsxhE3yhvwQq3gdhfcGBhC18yvCjWIB6Lj9px/S3tmznr6V8 T9cERXtJnSjFV46af+uFQ52ZxcNrnjTG1CSOd5k82pvNXAeOkl8BNeB9qmyww+x2yK6g sYZmKZsuhL3pkIiJb/lEIDbat07X3QxGSY4/8d3ksvZ1GcNkUuFLKY2UbT3ABVjnEgmY u5vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783615684; x=1784220484; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=xJW2ZcrjPjx/PI62Gs3l5SSes4AcJMYW3LZ2O4zfkV4=; b=MgKk6+rYXND/RXaMO0kkJB2WMIQnQrw97emr1TKkNBY5dT0ic0jzVr2baxSWSz0+u6 INs55pgXVzz9tIZ+D6YNIK9zTqqJ8rGzVb442zc5V3XCQIXytlqwscWLpnqKim9buBoV ATwKLAu2NPFCLZny5pfbmIOHePItIQoI/JqDYzl6CJ5Cjnb1qgtfz2NYQkq2fDAKiZad Gt4SlK2uAecc33cJ8ixYmA3QDosAR2IP126t7nvWSnpwpC9Lx32N79kKen+TOxY5YDt4 2O64aRYcxCwCaMxz35AE+2n7+73WO2bo2UtakYlckKBJcB/Lodn40GhqntkyhKrAOBGT 2rpg== X-Forwarded-Encrypted: i=1; AHgh+RptTYGVPlahp6clsrVqeJitXisej4zEdx2qSYpLv5N7QOIGkIhx9QC97Un1EYoevw6H6wmkK/mRiyj5izE=@vger.kernel.org X-Gm-Message-State: AOJu0Yz1eZ8MItUijLOW5ryTMhUWLg+E7clNlimq6JA14hdmkOQiAbZg QWNM2eFyi3Qoa/Mhwlv4GrWO0YSB1t3306d4NXvt+KhIP0SFzHCgDIfg X-Gm-Gg: AfdE7ckJqcPPGiD9R8wQ+oYFUyAMZVQ/b8G9fa1v6xN5MaIbpZ9o7yieqq8YEXwSxcl rPScwAgG7rjAVpngiYX4lZikJTOor+Suscl4EjXwMnfN6JVPS92duMgcQFn/f9aVJ6YhvwSlrvQ jsQY+u1FfvPvgRPZYa14tj0zxTtGGqz1w1f4y2qw3wmaVu1Q9Fd+bny+IRyLcTOtrXPiTPNkRby ZBsW1tcggVldsl+beDhPKrkm0bE9roPwIxRV5dhENuJXZ6D1vxmy6Y3/RlTQt6ivMQpCtNubkty VxUFBvqykzuREEOW/EkQhBKi0e/+RrhZJG4DtKmtAJzw6AUXHaYDrgtQIDWRT5BI1SfH0x84Xr9 Qeb8MZGU+uo7wQvxbEQSTXIHKoYXcIQlzRulnYECB9Yyaqn5lNGdphAP4F+UN//rpyfAzQ6goG7 6c6+WdmrmU5YznnbGU1N48lT/tyPps2ZOPXYW/izbWzejSfA== X-Received: by 2002:a05:6a21:670b:b0:3b2:b1f8:c745 with SMTP id adf61e73a8af0-3c0bc93823bmr9807816637.20.1783615684503; Thu, 09 Jul 2026 09:48:04 -0700 (PDT) Received: from volcano9f8e-host.amd.com ([165.204.217.251]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13b6593c4ddsm35709287c88.1.2026.07.09.09.48.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2026 09:48:04 -0700 (PDT) From: Hemanth Selam To: seanjc@google.com, pbonzini@redhat.com, shuah@kernel.org Cc: kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Hemanth Selam Subject: [PATCH v1 2/2] KVM: selftests: SEV: Sanity check the launch measurement Date: Thu, 9 Jul 2026 22:17:51 +0530 Message-ID: <20260709164751.621326-3-hemanth.selam@gmail.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260709164751.621326-1-hemanth.selam@gmail.com> References: <20260709164751.621326-1-hemanth.selam@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- .../selftests/kvm/x86/sev_smoke_test.c | 29 +++++++++++++++++-- 1 file changed, 27 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..795b03a6b7f3 100644 --- a/tools/testing/selftests/kvm/x86/sev_smoke_test.c +++ b/tools/testing/selftests/kvm/x86/sev_smoke_test.c @@ -150,16 +150,41 @@ 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); + /* + * Capture the launch measurement and sanity check it. A full + * attestation-style validation (recomputing the expected value) isn't + * possible here as userspace does not possess the transport keys the + * PSP uses to derive the measurement; at minimum it must be non-zero. + * SNP does not return a measurement through this path, so skip it. + */ + 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