From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796343433; b=4jctfWJ10fgt3nS0f+4Th1jq1ir8VH0HVdXnUntwj4q0+X1VEPi+F2bvLZRLscm6q150 MkcxquXp4Kg9NucBp2ElKrBuHzx9JSxA9z5HYDBncylR6svkVk9Qbzx3MIXAGXX7/CEHy OU1o6ix8ZSmDgg/V08nSUMihJ7KcahjgSGJMFsTl4A2jP5isvchFcRH3AF2qwX9YLQ2qR uotgWHurY3tq0kXzYjWOMQ/ohkbLo7pyBGK5DNG4C4XsRcn/mB/WTYY9KosRVLhhKom/c Lx0/B90Yq25qJe/cCR4BtBDKQ3LxWRtL2I8aUOYvHbHXAdE/AF/9InQttkjSznlfshQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796343433; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=ZZNfgt2g7xMrS9r27NCyWuWVhbCetfilXL4qXG+IAbc=; b=A6ts/UdGuv0G825zPZJImYBMbCmM8SAXj2BpERHk8DjycWITiFRp0MMxbL6bgPM3KaME FHY+4f2iT44W9yGOx8QY7YjtLzTBE+ouqX8VqSMTi2pDioGi4SuSqMHpC4slqfwM9CbJJ 99Rlq/Clmp4UDjNUHcTkP3mHDVjIKjvGyloAqJdv3T37gN2rwdQLTj6VI02VfkbDqXeRU U946PaiIyPM2Nvt5pTMEYF2uZR4+qi4xv2oWSKFE8J6tQhVAKIp1lSoH/b1K5h6KP6++4 Eo/W9vCWcqJ8Lscu400WOXTAoxT2lvTSP87y5EB6IxknV2QNvkSqaGemBPUWkof+ubQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=erfMF4Bb; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 459C2606A330 for ; Fri, 4 Dec 2026 00:17:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=erfMF4Bb Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D5CB1F000CE; Fri, 4 Dec 2026 00:17:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796343432; bh=ZZNfgt2g7xMrS9r27NCyWuWVhbCetfilXL4qXG+IAbc=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=erfMF4BbeLdihN5jOuyMqMnyDXLm+al9jhAB0E2DATbqvxYTAMYcpY7O0WsSIA7i1 mJsXMO+EWF2cwZLz/GBA2fKjA5Z3KarmDP2eoAqngQKu/uLuGHi4/d+60ZmzgapF74 1heq8DgwiHv+3BdgoIgtK3rCmVLHwEWoP3hjqAGQmCvmU6tCd/td6Z4ZvFVRnLR6xm 1X4z1BNSpUj+ns3WCgWem1m8DvdHMkmB7A22VsOzP2zKllPBXpKgXLGjotFf9DVwQF 5In9wrycFhFwj/Va9rot0wczkp7l69hBcncViAoq478WPrcZ+34PqvqEFoOlb3taXn j/cz1eBSACVpA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 05/10] KVM: nVMX: Shadow supervisor shadow-stack control of nested EPT Reply-To: sashiko-reviews@lists.linux.dev To: =?utf-8?b?RGVubmlzIFJldcOfd2ln?= Cc: kvm@vger.kernel.org In-Reply-To: <20261204-nested-sss-v1-5-57de06f58b2b@reusswig.codes> References: <20261204-nested-sss-v1-0-57de06f58b2b@reusswig.codes> <20261204-nested-sss-v1-5-57de06f58b2b@reusswig.codes> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 00:17:11 +0000 X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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=3Dfalse - [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=C3=9Fwig 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_tmp= l.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_wal= ker *walker, > u64 walk_nx_mask =3D 0; > const int write_fault =3D access & PFERR_WRITE_MASK; > const int fetch_fault =3D 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 =3D FNAME(is_sss_access)(w, access); > + const bool dirty_fault =3D 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 =3D false. When the backing host page is read-only (such as t= he shared zero page or a CoW page), __kvm_mmu_faultin_pfn() omits FOLL_WRITE and leaves fault->map_writable =3D 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 !=3D fault->goal_level, vcpu->kvm)) > return -EIO; > =20 > - ret =3D mmu_set_spte(vcpu, fault->slot, it.sptep, gw->pte_access, > + ret =3D mmu_set_spte(vcpu, fault->slot, it.sptep, > + gw->pte_access | gw->sss_access, > base_gfn, fault->pfn, fault); > if (ret =3D=3D 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=3D0) from dirty (D= =3D1) 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_ma= sk miss a required remote TLB flush during write-protection? For a standard supervisor shadow-stack EPT leaf (R=3D1, W=3D0, bit 60=3D1), 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, s= truct kvm_mmu_page *sp, int > pte_access =3D sp->role.access; > pte_access &=3D FNAME(gpte_access)(gpte); > FNAME(protect_clean_gpte)(vcpu->arch.mmu->w, &pte_access, gpte); > + pte_access |=3D FNAME(gpte_sss_access)(vcpu->arch.mmu->w, sp->role.acce= ss, > + gpte, false); > =20 > 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=3D0 cached shadow page while the active MMU has ept_sss= =3D1 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=3D1 cached shadow page and causes unnecessary EPT violations when switching back. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204-nested-sss= -v1-0-57de06f58b2b@reusswig.codes?part=3D5