LKML Archive on
help / color / mirror / Atom feed
From: Alexey Kardashevskiy <>
Cc: Alexey Kardashevskiy <>,, Paolo Bonzini <>
Subject: [RFC PATCH kernel] KVM: Stop leaking memory in debugfs
Date: Fri, 30 Jul 2021 14:32:17 +1000	[thread overview]
Message-ID: <> (raw)

The debugfs folder name is made of a supposedly unique pair of
the process pid and a VM fd. However it is possible to get a race here
which manifests in these messages:

[  471.846235] debugfs: Directory '20245-4' with parent 'kvm' already present!

debugfs_create_dir() returns an error which is handled correctly
everywhere except kvm_create_vm_debugfs() where the code allocates
stat data structs and overwrites the older values regardless.

Spotted by syzkaller. This slow memory leak produces way too many
OOM reports.

Signed-off-by: Alexey Kardashevskiy <>

I am pretty sure we better fix the race but I am not quite sure what
lock is appropriate here, ideas?

 virt/kvm/kvm_main.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 986959833d70..89496fd8127a 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -904,6 +904,10 @@ static int kvm_create_vm_debugfs(struct kvm *kvm, int fd)
 	snprintf(dir_name, sizeof(dir_name), "%d-%d", task_pid_nr(current), fd);
 	kvm->debugfs_dentry = debugfs_create_dir(dir_name, kvm_debugfs_dir);
+	if (IS_ERR_OR_NULL(kvm->debugfs_dentry)) {
+		pr_err("Failed to create %s\n", dir_name);
+		return 0;
+	}
 	kvm->debugfs_stat_data = kcalloc(kvm_debugfs_num_entries,

             reply	other threads:[~2021-07-30  4:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-30  4:32 Alexey Kardashevskiy [this message]
2021-08-03 11:16 ` [RFC PATCH kernel] KVM: Stop leaking memory in debugfs Greg KH
2021-08-03 12:52   ` Paolo Bonzini
2021-08-03 13:11     ` Greg KH
2021-08-03 13:29       ` Paolo Bonzini
2021-08-03 13:13     ` Alexey Kardashevskiy

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \

* 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;
as well as URLs for NNTP newsgroup(s).