From: sashiko-bot@kernel.org
To: "Dennis Reußwig" <dennis@reusswig.codes>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 05/10] KVM: nVMX: Shadow supervisor shadow-stack control of nested EPT
Date: Fri, 04 Dec 2026 00:17:11 +0000 [thread overview]
Message-ID: <sashiko-outbox-248812@kernel.org> (raw)
In-Reply-To: <20261204-nested-sss-v1-5-57de06f58b2b@reusswig.codes>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] KVM: nVMX: supervisor shadow-stack reads livelock with
fault->write=false
- [High] KVM: nVMX: direct SP role omits ACC_EPT_SSS_MASK, aliasing huge
EPT pages
- [High] KVM: x86/mmu: missing TLB flush on write-protect of SSS-only
SPTEs
- [Medium] KVM: x86/mmu: FNAME(sync_spte)() uses active MMU ept_sss
instead of sp->role
--
commit 54eeafaa463b601d88199d358ce23d372c136cef
Author: Dennis Reußwig <dennis@reusswig.codes>
KVM: nVMX: Shadow supervisor shadow-stack control of nested EPT
This commit adds shadow MMU support for nested EPT supervisor shadow-stack
control (EPTP bit 7), including a new role.ept_sss bit, walker checks and
dirty-bit updates for supervisor shadow-stack accesses, bit 60 propagation
to shadow SPTEs, and EPT violation exit qualification bits 13 and 14.
> diff --git a/arch/x86/kvm/mmu/paging_tmpl.h b/arch/x86/kvm/mmu/paging_tmpl.h
> index 939a10fc11107..02421e74ec369 100644
> --- a/arch/x86/kvm/mmu/paging_tmpl.h
> +++ b/arch/x86/kvm/mmu/paging_tmpl.h
[ ... ]
> @@ -329,6 +380,12 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
> u64 walk_nx_mask = 0;
> const int write_fault = access & PFERR_WRITE_MASK;
> const int fetch_fault = access & PFERR_FETCH_MASK;
> + /*
> + * Supervisor shadow-stack accesses under EPTP bit 7 can write the page,
> + * so they set the Dirty flag even when they only read the shadow stack.
> + */
> + const bool sss_fault = FNAME(is_sss_access)(w, access);
> + const bool dirty_fault = write_fault || sss_fault;
> /*
> * Note! Track the error_code that's common to legacy shadow paging
> * and NPT shadow paging as a u16 to guard against unintentionally
[Severity: High]
Can supervisor shadow-stack reads livelock L2 because fault->write stays
false after FNAME(walk_addr_generic)() returns?
A supervisor shadow-stack read under EPTP bit 7 arrives with PFERR_SS_MASK
set and PFERR_WRITE_MASK clear, so kvm_mmu_do_page_fault() sets
fault->write = false. When the backing host page is read-only (such as the
shared zero page or a CoW page), __kvm_mmu_faultin_pfn() omits FOLL_WRITE
and leaves fault->map_writable = false. make_spte() then clears
ACC_EPT_SSS_MASK and installs a shadow SPTE with bit 60 clear, so L2
immediately takes the same EPT violation in an infinite loop.
The same livelock occurs on a write-tracked or non-unsyncable L1 GFN:
page_fault_handle_page_track() and mmu_set_spte() both gate write-protect
handling on fault->write, so KVM ignores wrprot and returns RET_PF_FIXED
(then RET_PF_SPURIOUS) instead of RET_PF_WRITE_PROTECTED.
[ ... ]
> @@ -789,7 +866,8 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault,
> if (KVM_BUG_ON(it.level != fault->goal_level, vcpu->kvm))
> return -EIO;
>
> - ret = mmu_set_spte(vcpu, fault->slot, it.sptep, gw->pte_access,
> + ret = mmu_set_spte(vcpu, fault->slot, it.sptep,
> + gw->pte_access | gw->sss_access,
> base_gfn, fault->pfn, fault);
> if (ret == RET_PF_SPURIOUS)
> return ret;
[Severity: High]
Can omitting gw->sss_access from direct_access and role.access allow direct
shadow pages of huge EPT leaves to alias across bit 60 settings?
FNAME(fetch)() initializes direct_access from gw->pte_access without
gw->sss_access, and role.access is only 4 bits wide while role.ept_sss is
unconditionally inherited by every child SP in kvm_mmu_child_role(). Two
2MB/1GB L1 EPT leaves mapping the same L1 base_gfn with identical RWX bits
under EPTP bit 7 -- one with bit 60 set and one with bit 60 clear -- compute
the same role.word and share one direct SP in mmu_page_hash. Once
mmu_set_spte() installs VMX_EPT_SSS_MASK via the bit-60-set mapping, L2
gains unauthorized supervisor shadow-stack access through the bit-60-clear
mapping, bypassing L1 EPT isolation.
shadow_mmu_get_sp_for_split() hits the same aliasing because passing
ACC_EPT_SSS_MASK into kvm_mmu_child_role() silently truncates bit 4.
validate_direct_spte() also cannot distinguish clean (D=0) from dirty (D=1)
huge EPT leaves, leaking bit 60 to clean aliases and bypassing L1 Dirty/PML
tracking. Finally, direct_pte_prefetch_many() prefetches with
sp->role.access, omitting bit 60 on prefetched 4KB siblings of a huge
supervisor shadow stack.
[Severity: High]
Can installing an ACC_EPT_SSS_MASK-only SPTE without shadow_mmu_writable_mask
miss a required remote TLB flush during write-protection?
For a standard supervisor shadow-stack EPT leaf (R=1, W=0, bit 60=1),
make_spte() sets VMX_EPT_SSS_MASK while leaving PT_WRITABLE_MASK and
shadow_mmu_writable_mask clear. If dirty logging clears VMX_EPT_SSS_MASK
under mmu_lock and defers its TLB flush until after dropping mmu_lock, a
concurrent write-protect sees all three checks in spte_write_protect()
evaluate to false:
CPU0 (dirty logging) CPU1 (shadowing)
lock(mmu_lock)
__rmap_clear_dirty()
clear VMX_EPT_SSS_MASK
unlock(mmu_lock)
lock(mmu_lock)
account_shadowed()
kvm_mmu_slot_gfn_write_protect()
spte_write_protect(..., true)
returns false <-- skips TLB flush
unlock(mmu_lock)
kvm_flush_remote_tlbs_memslot()
Because account_shadowed() (and __kvm_write_track_add_gfn()) omits
kvm_flush_remote_tlbs_gfn(), a remote vCPU with a stale TLB entry carrying
VMX_EPT_SSS_MASK can still write into the newly shadowed guest page table
via supervisor shadow-stack accesses without trapping, corrupting shadow
MMU coherence.
[ ... ]
> @@ -973,6 +1051,8 @@ static int FNAME(sync_spte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, int
> pte_access = sp->role.access;
> pte_access &= FNAME(gpte_access)(gpte);
> FNAME(protect_clean_gpte)(vcpu->arch.mmu->w, &pte_access, gpte);
> + pte_access |= FNAME(gpte_sss_access)(vcpu->arch.mmu->w, sp->role.access,
> + gpte, false);
>
> if (sync_mmio_spte(vcpu, &sp->spt[i], gfn, pte_access))
> return 0;
[Severity: Medium]
Should FNAME(sync_spte)() check sp->role.ept_sss instead of reading
is_ept_sss(vcpu->arch.mmu->w) from the active MMU?
If L1 switches between two EPTPs with the same EP4TA (bits 51:12) and
opposite bit 7 settings, the previous root remains cached in prev_roots[].
When an EPT violation is reflected to L1, nested_ept_invalidate_addr()
matches prev_roots[] solely by EPTP_PA_MASK in nested_ept_root_matches()
and calls kvm_mmu_invalidate_addr() -> __kvm_mmu_invalidate_addr() ->
kvm_sync_spte() without verifying that sp->role matches the active MMU.
Syncing an ept_sss=0 cached shadow page while the active MMU has ept_sss=1
installs ACC_EPT_SSS_MASK and VMX_EPT_SSS_MASK (plus shadow_dirty_mask)
onto a non-SSS shadow page, violating sync_spte()'s read-only invariant and
triggering spurious dirty marking. In the opposite direction, it strips
VMX_EPT_SSS_MASK from an ept_sss=1 cached shadow page and causes
unnecessary EPT violations when switching back.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-nested-sss-v1-0-57de06f58b2b@reusswig.codes?part=5
next prev parent reply other threads:[~2026-12-04 0:17 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 [this message]
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
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-248812@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