Skip to contentSkip to conversation

KVM: Add missing debugfs cleanup in kvm_init error path

PATCH In review Steffen Eiden 2 participants 3 messages Jul 9 – Jul 10 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: Add missing debugfs cleanup in kvm_init error path

If any initialization after kvm_init_debug() fails the cleanup code did not remove the debugfs entries. Therefore, the corresponding debugfs entries where still alive but the backing fops are already freed, creating a use-after-free scenario. Fix this by removing the debugfs entries if vfio init fails.

Fixes 2b0128127373 ("KVM: Register /dev/kvm as the _very_ last thing during initialization")
---
 virt/kvm/kvm_main.c | 1 +
 1 file changed, 1 insertion(+)
virt/kvm/kvm_main.c +1 -0
index e44c20c04961..d4420ebfd972 100644
@@ -6559,6 +6559,7 @@ int kvm_init(unsigned vcpu_size, unsigned vcpu_align, struct module *module)
 err_gmem:
 	kvm_vfio_ops_exit();
 err_vfio:
+	debugfs_remove_recursive(kvm_debugfs_dir);
 	kvm_async_pf_deinit();
 err_async_pf:
 	kvm_irqfd_exit();
Signature · 1 line
2.53.0
#1 lore raw
Quoted 5 lines · Steffen Eiden

If any initialization after kvm_init_debug() fails the cleanup code did not remove the debugfs entries. Therefore, the corresponding debugfs entries where still alive but the backing fops are already freed, creating a use-after-free scenario. Fix this by removing the debugfs entries if vfio init fails.

Already posted, and applied locally on my end.

https://lore.kernel.org/all/20260706095910.39798-1-leixiang%40kylinos.cn

#2 lore raw
Quoted 10 lines · Sean Christopherson
Quoted 5 lines · Steffen Eiden

If any initialization after kvm_init_debug() fails the cleanup code did not remove the debugfs entries. Therefore, the corresponding debugfs entries where still alive but the backing fops are already freed, creating a use-after-free scenario. Fix this by removing the debugfs entries if vfio init fails.

Already posted, and applied locally on my end.

https://lore.kernel.org/all/20260706095910.39798-1-leixiang%40kylinos.cn

Oh sorry, I missed that.