Skip to content

Commit fd546ab

Browse files
committed
KVM: selftests: Fix mostly theoretical leak of VM's binary stats FD
When allocating and freeing a VM's cached binary stats info, check for a NULL descriptor, not a '0' file descriptor, as '0' is a legal FD. E.g. in the unlikely scenario the kernel installs the stats FD at entry '0', selftests would reallocate on the next __vm_get_stat() and/or fail to free the stats in kvm_vm_free(). Fixes: 83f6e10 ("KVM: selftests: Cache binary stats metadata for duration of test") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent dae7d81 commit fd546ab

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tools/testing/selftests/kvm/lib/kvm_util.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ void kvm_vm_free(struct kvm_vm *vmp)
749749
return;
750750

751751
/* Free cached stats metadata and close FD */
752-
if (vmp->stats_fd) {
752+
if (vmp->stats_desc) {
753753
free(vmp->stats_desc);
754754
close(vmp->stats_fd);
755755
}
@@ -2218,7 +2218,7 @@ void __vm_get_stat(struct kvm_vm *vm, const char *stat_name, uint64_t *data,
22182218
size_t size_desc;
22192219
int i;
22202220

2221-
if (!vm->stats_fd) {
2221+
if (!vm->stats_desc) {
22222222
vm->stats_fd = vm_get_stats_fd(vm);
22232223
read_stats_header(vm->stats_fd, &vm->stats_header);
22242224
vm->stats_desc = read_stats_descriptors(vm->stats_fd,

0 commit comments

Comments
 (0)