Skip to contentSkip to conversation

kvm: Fixes lack of KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 enabled check

PATCH In review Kunkun Jiang 2 participants 2 messages Jan 12, 2021 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm: Fixes lack of KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 enabled check

The KVM_CLEAR_DIRTY_LOG ioctl lacks the check whether the capability KVM_CAP_MANUAL_DIRTY_LOG_PROTECT is enabled or not. This may cause some problems if userspace calls the KVM_CLEAR_DIRTY_LOG ioctl, but dose't enable this capability. So we'd better to add it.

Fixes 2a31b9db15353 ("kvm: introduce manual dirty log reprotect")
---
 virt/kvm/kvm_main.c | 3 +++
 1 file changed, 3 insertions(+)
virt/kvm/kvm_main.c +3 -0
index fa9e3614d30e..8f5633d8a0e8 100644
@@ -1602,6 +1602,9 @@ static int kvm_clear_dirty_log_protect(struct kvm *kvm,
 	unsigned long *dirty_bitmap_buffer;
 	bool flush;
 
+	if (!kvm->manual_dirty_log_protect)
+		return -EPERM;
+
 	/* Dirty ring tracking is exclusive to dirty log tracking */
 	if (kvm->dirty_ring_size)
 		return -ENXIO;
Signature · 1 line
2.19.1
maintainer
#1 lore raw
Quoted 16 lines · Kunkun Jiang

The KVM_CLEAR_DIRTY_LOG ioctl lacks the check whether the capability KVM_CAP_MANUAL_DIRTY_LOG_PROTECT is enabled or not. This may cause some problems if userspace calls the KVM_CLEAR_DIRTY_LOG ioctl, but dose't enable this capability. So we'd better to add it.

Fixes 2a31b9db15353 ("kvm: introduce manual dirty log reprotect")
---
  virt/kvm/kvm_main.c | 3 +++
  1 file changed, 3 insertions(+)
virt/kvm/kvm_main.c +0 -0
index fa9e3614d30e..8f5633d8a0e8 100644

virt/kvm/kvm_main.c static int kvm_clear_dirty_log_protect(struct kvm *kvm, · line 1610

Quoted 9 lines
virt/kvm/kvm_main.c +3 -0
@@ -1602,6 +1602,9 @@ static int kvm_clear_dirty_log_protect(struct kvm *kvm,
  	unsigned long *dirty_bitmap_buffer;
  	bool flush;
 
+	if (!kvm->manual_dirty_log_protect)
+		return -EPERM;
+
  	/* Dirty ring tracking is exclusive to dirty log tracking */
  	if (kvm->dirty_ring_size)
  		return -ENXIO;

This is not a problem, KVM_CLEAR_DIRTY_LOG can always be used even if KVM_CAP_MANUAL_DIRTY_LOG_PROTECT was not enabled. The meaning is the same: clear the bits without returning them.

Paolo