lkml.org 
[lkml]   [2022]   [Oct]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] KVM: x86: Reduce refcount if single_open() fails in kvm_mmu_rmaps_stat_open()
Date
Refcount is increased before calling single_open() in
kvm_mmu_rmaps_stat_open(), If single_open() fails, refcount should be
restored, otherwise the vm couldn't be destroyed.

Fixes: 3bcd0662d66fd ("KVM: X86: Introduce mmu_rmaps_stat per-vm debugfs file")
Signed-off-by: Hou Wenlong <houwenlong.hwl@antgroup.com>
---
arch/x86/kvm/debugfs.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/debugfs.c b/arch/x86/kvm/debugfs.c
index cfed36aba2f7..412ed1b341fa 100644
--- a/arch/x86/kvm/debugfs.c
+++ b/arch/x86/kvm/debugfs.c
@@ -162,7 +162,12 @@ static int kvm_mmu_rmaps_stat_open(struct inode *inode, struct file *file)
if (!kvm_get_kvm_safe(kvm))
return -ENOENT;

- return single_open(file, kvm_mmu_rmaps_stat_show, kvm);
+ if (single_open(file, kvm_mmu_rmaps_stat_show, kvm)) {
+ kvm_put_kvm(kvm);
+ return -ENOMEM;
+ }
+
+ return 0;
}

static int kvm_mmu_rmaps_stat_release(struct inode *inode, struct file *file)
--
2.31.1
\
 
 \ /
  Last update: 2022-10-14 09:56    [W:0.043 / U:1.812 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site