All of lore.kernel.org
 help / color / mirror / Atom feed
* [GIT PULL 0/1] KVM: s390: another fix for 4.15 (via kvm/master)
@ 2018-01-24 14:49 Christian Borntraeger
  2018-01-24 14:49 ` [GIT PULL 1/1] KVM: s390: add proper locking for CMMA migration bitmap Christian Borntraeger
  2018-01-25 14:22 ` [GIT PULL 0/1] KVM: s390: another fix for 4.15 (via kvm/master) Radim Krčmář
  0 siblings, 2 replies; 3+ messages in thread
From: Christian Borntraeger @ 2018-01-24 14:49 UTC (permalink / raw)
  To: Paolo Bonzini, Radim Krčmář
  Cc: KVM, Cornelia Huck, Christian Borntraeger, linux-s390,
	Janosch Frank, David Hildenbrand, Claudio Imbrenda

Paolo, Radim,

one last fix for 4.15. (if it is too late for 4.15 I can send it
for the next merge window together with the other pending patches, let
me know).

The following changes since commit c2cf265d860882b51a200e4a7553c17827f2b730:

  KVM: s390: prevent buffer overrun on memory hotplug during migration (2017-12-22 15:22:41 +0100)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git  tags/kvm-s390-master-4.15-3

for you to fetch changes up to 1de1ea7efeb9e8543212210e34518b4049ccd285:

  KVM: s390: add proper locking for CMMA migration bitmap (2018-01-24 15:22:51 +0100)

----------------------------------------------------------------
KVM: s390: another fix for cmma migration

This fixes races and potential use after free in the
cmma migration code.

----------------------------------------------------------------
Christian Borntraeger (1):
      KVM: s390: add proper locking for CMMA migration bitmap

 arch/s390/kvm/kvm-s390.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [GIT PULL 1/1] KVM: s390: add proper locking for CMMA migration bitmap
  2018-01-24 14:49 [GIT PULL 0/1] KVM: s390: another fix for 4.15 (via kvm/master) Christian Borntraeger
@ 2018-01-24 14:49 ` Christian Borntraeger
  2018-01-25 14:22 ` [GIT PULL 0/1] KVM: s390: another fix for 4.15 (via kvm/master) Radim Krčmář
  1 sibling, 0 replies; 3+ messages in thread
From: Christian Borntraeger @ 2018-01-24 14:49 UTC (permalink / raw)
  To: Paolo Bonzini, Radim Krčmář
  Cc: KVM, Cornelia Huck, Christian Borntraeger, linux-s390,
	Janosch Frank, David Hildenbrand, Claudio Imbrenda

Some parts of the cmma migration bitmap is already protected
with the kvm->lock (e.g. the migration start). On the other
hand the read of the cmma bits is not protected against a
concurrent free, neither is the emulation of the ESSA instruction.
Let's extend the locking to all related ioctls by using
the slots lock for
- kvm_s390_vm_start_migration
- kvm_s390_vm_stop_migration
- kvm_s390_set_cmma_bits
- kvm_s390_get_cmma_bits

In addition to that, we use synchronize_srcu before freeing
the migration structure as all users hold kvm->srcu for read.
(e.g. the ESSA handler).

Reported-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: stable@vger.kernel.org # 4.13+
Fixes: 190df4a212a7 (KVM: s390: CMMA tracking, ESSA emulation, migration mode)
Reviewed-by: Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
---
 arch/s390/kvm/kvm-s390.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index abcd24fdde3fc..52880e980a336 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -766,7 +766,7 @@ static void kvm_s390_sync_request_broadcast(struct kvm *kvm, int req)
 
 /*
  * Must be called with kvm->srcu held to avoid races on memslots, and with
- * kvm->lock to avoid races with ourselves and kvm_s390_vm_stop_migration.
+ * kvm->slots_lock to avoid races with ourselves and kvm_s390_vm_stop_migration.
  */
 static int kvm_s390_vm_start_migration(struct kvm *kvm)
 {
@@ -822,7 +822,7 @@ static int kvm_s390_vm_start_migration(struct kvm *kvm)
 }
 
 /*
- * Must be called with kvm->lock to avoid races with ourselves and
+ * Must be called with kvm->slots_lock to avoid races with ourselves and
  * kvm_s390_vm_start_migration.
  */
 static int kvm_s390_vm_stop_migration(struct kvm *kvm)
