Skip to content

Commit a44a4cc

Browse files
ouptonMarc Zyngier
authored andcommitted
KVM: Don't create VM debugfs files outside of the VM directory
Unfortunately, there is no guarantee that KVM was able to instantiate a debugfs directory for a particular VM. To that end, KVM shouldn't even attempt to create new debugfs files in this case. If the specified parent dentry is NULL, debugfs_create_file() will instantiate files at the root of debugfs. For arm64, it is possible to create the vgic-state file outside of a VM directory, the file is not cleaned up when a VM is destroyed. Nonetheless, the corresponding struct kvm is freed when the VM is destroyed. Nip the problem in the bud for all possible errant debugfs file creations by initializing kvm->debugfs_dentry to -ENOENT. In so doing, debugfs_create_file() will fail instead of creating the file in the root directory. Cc: [email protected] Fixes: 929f45e ("kvm: no need to check return value of debugfs_create functions") Signed-off-by: Oliver Upton <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 02de933 commit a44a4cc

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

virt/kvm/kvm_main.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ static void kvm_destroy_vm_debugfs(struct kvm *kvm)
932932
int kvm_debugfs_num_entries = kvm_vm_stats_header.num_desc +
933933
kvm_vcpu_stats_header.num_desc;
934934

935-
if (!kvm->debugfs_dentry)
935+
if (IS_ERR(kvm->debugfs_dentry))
936936
return;
937937

938938
debugfs_remove_recursive(kvm->debugfs_dentry);
@@ -955,6 +955,12 @@ static int kvm_create_vm_debugfs(struct kvm *kvm, int fd)
955955
int kvm_debugfs_num_entries = kvm_vm_stats_header.num_desc +
956956
kvm_vcpu_stats_header.num_desc;
957957

958+
/*
959+
* Force subsequent debugfs file creations to fail if the VM directory
960+
* is not created.
961+
*/
962+
kvm->debugfs_dentry = ERR_PTR(-ENOENT);
963+
958964
if (!debugfs_initialized())
959965
return 0;
960966

@@ -5479,7 +5485,7 @@ static void kvm_uevent_notify_change(unsigned int type, struct kvm *kvm)
54795485
}
54805486
add_uevent_var(env, "PID=%d", kvm->userspace_pid);
54815487

5482-
if (kvm->debugfs_dentry) {
5488+
if (!IS_ERR(kvm->debugfs_dentry)) {
54835489
char *tmp, *p = kmalloc(PATH_MAX, GFP_KERNEL_ACCOUNT);
54845490

54855491
if (p) {

0 commit comments

Comments
 (0)