Skip to content

Commit 30486e7

Browse files
gkurzpaulusmack
authored andcommitted
KVM: PPC: Book3S HV: XIVE: Fix potential page leak on error path
We need to check the host page size is big enough to accomodate the EQ. Let's do this before taking a reference on the EQ page to avoid a potential leak if the check fails. Cc: [email protected] # v5.2 Fixes: 13ce329 ("KVM: PPC: Book3S HV: XIVE: Add controls for the EQ configuration") Signed-off-by: Greg Kurz <[email protected]> Reviewed-by: Cédric Le Goater <[email protected]> Signed-off-by: Paul Mackerras <[email protected]>
1 parent 31a88c8 commit 30486e7

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

arch/powerpc/kvm/book3s_xive_native.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -630,12 +630,6 @@ static int kvmppc_xive_native_set_queue_config(struct kvmppc_xive *xive,
630630

631631
srcu_idx = srcu_read_lock(&kvm->srcu);
632632
gfn = gpa_to_gfn(kvm_eq.qaddr);
633-
page = gfn_to_page(kvm, gfn);
634-
if (is_error_page(page)) {
635-
srcu_read_unlock(&kvm->srcu, srcu_idx);
636-
pr_err("Couldn't get queue page %llx!\n", kvm_eq.qaddr);
637-
return -EINVAL;
638-
}
639633

640634
page_size = kvm_host_page_size(kvm, gfn);
641635
if (1ull << kvm_eq.qshift > page_size) {
@@ -644,6 +638,13 @@ static int kvmppc_xive_native_set_queue_config(struct kvmppc_xive *xive,
644638
return -EINVAL;
645639
}
646640

641+
page = gfn_to_page(kvm, gfn);
642+
if (is_error_page(page)) {
643+
srcu_read_unlock(&kvm->srcu, srcu_idx);
644+
pr_err("Couldn't get queue page %llx!\n", kvm_eq.qaddr);
645+
return -EINVAL;
646+
}
647+
647648
qaddr = page_to_virt(page) + (kvm_eq.qaddr & ~PAGE_MASK);
648649
srcu_read_unlock(&kvm->srcu, srcu_idx);
649650

0 commit comments

Comments
 (0)