@@ -837,6 +837,8 @@ static int kvm_s390_vm_stop_migration(struct kvm *kvm)
 
 	if (kvm->arch.use_cmma) {
 		kvm_s390_sync_request_broadcast(kvm, KVM_REQ_STOP_MIGRATION);
+		/* We have to wait for the essa emulation to finish */
+		synchronize_srcu(&kvm->srcu);
 		vfree(mgs->pgste_bitmap);
 	}
 	kfree(mgs);
@@ -846,14 +848,12 @@ static int kvm_s390_vm_stop_migration(struct kvm *kvm)
 static int kvm_s390_vm_set_migration(struct kvm *kvm,
 				     struct kvm_device_attr *attr)
 {
-	int idx, res = -ENXIO;
+	int res = -ENXIO;
 
-	mutex_lock(&kvm->lock);
+	mutex_lock(&kvm->slots_lock);
 	switch (attr->attr) {
 	case KVM_S390_VM_MIGRATION_START:
-		idx = srcu_read_lock(&kvm->srcu);
 		res = kvm_s390_vm_start_migration(kvm);
-		srcu_read_unlock(&kvm->srcu, idx);
 		break;
 	case KVM_S390_VM_MIGRATION_STOP:
 		res = kvm_s390_vm_stop_migration(kvm);
@@ -861,7 +861,7 @@ static int kvm_s390_vm_set_migration(struct kvm *kvm,
 	default:
 		break;
 	}
-	mutex_unlock(&kvm->lock);
+	mutex_unlock(&kvm->slots_lock);
 
 	return res;
 }
@@ -1751,7 +1751,9 @@ long kvm_arch_vm_ioctl(struct file *filp,
 		r = -EFAULT;
 		if (copy_from_user(&args, argp, sizeof(args)))
 			break;
+		mutex_lock(&kvm->slots_lock);
 		r = kvm_s390_get_cmma_bits(kvm, &args);
+		mutex_unlock(&kvm->slots_lock);
 		if (!r) {
 			r = copy_to_user(argp, &args, sizeof(args));
 			if (r)
@@ -1765,7 +1767,9 @@ long kvm_arch_vm_ioctl(struct file *filp,
 		r = -EFAULT;
 		if (copy_from_user(&args, argp, sizeof(args)))
 			break;
+		mutex_lock(&kvm->slots_lock);
 		r = kvm_s390_set_cmma_bits(kvm, &args);
+		mutex_unlock(&kvm->slots_lock);
 		break;
 	}
 	default:
-- 
2.13.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [GIT PULL 0/1] KVM: s390: another fix for 4.15 (via kvm/master)
  2018-01-24 14:49 [GIT PULL 0/1] KVM: s390: another fix for 4.15 (via kvm/master) Christian Borntraeger
  2018-01-24 14:49 ` [GIT PULL 1/1] KVM: s390: add proper locking for CMMA migration bitmap Christian Borntraeger
@ 2018-01-25 14:22 ` Radim Krčmář
  1 sibling, 0 replies; 3+ messages in thread
From: Radim Krčmář @ 2018-01-25 14:22 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: Paolo Bonzini, KVM, Cornelia Huck, linux-s390, Janosch Frank,
	David Hildenbrand, Claudio Imbrenda

2018-01-24 15:49+0100, Christian Borntraeger:
> Paolo, Radim,
> 
> one last fix for 4.15. (if it is too late for 4.15 I can send it
> for the next merge window together with the other pending patches, let
> me know).

It is a small fix, so no problem for 4.15.  Pulled, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-01-25 14:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-24 14:49 [GIT PULL 0/1] KVM: s390: another fix for 4.15 (via kvm/master) Christian Borntraeger
2018-01-24 14:49 ` [GIT PULL 1/1] KVM: s390: add proper locking for CMMA migration bitmap Christian Borntraeger
2018-01-25 14:22 ` [GIT PULL 0/1] KVM: s390: another fix for 4.15 (via kvm/master) Radim Krčmář

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.