From: sashiko-bot@kernel.org
To: "Dennis Reußwig" <dennis@reusswig.codes>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 06/10] KVM: nVMX: Advertise supervisor shadow-stack control for nested EPT
Date: Fri, 04 Dec 2026 00:13:58 +0000 [thread overview]
Message-ID: <sashiko-outbox-248809@kernel.org> (raw)
In-Reply-To: <20261204-nested-sss-v1-6-57de06f58b2b@reusswig.codes>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] KVM: x86/mmu: EPT violation livelock on supervisor shadow-stack
read faults
- [High] KVM: x86/mmu: direct shadow page role omits ACC_EPT_SSS_MASK on
huge pages
- [Medium] KVM: x86/mmu: make_spte() omits shadow_mmu_writable_mask on
SSS-only SPTEs
--
commit e65818dd0c34cc8796a7568dea29e47732d607e4
Author: Dennis Reußwig <dennis@reusswig.codes>
KVM: nVMX: Advertise supervisor shadow-stack control for nested EPT
This commit advertises VMX_EPT_SSS_BIT in IA32_VMX_EPT_VPID_CAP when the
host supports shadow stacks and advanced VM-exit information, and allows
L1 to set VMX_EPTP_SSS_BIT in nested_vmx_check_eptp().
> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index dc71998554977..f7bcf18917167 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
> @@ -2930,7 +2930,12 @@ static bool nested_vmx_check_eptp(struct kvm_vcpu *vcpu, u64 new_eptp)
> }
>
> /* Reserved bits should not be set */
> - if (CC(!kvm_vcpu_is_legal_gpa(vcpu, new_eptp) || ((new_eptp >> 7) & 0x1f)))
> + if (CC(!kvm_vcpu_is_legal_gpa(vcpu, new_eptp) || ((new_eptp >> 8) & 0xf)))
> + return false;
> +
> + /* Supervisor shadow-stack control, if set, should be supported */
> + if (CC((new_eptp & VMX_EPTP_SSS_BIT) &&
> + !(vmx->nested.msrs.ept_caps & VMX_EPT_SSS_BIT)))
> return false;
>
> /* AD, if set, should be supported */
[Severity: High]
Can allowing VMX_EPTP_SSS_BIT trigger an infinite EPT violation livelock
on supervisor shadow-stack read faults?
With EPTP bit 7 set, hardware requires VMX_EPT_SSS_MASK (bit 60) on EPT02
leaf SPTEs even for read-only supervisor shadow-stack operations such as
RET or RSTORSSP. On an EPT violation for such a read,
__vt_handle_ept_violation() sets PFERR_SS_MASK without PFERR_WRITE_MASK,
so kvm_mmu_do_page_fault() leaves fault.write false.
Downstream MMU fault handling checks only fault->write:
__kvm_mmu_faultin_pfn() omits FOLL_WRITE, so a read-only host backing page
(such as a CoW page or shared zero page) resolves with map_writable = false
and make_spte() strips ACC_EPT_SSS_MASK. Similarly, on a write-tracked or
shadowed L1 GFN, page_fault_handle_page_track() returns false,
FNAME(fetch)() skips fault->write_fault_to_shadow_pgtable, and
mmu_set_spte() returns RET_PF_FIXED (then RET_PF_SPURIOUS) instead of
RET_PF_WRITE_PROTECTED while leaving bit 60 clear.
In both cases KVM resumes L2 on the same instruction with bit 60 still 0,
hanging the L2 vCPU and spinning the host CPU in an endless fault loop.
[ ... ]
> @@ -7251,9 +7256,20 @@ static void nested_vmx_setup_secondary_ctls(u32 ept_caps,
> VMX_EPTP_WB_BIT |
> VMX_EPT_INVEPT_BIT |
> VMX_EPT_EXECUTE_ONLY_BIT |
> - VMX_EPT_ADVANCED_VMEXIT_INFO_BIT;
> + VMX_EPT_ADVANCED_VMEXIT_INFO_BIT |
> + VMX_EPT_SSS_BIT;
>
> msrs->ept_caps &= ept_caps;
> +
> + /*
> + * Supervisor shadow-stack control needs shadow stacks for the
> + * guest, and advanced VM-exit information to tell supervisor
> + * from user shadow-stack accesses in EPT violations.
> + */
> + if (!kvm_cpu_cap_has(X86_FEATURE_SHSTK) ||
> + !(msrs->ept_caps & VMX_EPT_ADVANCED_VMEXIT_INFO_BIT))
> + msrs->ept_caps &= ~VMX_EPT_SSS_BIT;
[Severity: Medium]
Now that VMX_EPT_SSS_BIT is exposed, can dirty logging race with guest
page-table shadowing and skip a required remote TLB flush on SSS-only
SPTEs?
In commit "KVM: x86/mmu: Handle the EPT supervisor shadow-stack bit like a
write bit", make_spte() sets VMX_EPT_SSS_MASK for SSS-only SPTEs
(ACC_EPT_SSS_MASK without ACC_WRITE_MASK) without setting
shadow_mmu_writable_mask. Dirty-logging paths such as
kvm_get_dirty_log_protect() and kvm_mmu_slot_apply_flags() clear
VMX_EPT_SSS_MASK under mmu_lock and defer remote TLB flushes until after
dropping mmu_lock:
CPU0 CPU1
kvm_get_dirty_log_protect()
KVM_MMU_LOCK(kvm)
... -> spte_write_protect()
clears VMX_EPT_SSS_MASK
KVM_MMU_UNLOCK(kvm)
KVM_MMU_LOCK(kvm)
account_shadowed()
spte_write_protect(..., true)
returns false <-- skips TLB flush
KVM_MMU_UNLOCK(kvm)
kvm_flush_remote_tlbs_memslot()
Because shadow_mmu_writable_mask is clear, spte_write_protect(..., true)
sees is_writable_pte(), is_sss_spte(), and is_mmu_writable_spte() all
false and returns false. A remote vCPU running L2 with a stale
VMX_EPT_SSS_MASK=1 TLB entry can then perform supervisor shadow-stack
writes into the shadowed guest page table without trapping, desynchronizing
KVM's shadow page tables (and bypassing kvm_write_track consumers).
Setting shadow_mmu_writable_mask whenever make_spte() grants
VMX_EPT_SSS_MASK would preserve the dirty-logging write-protect invariant.
> msrs->ept_caps |= VMX_EPT_EXTENT_GLOBAL_BIT |
> VMX_EPT_EXTENT_CONTEXT_BIT | VMX_EPT_2MB_PAGE_BIT |
> VMX_EPT_1GB_PAGE_BIT;
[Severity: High]
Does advertising VMX_EPT_SSS_BIT alongside 2MB and 1GB nested EPT huge
pages allow L2 to bypass EPT supervisor shadow-stack isolation?
In union kvm_mmu_page_role, role.access is only 4 bits wide and cannot
store ACC_EPT_SSS_MASK (bit 4). FNAME(fetch)() omits gw->sss_access from
direct_access, and kvm_mmu_child_role() silently truncates bit 4 when
assigning role.access.
When KVM shadows L1 2MB/1GB huge pages with 4KB direct shadow pages, two
huge-page mappings of the same L1 base GFN with identical RWX bits — one
with bit 60 set and one with bit 60 clear, such as Hyper-V VTL1 vs VTL0
EPTs — collide in mmu_page_hash on the same direct shadow page. Any 4KB
SPTE populated with VMX_EPT_SSS_MASK via the SSS=1 mapping (including
across shadow_mmu_split_huge_page()) is exposed through the SSS=0 mapping,
letting L2 perform supervisor shadow-stack writes where L1 forbade them.
For the same reason, validate_direct_spte() fails to drop a cached direct
shadow page when L1 clears bit 60 without changing RWX, and INVEPT via
mmu_free_root_page() leaves those stale direct shadow pages in
mmu_page_hash for reuse.
Finally, direct_pte_prefetch_many() seeds access from sp->role.access
without ACC_EPT_SSS_MASK, so prefetched 4KB SPTEs under an SSS=1 huge page
lose bit 60 and incur extra EPT violation VM-exits.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-nested-sss-v1-0-57de06f58b2b@reusswig.codes?part=6
next prev parent reply other threads:[~2026-12-04 0:13 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 23:49 [PATCH 00/10] KVM: nVMX: Supervisor shadow-stack control for nested EPT and CET with eVMCS Dennis Reußwig
2026-12-03 23:49 ` [PATCH 01/10] KVM: nVMX: Allow CET entry/exit controls with enlightened VMCS Dennis Reußwig
2026-12-03 23:49 ` [PATCH 02/10] KVM: x86/mmu: Move TDP A/D tracking type to SPTE bits 56-57 Dennis Reußwig
2026-12-03 23:49 ` [PATCH 03/10] KVM: VMX: Report shadow-stack accesses in EPT violations as PFERR_SS Dennis Reußwig
2026-12-03 23:59 ` sashiko-bot
2026-12-03 23:49 ` [PATCH 04/10] KVM: x86/mmu: Handle the EPT supervisor shadow-stack bit like a write bit Dennis Reußwig
2026-12-04 0:16 ` sashiko-bot
2026-12-03 23:49 ` [PATCH 05/10] KVM: nVMX: Shadow supervisor shadow-stack control of nested EPT Dennis Reußwig
2026-12-04 0:17 ` sashiko-bot
2026-12-03 23:49 ` [PATCH 06/10] KVM: nVMX: Advertise supervisor shadow-stack control for " Dennis Reußwig
2026-12-04 0:13 ` sashiko-bot [this message]
2026-12-03 23:49 ` [PATCH 07/10] KVM: selftests: Add helpers for nested EPT shadow-stack and MBEC tests Dennis Reußwig
2026-12-03 23:49 ` [PATCH 08/10] KVM: selftests: Add nested EPT supervisor shadow-stack test Dennis Reußwig
2026-12-04 0:00 ` sashiko-bot
2026-12-03 23:49 ` [PATCH 09/10] KVM: selftests: Add nested EPT mode-based execute control test Dennis Reußwig
2026-12-04 0:07 ` sashiko-bot
2026-12-03 23:49 ` [PATCH 10/10] KVM: selftests: Check VMX capabilities for CET in L2 with MBEC Dennis Reußwig
2026-12-04 0:10 ` 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=sashiko-outbox-248809@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dennis@reusswig.codes \
--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