From nobody Thu Apr 2 09:29:02 2026 Received: from mail-oo1-f74.google.com (mail-oo1-f74.google.com [209.85.161.74]) (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 AFA66364050 for ; Thu, 5 Mar 2026 22:27:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772749623; cv=none; b=fO4bGVbrG7gHFNa03sV7HVI7Lwn0T6Ly6xxYp7D7n8nSO+QBxw4GLOCsMJVV3SqfZLIO6QvpbEsm/fbC2alocXd2xQuo2LN9xqgudOGrpGU8ojaTBRBdeMKaYP4zb2OTYya7ay9zo2y92W+t8yTXxhUv78avKk/bTA90K4KHlwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772749623; c=relaxed/simple; bh=QYpfE9Bp+VZ43WxgiWmgZ8DPxnJQhn/XjQ9FpmT4AHA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=U44FuDwXiyAKMj0/IfPwDlnv6t8itm2G1LqK/GGQDyslo/P/mAmAkdaBc/5l1BQGZjOQHCM5wvSP/rvLg2zotHB5bwrULGr1SHFc1HWmVmtlwgz1+TU8r6YZakXS24BFZ5xy+vUP7Pjbur0d3JzCN18S5sHGYY+hN75+YOXYGes= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--sagis.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=cSj/KVfw; arc=none smtp.client-ip=209.85.161.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--sagis.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="cSj/KVfw" Received: by mail-oo1-f74.google.com with SMTP id 006d021491bc7-672c40f3873so141858445eaf.2 for ; Thu, 05 Mar 2026 14:27:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772749621; x=1773354421; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=vwFpu8D3VQ5vH2ngB7YkgvdL0e7mIaS+4lfFZO8V8nI=; b=cSj/KVfwaguuIYi0WT+WmKj8d4s1DQVE+2B7PbSKx202YY+PkK5SmDOYeqdQAIQeM3 2OIXFbX8jZIp/jUyjV13T9nQa8KaNGM8LeWVdBmRwD3wWLt/+v5yiaMEh7h0ZngYh3z4 f0wp6d9YDBSMUskUAzT42VjViWDFvoeOJzuRydGe0pSzi8bv0g+ULg08/MNQFqzot2lB 3glIvBSLPtxrW7S8fRcJFOb7SimrMl5Ip9Q7x6w+yiUwBtk1BWG5Ad8Rot9hAcLLrWjk Na4ejN0LcPcyMhgM07r1xbcMtAGJh9nGKRFGe1Laa6uhNIi6Cgogkm6wa6TsAwYB45Fl P3mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772749621; x=1773354421; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vwFpu8D3VQ5vH2ngB7YkgvdL0e7mIaS+4lfFZO8V8nI=; b=ad0uvpMkAaUAHemLW6QSqdDhlq4me+WyBPk1NJftviWlOVN7sI1/Kp77vsjmklahD9 5ZUO87txib31JF+rILaBXD035FIUNGBUZ27K93lEBI8TJ6hwfQNbZID6YB3C2l7d/xI+ wbxrkKuZlptI2gs+sDRyqhYcCoijYatKZCJ04/aYZ2wsLXRKE3BaSokbRYfghGpPZuOJ RAHpoOeDGR9jYB/2BT1YVjNqZ2KU1KRCzm/8rGvW45lbkK7LQNKDijv0A0B6sabgXqJT X7gG484sFCWX3EJwVrZoROavLre7EPQUp+zQ1fOdJ4HJCHPJgI+WDgmoBl8nRJCg3pZv xUug== X-Forwarded-Encrypted: i=1; AJvYcCUdvSigglvxVufV8FSoiwXWFexZYS6GnDxQj9BPSrldOS479mUHkEHWhN4XGmPvI2r8+M4oyRcByZU8plc=@vger.kernel.org X-Gm-Message-State: AOJu0YymQuEz9+JNkXQNb/SPrCWgOk9XtJx76Fd+Z0iOSzPyrJwc13L4 MPrQxqL1BHki8juIApf7UwE7N5zMg4ngEIW3wJZq5fjluAILy9XOvhmV2L9/4Vm/O07TMsJO0Cd yiw== X-Received: from jagg2-n2.prod.google.com ([2002:a05:6638:c702:20b0:5ce:ce5a:92a8]) (user=sagis job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6820:179b:b0:67a:4fe9:a4b0 with SMTP id 006d021491bc7-67b9bc6ad75mr110144eaf.15.1772749620561; Thu, 05 Mar 2026 14:27:00 -0800 (PST) Date: Thu, 5 Mar 2026 22:26:27 +0000 In-Reply-To: <20260305222627.4193305-1-sagis@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260305222627.4193305-1-sagis@google.com> X-Mailer: git-send-email 2.53.0.473.g4a7958ca14-goog Message-ID: <20260305222627.4193305-3-sagis@google.com> Subject: [PATCH v4 2/2] KVM: SEV: Restrict userspace return codes for KVM_HC_MAP_GPA_RANGE From: Sagi Shahar To: Vishal Annapurve , Sean Christopherson , Paolo Bonzini , Dave Hansen , Kiryl Shutsemau , Rick Edgecombe Cc: Thomas Gleixner , Borislav Petkov , "H. Peter Anvin" , Michael Roth , Tom Lendacky , x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev, Sagi Shahar Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To align with the updated TDX api that allows userspace to request that guests retry MAP_GPA operations, make sure that userspace is only returning EINVAL or EAGAIN as possible error codes. Reviewed-by: Michael Roth Signed-off-by: Sagi Shahar --- arch/x86/kvm/svm/sev.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 3f9c1aa39a0a..04076262f087 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -3718,9 +3718,13 @@ static int snp_rmptable_psmash(kvm_pfn_t pfn) =20 static int snp_complete_psc_msr(struct kvm_vcpu *vcpu) { + u64 hypercall_ret =3D READ_ONCE(vcpu->run->hypercall.ret); struct vcpu_svm *svm =3D to_svm(vcpu); =20 - if (vcpu->run->hypercall.ret) + if (!kvm_is_valid_map_gpa_range_ret(hypercall_ret)) + return -EINVAL; + + if (hypercall_ret) set_ghcb_msr(svm, GHCB_MSR_PSC_RESP_ERROR); else set_ghcb_msr(svm, GHCB_MSR_PSC_RESP); @@ -3811,10 +3815,14 @@ static void __snp_complete_one_psc(struct vcpu_svm = *svm) =20 static int snp_complete_one_psc(struct kvm_vcpu *vcpu) { + u64 hypercall_ret =3D READ_ONCE(vcpu->run->hypercall.ret); struct vcpu_svm *svm =3D to_svm(vcpu); struct psc_buffer *psc =3D svm->sev_es.ghcb_sa; =20 - if (vcpu->run->hypercall.ret) { + if (!kvm_is_valid_map_gpa_range_ret(hypercall_ret)) + return -EINVAL; + + if (hypercall_ret) { snp_complete_psc(svm, VMGEXIT_PSC_ERROR_GENERIC); return 1; /* resume guest */ } --=20 2.53.0.473.g4a7958ca14-goog