Skip to content

Commit c31745d

Browse files
committed
virt: guest_memfd: fix reference leak on hwpoisoned page
If kvm_gmem_get_pfn() detects an hwpoisoned page, it returns -EHWPOISON but it does not put back the reference that kvm_gmem_get_folio() had grabbed. Add the forgotten folio_put(). Fixes: a7800aa ("KVM: Add KVM_CREATE_GUEST_MEMFD ioctl() for guest-specific backing memory") Cc: [email protected] Reviewed-by: Liam Merwick <[email protected]> Reviewed-by: Isaku Yamahata <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent f474092 commit c31745d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

virt/kvm/guest_memfd.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,10 @@ int kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot,
510510
}
511511

512512
if (folio_test_hwpoison(folio)) {
513+
folio_unlock(folio);
514+
folio_put(folio);
513515
r = -EHWPOISON;
514-
goto out_unlock;
516+
goto out_fput;
515517
}
516518

517519
page = folio_file_page(folio, index);
@@ -522,7 +524,6 @@ int kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot,
522524

523525
r = 0;
524526

525-
out_unlock:
526527
folio_unlock(folio);
527528
out_fput:
528529
fput(file);

0 commit comments

Comments
 (0)