All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tina Zhang" <zhang_wei@open-hieco.net>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v2 4/8] KVM: nSVM: Propagate hardware DecodeAssist bytes to VMCB12
Date: Tue, 14 Jul 2026 05:32:23 +0000	[thread overview]
Message-ID: <20260714053223.776471F000E9@smtp.kernel.org> (raw)
In-Reply-To: <fa4f6cd7845aa6bc86cce8547bddc3ec60a8684f.1783999988.git.zhang_wei@open-hieco.net>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Hardware DecodeAssist bytes are not propagated to VMCB12 for intercepted #PF exits when KVM reflects the page fault, breaking the feature.
- [Medium] KVM reads control fields directly from guest-controlled memory (VMCB12) to determine if DecodeAssist bytes should be copied, creating a TOCTOU race condition.
--

--- Patch [4]: [PATCH v2 4/8] KVM: nSVM: Propagate hardware DecodeAssist bytes to VMCB12 ---
commit 3aed32a695a3f569675b1941e25ebc814c2dc09d
Author: Tina Zhang <zhang_wei@open-hieco.net>

KVM: nSVM: Propagate hardware DecodeAssist bytes to VMCB12

When DecodeAssists is exposed to L1, copy fresh hardware instruction
bytes from VMCB02 to VMCB12 for data #NPF and intercepted #PF VM-Exits.
Clear VMCB12's instruction-byte state for instruction-fetch faults,
unrelated exits, and exits without fresh VMCB02 state so that stale bytes
are not exposed to L1.

> diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
> index 70e2ee3af78b2..9e12eab7eed97 100644
> --- a/arch/x86/kvm/svm/nested.c
> +++ b/arch/x86/kvm/svm/nested.c
[ ... ]
> +static bool nested_svm_vmexit_supports_insn_bytes(struct kvm_vcpu *vcpu,
> +						  const struct vmcb *vmcb12)
> +{
> +	u64 exit_code = vmcb12->control.exit_code;
> +
> +	if (!guest_cpu_cap_has(vcpu, X86_FEATURE_DECODEASSISTS))
> +		return false;
> +
> +	if (exit_code != SVM_EXIT_NPF &&
> +	    exit_code != SVM_EXIT_EXCP_BASE + PF_VECTOR)
> +		return false;
> +
> +	return !(vmcb12->control.exit_info_1 & PFERR_FETCH_MASK);

[Severity: Medium]
Could this create a TOCTOU race condition by reading control fields directly
from guest-controlled memory? 

Because vmcb12 is mapped to guest physical memory, a malicious L1 guest on a
sibling vCPU could concurrently modify these fields. For instance, changing
the exit code to SVM_EXIT_NPF after KVM has already populated it.

Would this trick KVM into bypassing the intended security clearing logic,
thereby leaking DecodeAssist bytes for unrelated exits that were supposed to
be scrubbed? Should KVM read these fields from the trusted host-managed
vmcb02 instead?

> +}
> +
> +/*
> + * Rebuild VMCB12's DecodeAssist bytes for the nested VM-Exit.  Use fresh
> + * hardware VMCB02 state when available; otherwise report a zero byte count.
> + */
> +static void nested_svm_update_vmcb12_insn_bytes(struct kvm_vcpu *vcpu,
> +						struct vmcb *vmcb12,
> +						struct vmcb *vmcb02)
> +{
> +	struct vcpu_svm *svm = to_svm(vcpu);
> +	bool vmcb02_insn_bytes_fresh = svm->nested.vmcb02_insn_bytes_fresh;
> +
> +	svm->nested.vmcb02_insn_bytes_fresh = false;
> +
> +	nested_svm_clear_insn_bytes(vmcb12);
> +
> +	if (!nested_svm_vmexit_supports_insn_bytes(vcpu, vmcb12))
> +		return;
> +
> +	if (vmcb02_insn_bytes_fresh)
> +		nested_svm_copy_insn_bytes(vmcb12, vmcb02);

[Severity: High]
Does KVM fail to propagate hardware DecodeAssist bytes for intercepted #PF
exits when it reflects the page fault?

When L0 intercepts a #PF and reflects it to L1 via
nested_svm_inject_exception_vmexit():

nested_svm_inject_exception_vmexit() {
    ...
    vmcb->control.exit_code = SVM_EXIT_EXCP_BASE + ex->vector;
    ...
    nested_svm_vmexit(svm);
}

It seems nested_svm_inject_exception_vmexit() fails to set the
vmcb02_insn_bytes_fresh flag. Because the flag remains false, the valid
hardware instruction bytes are silently dropped here instead of being copied
to VMCB12. 

Will this cause L1 hypervisors relying on DecodeAssist for #PF to receive an
empty instruction buffer and fail to decode the faulting instruction?

> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1783999988.git.zhang_wei@open-hieco.net?part=4

  reply	other threads:[~2026-07-14  5:32 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-14  5:09 [PATCH v2 0/8] KVM: nSVM: Enable DecodeAssists for nested guests Tina Zhang
2026-07-14  5:09 ` [PATCH v2 1/8] KVM: x86: Add intercept_linear_addr to x86_instruction_info Tina Zhang
2026-07-14  5:09 ` [PATCH v2 2/8] KVM: nSVM: Synthesize DecodeAssists EXITINFO for emulated intercepts Tina Zhang
2026-07-14  5:31   ` sashiko-bot
2026-07-14  5:09 ` [PATCH v2 3/8] KVM: nSVM: Track fresh VMCB02 DecodeAssist bytes Tina Zhang
2026-07-14  5:30   ` sashiko-bot
2026-07-14  5:10 ` [PATCH v2 4/8] KVM: nSVM: Propagate hardware DecodeAssist bytes to VMCB12 Tina Zhang
2026-07-14  5:32   ` sashiko-bot [this message]
2026-07-14  5:10 ` [PATCH v2 5/8] KVM: nSVM: Use emulator bytes for synthesized nested #NPF/#PF Tina Zhang
2026-07-14  5:32   ` sashiko-bot
2026-07-14  5:10 ` [PATCH v2 6/8] KVM: nSVM: Fetch missing DecodeAssist bytes for synthesized #NPF/#PF Tina Zhang
2026-07-14  5:45   ` sashiko-bot
2026-07-14  5:10 ` [PATCH v2 7/8] KVM: nSVM: Advertise DecodeAssists to L1 Tina Zhang
2026-07-14  5:10 ` [PATCH v2 8/8] KVM: selftests: Add nested SVM DecodeAssists test Tina Zhang
2026-07-14  5:29   ` 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=20260714053223.776471F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=zhang_wei@open-hieco.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.