Skip to content

Commit

Permalink
KVM: selftests: Verify stats fd is usable after VM fd has been closed
Browse files Browse the repository at this point in the history
Verify that VM and vCPU binary stats files are usable even after userspace
has put its last direct reference to the VM.  This is a regression test
for a UAF bug where KVM didn't gift the stats files a reference to the VM.

Signed-off-by: Sean Christopherson <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
sean-jc authored and bonzini committed Jul 29, 2023
1 parent 65f1f57 commit 211c018
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tools/testing/selftests/kvm/kvm_binary_stats_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,21 @@ int main(int argc, char *argv[])
stats_test(vcpu_get_stats_fd(vcpus[i * max_vcpu + j]));
}

/*
* Close the VM fd and redo the stats tests. KVM should gift a
* reference (to the VM) to each stats fd, i.e. stats should
* still be accessible even after userspace has put its last
* _direct_ reference to the VM.
*/
kvm_vm_free(vms[i]);

stats_test(vm_stats_fds);
for (j = 0; j < max_vcpu; ++j)
stats_test(vcpu_stats_fds[j]);

ksft_test_result_pass("vm%i\n", i);
}

for (i = 0; i < max_vm; ++i)
kvm_vm_free(vms[i]);
free(vms);
free(vcpus);
free(vcpu_stats_fds);
Expand Down

0 comments on commit 211c018

Please sign in to comment.