Skip to content

Commit

Permalink
virt: guest_memfd: fix reference leak on hwpoisoned page
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bonzini committed Jun 20, 2024
1 parent f474092 commit c31745d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions virt/kvm/guest_memfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,10 @@ int kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot,
}

if (folio_test_hwpoison(folio)) {
folio_unlock(folio);
folio_put(folio);
r = -EHWPOISON;
goto out_unlock;
goto out_fput;
}

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

r = 0;

out_unlock:
folio_unlock(folio);
out_fput:
fput(file);
Expand Down

0 comments on commit c31745d

Please sign in to comment.