From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 474A38002A for ; Wed, 25 Nov 2026 16:49:29 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6APGmFmX015430; Wed, 25 Nov 2026 19:48:15 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6APGmFmX015430 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="bdsq+ogC" Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6APGm4cK015401 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Wed, 25 Nov 2026 19:48:04 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6APGm4cK015401 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-6b85c9f9af9so5762136a12.0 for ; Wed, 25 Nov 2026 08:48:04 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErGVIdONWmLvcQELswXdHpAj8m5wEBAPSm/zM6RNAKhSqr6XTPYeeyz1ebFf1VA0Mif7aKX19w==@openvz.org X-Gm-Message-State: APuU4Z8CDwOcgfsZTzvH3/gErTRyTZoRqDvb2rWmWMEsNQs6Lu8Yuh0M xDGQq2SI9dsJhvwYJ60VqK9Ca2wF9E5srDTVpBhDM8Q3yCgTAzenBraSXwxlshjyCn4ilrXXkH/ jB3NJ2Uh4iXXAjqwWr3PoSbt08rdlGqY9Xhr/capNCTObrd2EqeCOPw== X-Gm-Gg: AZFdTZf/AcWWEnwk/Fcm7niTRbay0EIz0fCzWvWeDN0T9nzJuwLUFCz7thzEuZu/A9A 6vo5f2cANmAol3Vk+wqeR3aXs2MOIn2ePStLmpgYA3MD45M84RiF4TcGY0wRdVjmhfFcdSBEUCK HRY7wR4yoEHxQ7kvcLiI6zDD7u0nq59lyiww/2AT4ub+BtVlUmjt3S5bv5udRiNjkBBOkDRlMZ5 2vpf00a5n63LeKjWre8xjsVJT68aWi7Rqn8rqeBJcL8AqlB+G8erCC1LuNksR+MQ0/l9rPsDIUi v/icJOkNT72dPOGYVrebketiAP2Vh3/iqJgeQ9vFV3wmLK1kRUNSTXhOqH/TOXdavUOmluKCp38 zidyk4WBJMv8iEb6a X-Received: by 2002:a05:6402:23d0:b0:6b7:a2d1:b2e8 with SMTP id 4fb4d7f45d1cf-6ba37e69e00mr12131393a12.17.1795625284419; Wed, 25 Nov 2026 08:48:04 -0800 (PST) X-Received: by 2002:a05:6402:23d0:b0:6b7:a2d1:b2e8 with SMTP id 4fb4d7f45d1cf-6ba37e69e00mr12131380a12.17.1795625283852; Wed, 25 Nov 2026 08:48:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795625283; cv=none; d=google.com; s=arc-20260327; b=Rqp+Ax2X3oPrALzrtbNoj0bCWnsSCSuPD/u7A7Oaa2h2dX9CuzEWgv0ixfGQZQJdp3 bU/5vmfrUMXIJM8N2JZAGLcB9IGaJaE7H8yNg2QCp+/QOtB2i2wS7YeQ7KIfr0gpfmnx p7sueQgUn6s4bSYM3wLdP+SvSpKouA6kK5w9SywxEru+3L0nbY93cSsEeZkfGIqpXDQA ymSd2wQfZU/kpoVrhBOAQv8gcj/NIJHeZZ6TBzO23+V+XW60h+VlPHJLqORTW55KR/BM In61/6y+1G9rFyRv3FTcpIGHKpqDPBjXoHkDiMap9NvamdpoxdXBJXHVjtivVQOlTiJq tA2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=6BBa5hOUSXn/lpcyyBloRGAyfrwxX3Ke7aR/J1tPBtc=; fh=LE/K+sLxUeUn268Z/1atilstPOROsBdjpu72a/1LaGI=; b=ondIhqtwVN/57eoJ3jbJtNZGQxmwH/l/1rFXbYUX5r217rPVv0ersn/dUQPshbpuSa chduqqChVCKGFQrwhsIliMoVVfFlXjpLk3fGCZSaPP7jKY12TsGbPaMXELCccg3JuS/i ykFrrPOXFgenTHdv+1RhsceKEGjSPbg1BBT+R580NpF755a0vDPCZVLtyb4j1ffb32nF IF+0X38bvVJTNlCO0XZ1l85kdZ3d24Nh0suYaFqohCGn5FvKnLYo+8Oyc2K98WRy25pG KCuOZSOEmplMTUxs1xSAWi4PoqsQgBi2QbR0UC/1BBfDdhqPvW+OcYIfZ/5s3NPuuEe6 WrCQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=bdsq+ogC; spf=pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=khorenko@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-6bb1309f1a6si3423876a12.88.2026.11.25.08.48.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2026 08:48:03 -0800 (PST) Received-SPF: pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=bdsq+ogC; spf=pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=khorenko@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=6BBa5hOUSXn/lpcyyBloRGAyfrwxX3Ke7aR/J1tPBtc=; b=bdsq+ogClCa6 Ta7UqrQbFFyVOJQsZdxlob1/aBwD/e1SIbMm1I1/ZlX1Wh1FllbdTCrtzCiHsQXRib4CkDOltIfb1 /M/6J4LRcUW7eIpmds2S5V4hE8dbaY/Cl095walXdqLhors99Rr7f0UfiS8FiZGwSr50+Kot1Ypmy H40kgnlf5n/KnGpke+fczypt2eszv6EE67nPjEoL3vgBXR1eJcPRj6qLpvvugdn1UncBzV2ZjltnR Z6IqmmouaGvUY+8cVAZJIT7AcpCDKPKNtw6FrCZ/s1t+q4PLRIxncmiRGskyAZ81nK15e0yEXuE42 dyUgyo/76G2OrwLveXNu9A==; Received: from ch-demo-asa.virtuozzo.com ([130.117.225.8] helo=f0.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xWG9v-00A0Rq-2b; Wed, 25 Nov 2026 17:48:02 +0100 From: Konstantin Khorenko To: Pavel Tikhomirov Date: Wed, 25 Nov 2026 17:48:02 +0100 Message-ID: <20261125164802.402895-3-khorenko@virtuozzo.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261125164802.402895-1-khorenko@virtuozzo.com> References: <20261125164802.402895-1-khorenko@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: OpenVZ devel list , "Denis V. Lunev" Subject: [Devel] [PATCH RK hci-8.0 3/3] ms/KVM: x86: Unconditionally reset MMU context when emulating INIT X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org From: Sean Christopherson [ Upstream commit c7c288d178cb0b78d3464a616b16b1aa0b316049 ] Force an MMU reset when emulating an INIT even if paging was already disabled, as the MMU page role includes guest_mode (L2), i.e. an INIT while L2 is running with CR0.PG=0 will result in KVM running L1 with a stale MMU context. Alternatively, the reset could be scoped strictly to paging being enabled or L2 being active, but SMM is also encoded in the page role. Even though it _should_ be impossible for the vCPU to be INIT'd while SMM is active, there's zero value in not handling SMM. At that point, the only scenario where KVM _doesn't_ need to reset the MMU context is on an INIT with the vCPU running in Real Mode or Unpaged Protect Mode, and while INIT in those modes is somewhat common, it's far from a hot path and re-initializing the MMU is not expensive, especially when the role isn't changing (KVM elides most of the re-configuration in that case). Note, like the Fixes commit, this bug only affects nested SVM as INIT is an unconditional intercept on VMX, i.e. it's impossible to emulate INIT while L2 is active. Temporarily keep the guest TLB flush when CR0.PG is being cleared even though it is fully redundant with the flush that is emitted on all INIT events (KVM itself only does RESET when a vCPU is being created, i.e. when CR0.PG must be '0'). Fixes: ed129ec9057f ("KVM: x86: forcibly leave nested mode on vCPU reset") Reported-by: Stefan Teodorescu Reported-by: Oren Yomtov Reported-by: Chris Mason Cc: stable@vger.kernel.org Cc: Yosry Ahmed Signed-off-by: Sean Christopherson Message-ID: <20261022015407.279870-2-seanjc@google.com> Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin (based on commit f55a3e4e08dc004b4bab7c1e9323d7e7e96e266a) https://virtuozzo.atlassian.net/browse/VSTOR-156442 Feature: fix ms/kvm ReadyKernel-specific changes: The fix is moved out of kvm_vcpu_reset() into svm_leave_nested(): - kvm_vcpu_reset() can't be livepatched: klp-build rejects its kvm_x86_call() static calls, their keys live in kvm.ko. - kvm-amd.ko can't call kvm_mmu_reset_context() from a livepatch: it does not reference that symbol today ("unexpected klp reloc for new symbol"). - svm_leave_nested() is where INIT drops guest_mode, through kvm_vcpu_reset() -> kvm_leave_nested(). Re-initialize the MMU there as a nested #VMEXIT does in nested_svm_load_cr3(): kvm_init_mmu() computes the role without guest_mode, kvm_mmu_new_pgd() moves L1 off the root built for L2. The root vmcb01 points to is then rewritten (KVM_REQ_LOAD_MMU_PGD or a reload) before the next VM-Enter, instead of the root L1 had before VMRUN, which may be freed by then. - Request MMU sync and TLB flush as nested_svm_transition_tlb_flush() does: kvm_mmu_new_pgd() may reuse a cached root and leaves both to its caller. - INIT with CR0.PG=1 is reset by kvm_vcpu_reset() anyway. With CR0.PG=0 (the bug) the role depends on guest_mode and smm only, so the one set here is final. INIT in SMM, also covered upstream, stays as is: it should be impossible. - The other callers of svm_leave_nested() (set nested state, RSM failure, KVM_SET_VCPU_EVENTS SMM change, shutdown intercept in L2, vCPU free) re-initialize the MMU too when the vCPU leaves L2. An unintercepted EFER.SVME clear by L2 gets the fix this way as well; upstream c7c288d does not cover that path. - Not covered: the shutdown intercept outside L2 with CR0.PG=0 clears vmcb01 and kvm_vcpu_reset() skips the MMU reset; upstream fixes that as a side effect. It does not involve nested state. - Blank lines of svm_leave_nested() are dropped to keep the line numbers of nested.c intact. The svm_leave_nested() variant is Fima Shevrin's. RK_BUG: VSTOR-156442 RK_CVE: CVE-2026-99312 RK_CHANGELOG: Fix a guest-to-host use-after-free in nested KVM on AMD. Co-developed-by: Fima Shevrin Signed-off-by: Fima Shevrin Reviewed-by: Pavel Tikhomirov Signed-off-by: Konstantin Khorenko --- arch/x86/kvm/svm/nested.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index b7fd2e8699987..7095ed7ce2e01 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -1339,14 +1339,14 @@ void svm_leave_nested(struct kvm_vcpu *vcpu) if (is_guest_mode(vcpu)) { svm->nested.nested_run_pending = 0; svm->nested.vmcb12_gpa = INVALID_GPA; - leave_guest_mode(vcpu); - svm_switch_vmcb(svm, &svm->vmcb01); - nested_svm_uninit_mmu_context(vcpu); vmcb_mark_all_dirty(svm->vmcb); - + kvm_init_mmu(vcpu); + kvm_mmu_new_pgd(vcpu, vcpu->arch.cr3); + kvm_make_request(KVM_REQ_MMU_SYNC, vcpu); + kvm_make_request(KVM_REQ_TLB_FLUSH_CURRENT, vcpu); if (kvm_apicv_activated(vcpu->kvm)) kvm_make_request(KVM_REQ_APICV_UPDATE, vcpu); } -- 2.43.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel