From nobody Mon Feb 9 16:17:52 2026 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (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 CDEB632AADE for ; Thu, 13 Nov 2025 22:56:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763074605; cv=none; b=AdxFKMzuq0BaR9eVLL7PKhtGZH/aJ4Fe+zPMweed1djjVSNwDSshjeDI6gBX2QctB5v14W5DTqBwCZbYC6KIvGy04ah9wd3tpozSlpJXCpPTrja9iIigY2+x/GioSgN0X2URdv3v61HVGZciF9ws3YrAXDsrPulhBMI5VFaoOKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763074605; c=relaxed/simple; bh=a+s6sZNkgEmBhyZ1wdOGRI7wiOUgOGhVQHVBCdK4J8Q=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=eUqmUGaRSWtUjhAE08k+6cE5l42RkJaWUom2qfRtzPKHJ2JHVZC2Cg4hBh7MPqWkftRYmYOaH1qHcBwP4Rlbre7hdx88euPlXoFfeKLZoV0Qhpylc5Av/GeYa0lPzuvbb0zd83NZTfNIDeYxxNl3i1/Yv0MnKt0M0OBQ9MIA+jI= 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=XLF/H1se; arc=none smtp.client-ip=209.85.214.201 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="XLF/H1se" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-297b35951b7so18135595ad.3 for ; Thu, 13 Nov 2025 14:56:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763074603; x=1763679403; 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=mHz4oN+bRmjr/Tq43pRV+YXBpy16+hTvzgAeUQ/5hJU=; b=XLF/H1sefUQgRYonaKzLHXfznh62AUf/0YB9jSmqZTcAkl7VhloeCFlB2ERuiZPfs4 y8WI96oxdZ1ITX3nZnuhOISOrrR42wAXoTifeLtqxPZNZM1XixfhWqbaKho46bpDeIMX sLzI0+gSxhbxqUupSCDnmD1UUtjCWRPB0I9MeddDeVYmC92gjDfMzGbAxpimaHJsnvgJ Qm2JPWaUjjQRYH2oQxj21XlEZKCH7bfZ7XcPdUCX8DqxCmcQCXH6dRflCar68VVlIfbN McxW/ChMNMaPD82QZB0IZUJJP1Xg/N3k4azzN5VPJF2rbfUjoxjJw5TFEWqZHFe0g0IS tw7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763074603; x=1763679403; 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=mHz4oN+bRmjr/Tq43pRV+YXBpy16+hTvzgAeUQ/5hJU=; b=XoH+0f1HDKfBGXSufqMutx8Vv6fwcuM6utcYHlYxXV9/WPN6YAIChB8xjd2fJE1all 3CjbFZKYM4jG1QgNXzlBih2Wm4IXF90FfnZpdEF+o+nSKA0edyHqDjEEU3k1ZRM9NGBU eUeXO9/XrqTHiVSGlm/PrU/k2zOBvhBjqmU6fUTqqDyX91nJ5SmxShZuQsI8sY2R4aS/ gjHILiW/SgpC8/3j+HQRmeTybbJ7iysuRlt5UlKWZ2V2N/XzTpGOHEr06CNHzuZYb0Lb G6O73gWojFoS3l2HX7zihJG8pT4NrSnItqTj5jYdWxFQ0pwpdVjQgQpER9POiHXM6SH2 auJQ== X-Forwarded-Encrypted: i=1; AJvYcCXUaOk1ek0YNLu0W8GkEx65cEUSRrpkDYaS5lvtiIQaapLfLIaauhbzGLsPReJDNPSh9Uy1uc5IIN8Db7M=@vger.kernel.org X-Gm-Message-State: AOJu0Yzj96/xfnYfrdh+ypJaTEtUEgFWkqskJsRdu25UntiEI5J7h5JW FlZuq1h1r2DkC7L/sjvvGUVB0uqLl/KtP34And6tl0Oms9quBJAjxoHBJxVFUIVHB0ix85aB38H QtDK+ew== X-Google-Smtp-Source: AGHT+IEO37c5pwPK2cMLUV9F0xRjUgNCC9Jy0Xa4OyxYda5fCXX6UpbBlg6x0BhMofP9nToBEj/Ouj9X0QU= X-Received: from plot13.prod.google.com ([2002:a17:902:8c8d:b0:295:fb8:7fb1]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:d502:b0:295:586d:677d with SMTP id d9443c01a7336-2986a74185fmr6475565ad.41.1763074603172; Thu, 13 Nov 2025 14:56:43 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 13 Nov 2025 14:56:21 -0800 In-Reply-To: <20251113225621.1688428-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: <20251113225621.1688428-1-seanjc@google.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog Message-ID: <20251113225621.1688428-10-seanjc@google.com> Subject: [PATCH 9/9] 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 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 85bc99f93275..308c70b6924e 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3467,6 +3467,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.rc1.455.g30608eb744-goog