Skip to content

Commit 64bb276

Browse files
sean-jcbonzini
authored andcommitted
KVM: x86/mmu: Check for shadow-present SPTE before querying A/D status
When updating accessed and dirty bits, check that the new SPTE is present before attempting to query its A/D bits. Failure to confirm the SPTE is present can theoretically cause a false negative, e.g. if a MMIO SPTE replaces a "real" SPTE and somehow the PFNs magically match. Realistically, this is all but guaranteed to be a benign bug. Fix it up primarily so that a future patch can tweak the MMU_WARN_ON checking A/D status to fire if the SPTE is not-present. Fixes: f8e1449 ("kvm: x86/mmu: Add access tracking for tdp_mmu") Cc: Ben Gardon <bgardon@google.com> Signed-off-by: Sean Christopherson <seanjc@google.com> Message-Id: <20210225204749.1512652-3-seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 2032195 commit 64bb276

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

‎arch/x86/kvm/mmu/tdp_mmu.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,12 @@ static int kvm_mmu_page_as_id(struct kvm_mmu_page *sp)
197197

198198
static void handle_changed_spte_acc_track(u64 old_spte, u64 new_spte, int level)
199199
{
200-
bool pfn_changed = spte_to_pfn(old_spte) != spte_to_pfn(new_spte);
201-
202200
if (!is_shadow_present_pte(old_spte) || !is_last_spte(old_spte, level))
203201
return;
204202

205203
if (is_accessed_spte(old_spte) &&
206-
(!is_accessed_spte(new_spte) || pfn_changed))
204+
(!is_shadow_present_pte(new_spte) || !is_accessed_spte(new_spte) ||
205+
spte_to_pfn(old_spte) != spte_to_pfn(new_spte)))
207206
kvm_set_pfn_accessed(spte_to_pfn(old_spte));
208207
}
209208

@@ -442,7 +441,7 @@ static void __handle_changed_spte(struct kvm *kvm, int as_id, gfn_t gfn,
442441

443442

444443
if (was_leaf && is_dirty_spte(old_spte) &&
445-
(!is_dirty_spte(new_spte) || pfn_changed))
444+
(!is_present || !is_dirty_spte(new_spte) || pfn_changed))
446445
kvm_set_pfn_dirty(spte_to_pfn(old_spte));
447446

448447
/*

0 commit comments

Comments
 (0)