From: sashiko-bot@kernel.org
To: "Sohil Mehta" <sohil.mehta@intel.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v4 4/7] KVM: VMX: Implement LASS violation check
Date: Thu, 06 Aug 2026 01:52:24 +0000 [thread overview]
Message-ID: <20260806015225.3A1641F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260806011536.4172258-5-sohil.mehta@intel.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] LASS enforcement for supervisor-mode instruction fetches incorrectly ignores whether SMEP is enabled.
- [High] LASS is incorrectly enforced in compatibility mode, leading to spurious #GP faults for supervisor accesses.
--
--- Patch [4]: [PATCH v4 4/7] KVM: VMX: Implement LASS violation check ---
commit 7357ad469a8f5e7cd4a7e4ed10750c1068c7cc69
Author: Zeng Guang <guang.zeng@intel.com>
KVM: VMX: Implement LASS violation check
This commit adds a VMX implementation for detecting Linear Address Space
Separation (LASS) violations during instruction emulation. It enforces
mode-based protections on emulated instruction fetches, data accesses,
and VMX/SGX ENCLS instructions. LASS enforcement relies on CR4 and RFLAGS
settings, applying restrictions selectively based on execution context.
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
[ ... ]
> @@ -8604,6 +8604,53 @@ gva_t vmx_get_untagged_addr(struct kvm_vcpu *vcpu, gva_t gva, unsigned int flags
> return (sign_extend64(gva, lam_bit) & ~BIT_ULL(63)) | (gva & BIT_ULL(63));
> }
>
> +bool vmx_is_lass_violation(struct kvm_vcpu *vcpu, gva_t gva,
> + unsigned int size, unsigned int flags)
> +{
> + const bool is_supervisor_address = !!(gva & BIT_ULL(63));
> + const bool implicit_supervisor = !!(flags & X86EMUL_F_IMPLICIT);
> + const bool fetch = !!(flags & X86EMUL_F_FETCH);
> +
> + if (!kvm_is_cr4_bit_set(vcpu, X86_CR4_LASS) || !is_long_mode(vcpu))
> + return false;
[Severity: High]
Should this check use is_64_bit_mode() instead of is_long_mode()?
If a guest is in compatibility mode with LASS and SMAP enabled, a compatibility
mode application might trigger an interrupt resulting in an implicit supervisor
access to the IDT or TSS. Since compatibility-mode linear addresses are 32-bit,
bit 63 is always 0.
Does using is_long_mode() cause the hypervisor to erroneously flag these as
LASS violations for supervisor mode, breaking 32-bit execution?
> +
> + /*
> + * INVLPG isn't subject to LASS, e.g. to allow invalidating userspace
> + * addresses without toggling RFLAGS.AC. Branch targets aren't subject
> + * to LASS in order to simplify far control transfers (the subsequent
> + * fetch will enforce LASS as appropriate).
> + */
> + if (flags & (X86EMUL_F_BRANCH | X86EMUL_F_INVLPG))
> + return false;
> +
> + if (!implicit_supervisor && vmx_get_cpl(vcpu) == 3)
> + return is_supervisor_address;
> +
> + /*
> + * LASS enforcement for supervisor-mode data accesses depends on SMAP
> + * being enabled, and like SMAP ignores explicit accesses if RFLAGS.AC=1.
> + */
> + if (!fetch) {
> + if (!kvm_is_cr4_bit_set(vcpu, X86_CR4_SMAP))
> + return false;
> +
> + if (!implicit_supervisor && (kvm_get_rflags(vcpu) & X86_EFLAGS_AC))
> + return false;
> + }
[Severity: High]
Does LASS enforcement for supervisor-mode instruction fetches require a check
for SMEP being enabled here?
According to the architecture specification, LASS applies to supervisor
instruction fetches only if SMEP is enabled, similar to how it requires
SMAP for data accesses.
If a guest OS running in 64-bit mode with CR4.LASS = 1 and CR4.SMEP = 0
performs a supervisor-mode instruction fetch from a user-mode address,
will omitting a kvm_is_cr4_bit_set(vcpu, X86_CR4_SMEP) check when fetch
is true cause a spurious #GP fault to be injected?
> +
> + /*
> + * The entire access must be in the appropriate address space. Note,
> + * if LAM is supported, @gva has already been untagged, so barring a
> + * massive architecture change to expand the canonical address range,
> + * it's impossible for a user access to straddle user and supervisor
> + * address spaces.
> + */
> + if (size && !((gva + size - 1) & BIT_ULL(63)))
> + return true;
> +
> + return !is_supervisor_address;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260806011536.4172258-1-sohil.mehta@intel.com?part=4
next prev parent reply other threads:[~2026-08-06 1:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 1:15 [PATCH v4 0/7] KVM: x86: Add LASS virtualization support Sohil Mehta
2026-08-06 1:15 ` [PATCH v4 1/7] KVM: x86: Add an emulator flag to differentiate branch targets from fetches Sohil Mehta
2026-08-06 1:15 ` [PATCH v4 2/7] KVM: x86: Use linear_read_system() to read the TSS I/O bitmap Sohil Mehta
2026-08-06 1:15 ` [PATCH v4 3/7] KVM: x86: Add LASS violation checks during instruction emulation Sohil Mehta
2026-08-06 1:15 ` [PATCH v4 4/7] KVM: VMX: Implement LASS violation check Sohil Mehta
2026-08-06 1:52 ` sashiko-bot [this message]
2026-08-07 1:42 ` Sohil Mehta
2026-08-06 1:15 ` [PATCH v4 5/7] KVM: x86: Virtualize LASS and advertise support to userspace Sohil Mehta
2026-08-06 1:15 ` [PATCH v4 6/7] KVM: selftests: Add coverage for LASS CPUID and CR4 handling Sohil Mehta
2026-08-06 1:15 ` [PATCH v4 7/7] selftests/x86: Add a userspace test for LASS enforcement Sohil Mehta
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=20260806015225.3A1641F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sohil.mehta@intel.com \
/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