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=1796444178; b=NF+q7iIxVJo4nSzqLR53Ygh6vTzJ7L+/v5JZ0zallnD85sN3A3MTtu09uPPLtB/tErHN Zzgm7Vkk73BqrRbccihFgAbOxivOurQqADkeXnaQ/LNkgrmddsxD8Ter3YBJPb/UnyMse IlONUW0YEKZcSIn0lBAO0vCcsH9VGGA8ZaFzK7NO0T5qbqVqh0D0rba4TapvjLjtu2Vl7 Pb2hG3ZwxKXY7TshTC8roo1JDK/FKIxHNwN5QE9xIuS4DmKhwWkWn5ARiU2wI006UUuYP LBMzeaIWVMUK/VBEZ1/RcrhkcZ5jh0A9KmtyN+I9uloU2M395hyr73u+Fuw/YH2owMA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796444178; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=OyzWvy4k8XLm81UqqRprCPv0bZ+XCYJYG5/mgUA4al4=; b=luVP1B8vhRHKZ+oXmo793cpR6SjTeb2S1/0xR6l+5TUbAhNMClLCoNqc0QZ1ZPhxbDqz KgERX4QrJ93Uum9//oSv3iyAI879ZsfrFEF9j+x5LY7Y7njw3xGxt80Y3Z6Q9v86+UzDT CZ3ehqq7n3kySXyjQ18rkhXpcb7YpQ1x7UTW1a/g49TXvRj/GCz2n9jxE1up2lAgsAPHJ k6l+J2eQao4gdAF3yZOVqF7oj+sJAA+wlkvb4HTfQCol7ZZi6ULPifmdFX5Kt95JiZMEg Lel8fJTzgx32wijgWSe8bfN2S0pelhK1BejN+eqv9DLJLSLdcuQR5gYP5NOSbN9taNg== 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=Mfw0omiy; 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 42D9B606A330 for ; Sat, 5 Dec 2026 04:16:18 +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=Mfw0omiy Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4DAF1F00936; Sat, 5 Dec 2026 04:16:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796444177; bh=OyzWvy4k8XLm81UqqRprCPv0bZ+XCYJYG5/mgUA4al4=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Mfw0omiyHOddlhzoIq2Jdkt4czA0C/3Dod6rGk+O69Te/qDhAZxyWvRQxSbWfIOLo I98Z+8CZeELg3dkEEIzA84RG/i+k6ZpKrlTQA7/R5HTvfJ2sx1ylD6XcGglHB692Ys bMpFUujxSeAr4Uq3w8Bh9iTkqJFzcs1OlhQnJcrF8EwMOYwOFfnjGDZ4ZmwgUFvgWT GerutBsGwOiiPhZpxe9rBIlK4U9EeQlGMFhS+L6DW/juAVfJo27/ka4PdOuoL/2G6K YdsCV3G+XSiyWGBF8RBee4TUen8s1YQ8xluNK4w3BHodqHz8/hyn0mjVXiEEFvyCmx pKXHXCy86Ashw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] KVM: x86/mmu: Check GPA bounds for 4-level TDP roots Reply-To: sashiko-reviews@lists.linux.dev To: "Wang Jiayue" Cc: kvm@vger.kernel.org In-Reply-To: <20261205034125.682290-1-akaieurus@gmail.com> References: <20261205034125.682290-1-akaieurus@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 04:16:17 +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 2 potential issues to consider: - [Medium] KVM: x86/mmu: skip of private/protected checks in kvm_mmu_do_page_fault() - [Low] kvm: x86/mmu: commit message omits trigger context and link to Fixes commit -- commit ee3d26fb92d3c5226d597ac7d5e6d4211015ddc4 Author: Wang Jiayue > KVM: x86/mmu: Check GPA bounds for 4-level TDP roots > > Check the GPA before walking a 4-level TDP root, including when > looking up an MMIO SPTE. Memslot lookup uses the full GFN, while the > SPTE walk uses only the address bits covered by the root. An > out-of-range fault can therefore resolve to an unrelated SPTE. > > Reject out-of-range prefaults with -EOPNOTSUPP. For guest faults, > emulate only shared accesses without a memslot. Return -EFAULT with > KVM_EXIT_MEMORY_FAULT for other out-of-range guest faults. > > Fixes: 10c30de01921 ("kvm: mmu: Use fast PF path for access tracking of h= uge pages when possible") > Signed-off-by: Wang Jiayue [Severity: Low] Does the commit message explain how this relates to 10c30de01921 ("kvm: mmu: Use fast PF path for access tracking of huge pages when possible"), or how = an out-of-range GPA reaches a 4-level TDP root? 10c30de01921 only added kvm_slot_dirty_track_enabled(fault->slot) in fast_page_fault(), turning an aliased noslot write fault on a huge SPTE into a NULL pointer dereference, which isn't mentioned here. The underlying 4-level TDP aliasing in kvm_mmu_do_page_fault() and handle_mmio_page_fault() also predates 10c30de01921, going back to d468d94b7baf ("KVM: x86: Dynamically calculate TDP level from max level and MAXPHYADDR") or fb72d1674d86 ("KVM: MMU: add TDP support to the KVM MMU"). Explaining how out-of-range faults reach a 4-level TDP root (e.g. a host wi= th >48-bit MAXPHYADDR using 4-level TDP, or KVM_PRE_FAULT_MEMORY) and clarifyi= ng the Fixes tag would help review and backport triage. > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index 2571dae03bdd3..9fe2dde179513 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c [ ... ] > @@ -5083,6 +5090,21 @@ static int kvm_mmu_do_page_fault(struct kvm_vcpu *= vcpu, gpa_t cr2_or_gpa, > */ > fault.gfn =3D gpa_to_gfn(fault.addr) & ~kvm_gfn_direct_bits(vcpu->kvm); > fault.slot =3D kvm_vcpu_gfn_to_memslot(vcpu, fault.gfn); > + > + /* > + * Don't walk the root for an out-of-range GPA. SPTE indexing > + * drops the upper bits, but memslot lookup doesn't, so the > + * walk would operate on SPTEs for a different GFN. > + */ > + if (unlikely(kvm_tdp_gpa_exceeds_root(vcpu->arch.mmu, fault.addr))) { > + if (fault.prefetch) > + return -EOPNOTSUPP; > + if (!fault.slot && !fault.is_private) > + return RET_PF_EMULATE; > + > + kvm_mmu_prepare_memory_fault_exit(vcpu, &fault); > + return -EFAULT; > + } > } [Severity: Medium] Can returning RET_PF_EMULATE here livelock confidential guests and bypass kvm_is_private_gfn() checks? For SEV-ES/SEV-SNP and TDX guests, x86_emulate_instruction() calls svm_check_emulate_instruction() or vt_check_emulate_instruction(), which return X86EMUL_RETRY_INSTR. With no MMIO SPTE installed, the vCPU re-enters at the same RIP in an infinite VM-exit loop instead of exiting to userspace. This also skips the fault->is_private !=3D kvm_is_private_gfn() check in kvm_mmu_faultin_pfn(). A shared fault on an unmapped out-of-range GFN mark= ed private via KVM_SET_MEMORY_ATTRIBUTES (or a PFERR_RSVD_MASK fault in KVM_X86_SW_PROTECTED_VM) emulates MMIO instead of KVM_EXIT_MEMORY_FAULT. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205034125.6822= 90-1-akaieurus@gmail.com?part=3D1