Skip to content

Commit 4c4a11c

Browse files
Xiaomeng Tonggregkh
authored andcommitted
KVM: PPC: Book3S HV: fix incorrect NULL check on list iterator
commit 300981a upstream. The bug is here: if (!p) return ret; The list iterator value 'p' will *always* be set and non-NULL by list_for_each_entry(), so it is incorrect to assume that the iterator value will be NULL if the list is empty or no element is found. To fix the bug, Use a new value 'iter' as the list iterator, while use the old value 'p' as a dedicated variable to point to the found element. Fixes: dfaa973 ("KVM: PPC: Book3S HV: In H_SVM_INIT_DONE, migrate remaining normal-GFNs to secure-GFNs") Cc: stable@vger.kernel.org # v5.9+ Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20220414062103.8153-1-xiam0nd.tong@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 91a36ec commit 4c4a11c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

arch/powerpc/kvm/book3s_hv_uvmem.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,15 @@ static bool kvmppc_gfn_is_uvmem_pfn(unsigned long gfn, struct kvm *kvm,
359359
static bool kvmppc_next_nontransitioned_gfn(const struct kvm_memory_slot *memslot,
360360
struct kvm *kvm, unsigned long *gfn)
361361
{
362-
struct kvmppc_uvmem_slot *p;
362+
struct kvmppc_uvmem_slot *p = NULL, *iter;
363363
bool ret = false;
364364
unsigned long i;
365365

366-
list_for_each_entry(p, &kvm->arch.uvmem_pfns, list)
367-
if (*gfn >= p->base_pfn && *gfn < p->base_pfn + p->nr_pfns)
366+
list_for_each_entry(iter, &kvm->arch.uvmem_pfns, list)
367+
if (*gfn >= iter->base_pfn && *gfn < iter->base_pfn + iter->nr_pfns) {
368+
p = iter;
368369
break;
370+
}
369371
if (!p)
370372
return ret;
371373
/*

0 commit comments

Comments
 (0)