Skip to contentSkip to conversation

kvm: debugfs: fix memory leak in kvm_create_vm_debugfs

PATCH Applied Pavel Skripkin 3 participants 3 messages Jul 1, 2021 – Jul 8, 2021 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm: debugfs: fix memory leak in kvm_create_vm_debugfs

In commit bc9e9e672df9 ("KVM: debugfs: Reuse binary stats descriptors") loop for filling debugfs_stat_data was copy-pasted 2 times, but in the second loop pointers are saved over pointers allocated in the first loop. It causes memory leak. Fix it.

Fixes bc9e9e672df9 ("KVM: debugfs: Reuse binary stats descriptors")
---
 virt/kvm/kvm_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/kvm_main.c +1 -1
index 7d95126cda9e..986959833d70 100644
@@ -935,7 +935,7 @@ static int kvm_create_vm_debugfs(struct kvm *kvm, int fd)
 		stat_data->kvm = kvm;
 		stat_data->desc = pdesc;
 		stat_data->kind = KVM_STAT_VCPU;
-		kvm->debugfs_stat_data[i] = stat_data;
+		kvm->debugfs_stat_data[i + kvm_vm_stats_header.num_desc] = stat_data;
 		debugfs_create_file(pdesc->name, kvm_stats_debugfs_mode(pdesc),
 				    kvm->debugfs_dentry, stat_data,
 				    &stat_fops_per_vm);
Signature · 1 line
2.32.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Pavel Skripkin

In commit bc9e9e672df9 ("KVM: debugfs: Reuse binary stats descriptors") loop for filling debugfs_stat_data was copy-pasted 2 times, but in the second loop pointers are saved over pointers allocated in the first loop. It causes memory leak. Fix it.

Fixes bc9e9e672df9 ("KVM: debugfs: Reuse binary stats descriptors")
---
 virt/kvm/kvm_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/kvm_main.c +0 -0
index 7d95126cda9e..986959833d70 100644

virt/kvm/kvm_main.c static int kvm_create_vm_debugfs(struct kvm *kvm, int fd) · line 938

Quoted 5 lines
virt/kvm/kvm_main.c +1 -1
@@ -935,7 +935,7 @@ static int kvm_create_vm_debugfs(struct kvm *kvm, int fd)
                stat_data->kvm = kvm;
                stat_data->desc = pdesc;
                stat_data->kind = KVM_STAT_VCPU;
-               kvm->debugfs_stat_data[i] = stat_data;
+               kvm->debugfs_stat_data[i + kvm_vm_stats_header.num_desc] = stat_data;

Pavel, thanks for fixing this.

Quoted 6 lines
virt/kvm/kvm_main.c +0 -1
                debugfs_create_file(pdesc->name, kvm_stats_debugfs_mode(pdesc),
                                    kvm->debugfs_dentry, stat_data,
                                    &stat_fops_per_vm);
--

2.32.0

maintainer Applied
#2 lore raw
Quoted 8 lines · Jing Zhang

In commit bc9e9e672df9 ("KVM: debugfs: Reuse binary stats descriptors") loop for filling debugfs_stat_data was copy-pasted 2 times, but in the second loop pointers are saved over pointers allocated in the first loop. It causes memory leak. Fix it.

Fixes bc9e9e672df9 ("KVM: debugfs: Reuse binary stats descriptors")

---

Queued, thanks.

Paolo