From: sashiko-bot@kernel.org
To: "Peng Hao" <flyingpenghao@gmail.com>
Cc: kvm@vger.kernel.org
Subject: Re: [RFC PATCH 2/3] KVM: Add a module param to disable the per-VM debugfs directories
Date: Mon, 16 Nov 2026 03:43:26 +0000 [thread overview]
Message-ID: <sashiko-outbox-216141@kernel.org> (raw)
In-Reply-To: <20261116032748.54582-3-flyingpeng@tencent.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] KVM: debugfs leak and UAF in
kvm_nested_s2_ptdump_create_debugfs()
--
commit 6b8cad730d46b448b05e32a4f22f6d9fe9cf399b
Author: Peng Hao <flyingpenghao@gmail.com>
KVM: Add a module param to disable the per-VM debugfs directories
This commit adds the kvm.per_vm_debugfs module parameter to allow skipping the
creation of per-VM and per-vCPU debugfs directories and files.
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index fff19e9239d2b..54a2924f9b928 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
[ ... ]
> @@ -1024,7 +1032,7 @@ static int kvm_create_vm_debugfs(struct kvm *kvm, const char *fdname)
> int kvm_debugfs_num_entries = kvm_vm_stats_header.num_desc +
> kvm_vcpu_stats_header.num_desc;
>
> - if (!debugfs_initialized())
> + if (!debugfs_initialized() || !per_vm_debugfs)
> return 0;
[Severity: Medium]
On arm64 with CONFIG_PTDUMP_STAGE2_DEBUGFS=y, does returning early here when
per_vm_debugfs is false cause kvm_nested_s2_ptdump_create_debugfs() to leak
nested_mmu* files in the root of debugfs and leave dangling pointers?
kvm_create_vm() initializes kvm->debugfs_dentry to ERR_PTR(-ENOENT), so
callers passing it as a parent to debugfs_create_file() or
debugfs_create_dir() fail as expected. However, kvm->arch.debugfs_nv_dentry
is zero-allocated (NULL) and is only populated when kvm_create_vm_debugfs()
reaches kvm_arch_create_vm_debugfs() -> kvm_s2_ptdump_create_debugfs().
When per_vm_debugfs is false while debugfs_initialized() is true,
kvm->arch.debugfs_nv_dentry remains NULL. Initializing a nested vCPU in
kvm_vcpu_init_nested() then calls kvm_nested_s2_ptdump_create_debugfs(),
passing NULL as the parent dentry:
arch/arm64/kvm/ptdump.c:kvm_nested_s2_ptdump_create_debugfs() {
...
debugfs_create_file(file_name, 0400,
mmu->arch->debugfs_nv_dentry, mmu,
&kvm_ptdump_guest_fops);
}
debugfs interprets a NULL parent as the root of the debugfs mount and creates
/sys/kernel/debug/nested_mmu* with inode->i_private pointing to mmu. When
the VM is destroyed, these root files are never removed while
kvm_destroy_nested() frees the nested_mmus arrays and kvm_destroy_vm() frees
struct kvm, so opening /sys/kernel/debug/nested_mmu* afterwards triggers a
use-after-free in kvm_ptdump_guest_open().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116032748.54582-1-flyingpeng@tencent.com?part=2
next prev parent reply other threads:[~2026-11-16 3:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 3:27 [RFC PATCH 0/3] KVM: Rework how halt-polling stats and per-VM debugfs use memory Peng Hao
2026-11-16 3:27 ` [RFC PATCH 1/3] KVM: Add the halt-polling time to the kvm_vcpu_wakeup tracepoint Peng Hao
2026-11-16 3:27 ` [RFC PATCH 2/3] KVM: Add a module param to disable the per-VM debugfs directories Peng Hao
2026-11-16 3:43 ` sashiko-bot [this message]
2026-11-16 3:27 ` [RFC PATCH 3/3] KVM: Move the halt-polling histograms out of struct kvm_vcpu_stat Peng Hao
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=sashiko-outbox-216141@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=flyingpenghao@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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