From: Steffen Eiden <seiden@linux.ibm.com>
To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>,
Steffen Eiden <seiden@linux.ibm.com>
Subject: [PATCH] KVM: Add missing debugfs cleanup in kvm_init error path
Date: Thu, 9 Jul 2026 17:21:54 +0200 [thread overview]
Message-ID: <20260709152154.235233-1-seiden@linux.ibm.com> (raw)
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")
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
virt/kvm/kvm_main.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index e44c20c04961..d4420ebfd972 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -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();
--
2.53.0
next reply other threads:[~2026-07-09 15:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 15:21 Steffen Eiden [this message]
2026-07-09 16:52 ` [PATCH] KVM: Add missing debugfs cleanup in kvm_init error path Sean Christopherson
2026-07-10 8:35 ` Steffen Eiden
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260709152154.235233-1-seiden@linux.ibm.com \
--to=seiden@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox