From nobody Mon Feb 9 00:00:54 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 2D513322B84 for ; Tue, 30 Dec 2025 21:14:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767129244; cv=none; b=tppryw8pFSd/senuIcfpdZzNBZyTfOxbZiGkoP05OVf1sUJddr0mq/MoCgQmNvFfFmGUGblfsRnfQVyNLSFdk1SyDEu/BuE/l6X99V3YTAw2Q1M67Nk5tl6QrXk7LOIQQLFR6DMAHDn0h8VshdwaCaWp2QUo6OuYU0T8QzlZKw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767129244; c=relaxed/simple; bh=EoxLt9CGajQHyT0DJbDfFAocT+/8S1HWJ5svkZDig3c=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=elSIOSUrQiT+EzMTb/et+o9lD3/F9ByFY8KKHCo1LZpmZ7vvLVP1jmRsi7WNXO2plkhamYjcEw7t6+y++4dfDqbanFt0bNro5thkmstUdxBsjXlRypQZoBaYLdo7hJ+tYYW7Jjln7RJztoO/Ulzp4wdTca8PUiCCiKKKqUMj7rA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=os5/JEm2; arc=none smtp.client-ip=209.85.216.73 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--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="os5/JEm2" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-34cc88eca7eso18607823a91.2 for ; Tue, 30 Dec 2025 13:14:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1767129242; x=1767734042; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=2l8e4mfqS4ac0ofFyg/wkIl0NnSi9zztS3YUrfbABw0=; b=os5/JEm2Ul6c6d87T7xL5TwPVMfUfOnhhZbuxICN8a7SyAi5zKvMLFi1QeWhbIMDI+ p63GLOcB5vhyOqQa1FEbsmQWbtseDJMrf5Ws1efl0pzOVbAoG/TPKE95/Dvxgw0+AwZb iw+aCBxa8s5Lg/pglHvOQksKZfdgzPMAzu7tmOqUU+dryF8JZPEP0Z29zVDXbQJRzQaN cE0k7c9+uiv3FDszjLozErFt6m1OgyK2w8W/tok7dASOybaBFPdTR1QoO7804Oxv7/QD tjOYEtJsahAGJTsUNirKFfsUYQkDY9kL5wCKw+EKGoSE6OngI6f+FbcVLxkeUzB4yGw+ sxZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767129242; x=1767734042; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2l8e4mfqS4ac0ofFyg/wkIl0NnSi9zztS3YUrfbABw0=; b=rTZs5KarjTs4ZGbOLPlNmPtuwQBXp13zrdYTh6yh3u4vStoR14NwG34qvnrJ7M91eg eKhO0zg73Q/sBpEK7PuDsc6QuTB4OsjsGPEC3O0gukv6hbcpNqSeIVE6zItgPbfaK7Rv 4Lf+IAn0PYqfq2AVYN1mNnYUo6Gqs5Pik+g5Onm4ZjdoEJxsU32FnJ8kYNMrd2OsIugy PKndehzBDP7wCFBqCJ95nEYrXK2latmrI4/FiXS7AGcrmqP2duC+uxlpSdQJuDC2Kdh/ B6re4OqpY1zWODtUjinuBgEhijYJhpVH9Ko04ozIzs0QScv4t2SwG7SLDojow/QU0IrQ 3Sdw== X-Forwarded-Encrypted: i=1; AJvYcCXMHdPphEMluNwP4dg+ji9ktvsv8T0B0j2yWQc9HdTECc6Ee5nW7A2Xvxxr2beT4FUQ6m5r5bO0GKJ05pw=@vger.kernel.org X-Gm-Message-State: AOJu0YwYlijIc64c33TcXUX4e5mn4aGsKQColT7nE+bqGR7wQVlyVeAb HeAUPjMyaAWgjywRqcGmk8ipfODyStZ7XYKHCmxrfcEKGFYRpHdD+LdWY6EYYt4/2zBTr/dI549 3E3hnEw== X-Google-Smtp-Source: AGHT+IEsJzuAlVbFq5IPl1q5CmU3amILxSyhNqXHiYg4ksn/VgJLbcnzFFETfo0s8qcklc5ptFrdojqRGHw= X-Received: from pjbot5.prod.google.com ([2002:a17:90b:3b45:b0:34a:a5cf:dcfd]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:514b:b0:341:a9e7:e5f9 with SMTP id 98e67ed59e1d1-34e91f6759emr24551317a91.0.1767129242518; Tue, 30 Dec 2025 13:14:02 -0800 (PST) Reply-To: Sean Christopherson Date: Tue, 30 Dec 2025 13:13:46 -0800 In-Reply-To: <20251230211347.4099600-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251230211347.4099600-1-seanjc@google.com> X-Mailer: git-send-email 2.52.0.351.gbe84eed79e-goog Message-ID: <20251230211347.4099600-8-seanjc@google.com> Subject: [PATCH v2 7/8] KVM: SVM: Harden exit_code against being used in Spectre-like attacks From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini , Vitaly Kuznetsov , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li Cc: kvm@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, Jim Mattson , Yosry Ahmed Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Explicitly clamp the exit code used to index KVM's exit handlers to guard against Spectre-like attacks, mainly to provide consistency between VMX and SVM (VMX was given the same treatment by commit c926f2f7230b ("KVM: x86: Protect exit_reason from being used in Spectre-v1/L1TF attacks"). For normal VMs, it's _extremely_ unlikely the exit code could be used to exploit a speculation vulnerability, as the exit code is set by hardware and unexpected/unknown exit codes should be quite well bounded (as is/was the case with VMX). But with SEV-ES+, the exit code is guest-controlled as it comes from the GHCB, not from hardware, i.e. an attack from the guest is at least somewhat plausible. Irrespective of SEV-ES+, hardening KVM is easy and inexpensive, and such an attack is theoretically possible. Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/svm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index b97e6763839b..a75cd832e194 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3477,6 +3477,7 @@ int svm_invoke_exit_handler(struct kvm_vcpu *vcpu, u6= 4 __exit_code) if (exit_code >=3D ARRAY_SIZE(svm_exit_handlers)) goto unexpected_vmexit; =20 + exit_code =3D array_index_nospec(exit_code, ARRAY_SIZE(svm_exit_handlers)= ); if (!svm_exit_handlers[exit_code]) goto unexpected_vmexit; =20 --=20 2.52.0.351.gbe84eed79e-goog