Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: amirmohammad.eftekhar@cispa.de
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: SVM: use wrmsrq_safe() when writing the nested TSC ratio MSR
Date: Wed, 22 Jul 2026 09:14:14 +0000	[thread overview]
Message-ID: <20260722091414.E842B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260722084702.1028983-2-amirmohammad.eftekhar@cispa.de>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Failing to write the MSR on an invalid TSC scaling ratio leaves the hardware MSR unmodified, allowing the guest to run with and leak the previous tenant's TSC ratio.
--

--- Patch [1]: [PATCH] KVM: SVM: use wrmsrq_safe() when writing the nested TSC ratio MSR ---
commit 1572db0bc125650e334549b4e8c1388d585aa8c9
Author: Amirmohammad Eftekhar <amirmohammad.eftekhar@cispa.de>

KVM: SVM: use wrmsrq_safe() when writing the nested TSC ratio MSR

This commit updates __svm_write_tsc_multiplier() to use wrmsrq_safe() when
writing the MSR_AMD64_TSC_RATIO. This change aims to prevent a host #GP
oops if a guest configures a composed nested TSC multiplier that exceeds the
40-bit hardware limit, falling back to a warning instead of a fault.

> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -467,7 +467,18 @@ static void __svm_write_tsc_multiplier(u64 multiplier)
>  	if (multiplier == __this_cpu_read(current_tsc_ratio))
>  		return;
>  
> -	wrmsrq(MSR_AMD64_TSC_RATIO, multiplier);
> +	/*
> +	 * multiplier is derived from the guest-influenced nested TSC scaling
> +	 * ratio and can, on a composed nested value, set bits above the 40-bit
> +	 * MSR_AMD64_TSC_RATIO field.  A plain wrmsrq() would #GP in host ring 0
> +	 * (caught only by the WRMSR extable); never let a guest-influenced
> +	 * value fault the host MSR write regardless of the compose bound.
> +	 */
> +	if (wrmsrq_safe(MSR_AMD64_TSC_RATIO, multiplier)) {
> +		pr_warn_ratelimited("SVM: rejected out-of-range TSC ratio %#llx\n",
> +				    multiplier);
> +		return;
> +	}

[Severity: High]
This is a pre-existing issue, but does returning early here leave the
hardware MSR unmodified?

If wrmsrq_safe() fails, the physical MSR_AMD64_TSC_RATIO retains its
previous value from the last VCPU scheduled on that physical core. Since the
error is caught but not propagated to abort the VCPU run, the guest could
enter with the unmodified, cross-tenant MSR value.

Because kvm_calc_nested_tsc_multiplier() in arch/x86/kvm/x86.c lacks bounds
checking (as the companion patch mentioned in the commit message is missing
from this tree), a malicious L1 guest could configure a large nested TSC
multiplier that exceeds the 40-bit hardware limit:

arch/x86/kvm/x86.c:kvm_calc_nested_tsc_multiplier() {
	if (l2_multiplier != kvm_caps.default_tsc_scaling_ratio)
		return mul_u64_u64_shr(l1_multiplier, l2_multiplier,
				       kvm_caps.tsc_scaling_ratio_frac_bits);

	return l1_multiplier;
}

Could this allow an L1 guest to run with and deduce the previous tenant's
TSC ratio?

>  	__this_cpu_write(current_tsc_ratio, multiplier);
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260722084702.1028983-2-amirmohammad.eftekhar@cispa.de?part=1

  reply	other threads:[~2026-07-22  9:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-22  8:47 [PATCH] KVM: x86: bound the composed nested TSC multiplier to the max ratio amirmohammad.eftekhar
2026-07-22  8:47 ` [PATCH] KVM: SVM: use wrmsrq_safe() when writing the nested TSC ratio MSR amirmohammad.eftekhar
2026-07-22  9:14   ` sashiko-bot [this message]
2026-07-22 13:51   ` Sean Christopherson
2026-07-22  9:16 ` [PATCH] KVM: x86: bound the composed nested TSC multiplier to the max ratio sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260722091414.E842B1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=amirmohammad.eftekhar@cispa.de \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox