[1/1] KVM: s390: fix locking for crypto setting error path
diff mbox series

Message ID 20181004193905.135291-2-borntraeger@de.ibm.com
State New
Headers show
Series
  • KVM: s390: fixup for vfio-ap
Related show

Commit Message

Christian Borntraeger Oct. 4, 2018, 7:39 p.m. UTC
We need to unlock the kvm->lock mutex in the error case.

Reported-by: smatch
Fixes: 37940fb0b6a2c4bf101 ("KVM: s390: device attrs to enable/disable AP interpretation")
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Pierre Morel <pmorel@linux.ibm.com>
---
 arch/s390/kvm/kvm-s390.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Comments

David Hildenbrand Oct. 4, 2018, 7:56 p.m. UTC | #1
On 04/10/2018 21:39, Christian Borntraeger wrote:
> We need to unlock the kvm->lock mutex in the error case.
> 
> Reported-by: smatch
> Fixes: 37940fb0b6a2c4bf101 ("KVM: s390: device attrs to enable/disable AP interpretation")
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
> Reviewed-by: Pierre Morel <pmorel@linux.ibm.com>
> ---
>  arch/s390/kvm/kvm-s390.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
> index b7964d77c6cd..80652907d3d8 100644
> --- a/arch/s390/kvm/kvm-s390.c
> +++ b/arch/s390/kvm/kvm-s390.c
> @@ -859,8 +859,10 @@ static int kvm_s390_vm_set_crypto(struct kvm *kvm, struct kvm_device_attr *attr)
>  	mutex_lock(&kvm->lock);
>  	switch (attr->attr) {
>  	case KVM_S390_VM_CRYPTO_ENABLE_AES_KW:
> -		if (!test_kvm_facility(kvm, 76))
> +		if (!test_kvm_facility(kvm, 76)) {
> +			mutex_unlock(&kvm->lock);
>  			return -EINVAL;
> +		}
>  		get_random_bytes(
>  			kvm->arch.crypto.crycb->aes_wrapping_key_mask,
>  			sizeof(kvm->arch.crypto.crycb->aes_wrapping_key_mask));
> @@ -868,8 +870,10 @@ static int kvm_s390_vm_set_crypto(struct kvm *kvm, struct kvm_device_attr *attr)
>  		VM_EVENT(kvm, 3, "%s", "ENABLE: AES keywrapping support");
>  		break;
>  	case KVM_S390_VM_CRYPTO_ENABLE_DEA_KW:
> -		if (!test_kvm_facility(kvm, 76))
> +		if (!test_kvm_facility(kvm, 76)) {
> +			mutex_unlock(&kvm->lock);
>  			return -EINVAL;
> +		}
>  		get_random_bytes(
>  			kvm->arch.crypto.crycb->dea_wrapping_key_mask,
>  			sizeof(kvm->arch.crypto.crycb->dea_wrapping_key_mask));
> @@ -877,16 +881,20 @@ static int kvm_s390_vm_set_crypto(struct kvm *kvm, struct kvm_device_attr *attr)
>  		VM_EVENT(kvm, 3, "%s", "ENABLE: DEA keywrapping support");
>  		break;
>  	case KVM_S390_VM_CRYPTO_DISABLE_AES_KW:
> -		if (!test_kvm_facility(kvm, 76))
> +		if (!test_kvm_facility(kvm, 76)) {
> +			mutex_unlock(&kvm->lock);
>  			return -EINVAL;
> +		}
>  		kvm->arch.crypto.aes_kw = 0;
>  		memset(kvm->arch.crypto.crycb->aes_wrapping_key_mask, 0,
>  			sizeof(kvm->arch.crypto.crycb->aes_wrapping_key_mask));
>  		VM_EVENT(kvm, 3, "%s", "DISABLE: AES keywrapping support");
>  		break;
>  	case KVM_S390_VM_CRYPTO_DISABLE_DEA_KW:
> -		if (!test_kvm_facility(kvm, 76))
> +		if (!test_kvm_facility(kvm, 76)) {
> +			mutex_unlock(&kvm->lock);
>  			return -EINVAL;
> +		}
>  		kvm->arch.crypto.dea_kw = 0;
>  		memset(kvm->arch.crypto.crycb->dea_wrapping_key_mask, 0,
>  			sizeof(kvm->arch.crypto.crycb->dea_wrapping_key_mask));
> 

Reviewed-by: David Hildenbrand <david@redhat.com>
Cornelia Huck Oct. 5, 2018, 7:41 a.m. UTC | #2
On Thu,  4 Oct 2018 21:39:05 +0200
Christian Borntraeger <borntraeger@de.ibm.com> wrote:

> We need to unlock the kvm->lock mutex in the error case.
> 
> Reported-by: smatch
> Fixes: 37940fb0b6a2c4bf101 ("KVM: s390: device attrs to enable/disable AP interpretation")
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
> Reviewed-by: Pierre Morel <pmorel@linux.ibm.com>
> ---
>  arch/s390/kvm/kvm-s390.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)

Reviewed-by: Cornelia Huck <cohuck@redhat.com>

Patch
diff mbox series

diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index b7964d77c6cd..80652907d3d8 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -859,8 +859,10 @@  static int kvm_s390_vm_set_crypto(struct kvm *kvm, struct kvm_device_attr *attr)
 	mutex_lock(&kvm->lock);
 	switch (attr->attr) {
 	case KVM_S390_VM_CRYPTO_ENABLE_AES_KW:
-		if (!test_kvm_facility(kvm, 76))
+		if (!test_kvm_facility(kvm, 76)) {
+			mutex_unlock(&kvm->lock);
 			return -EINVAL;
+		}
 		get_random_bytes(
 			kvm->arch.crypto.crycb->aes_wrapping_key_mask,
 			sizeof(kvm->arch.crypto.crycb->aes_wrapping_key_mask));
@@ -868,8 +870,10 @@  static int kvm_s390_vm_set_crypto(struct kvm *kvm, struct kvm_device_attr *attr)
 		VM_EVENT(kvm, 3, "%s", "ENABLE: AES keywrapping support");
 		break;
 	case KVM_S390_VM_CRYPTO_ENABLE_DEA_KW:
-		if (!test_kvm_facility(kvm, 76))
+		if (!test_kvm_facility(kvm, 76)) {
+			mutex_unlock(&kvm->lock);
 			return -EINVAL;
+		}
 		get_random_bytes(
 			kvm->arch.crypto.crycb->dea_wrapping_key_mask,
 			sizeof(kvm->arch.crypto.crycb->dea_wrapping_key_mask));
@@ -877,16 +881,20 @@  static int kvm_s390_vm_set_crypto(struct kvm *kvm, struct kvm_device_attr *attr)
 		VM_EVENT(kvm, 3, "%s", "ENABLE: DEA keywrapping support");
 		break;
 	case KVM_S390_VM_CRYPTO_DISABLE_AES_KW:
-		if (!test_kvm_facility(kvm, 76))
+		if (!test_kvm_facility(kvm, 76)) {
+			mutex_unlock(&kvm->lock);
 			return -EINVAL;
+		}
 		kvm->arch.crypto.aes_kw = 0;
 		memset(kvm->arch.crypto.crycb->aes_wrapping_key_mask, 0,
 			sizeof(kvm->arch.crypto.crycb->aes_wrapping_key_mask));
 		VM_EVENT(kvm, 3, "%s", "DISABLE: AES keywrapping support");
 		break;
 	case KVM_S390_VM_CRYPTO_DISABLE_DEA_KW:
-		if (!test_kvm_facility(kvm, 76))
+		if (!test_kvm_facility(kvm, 76)) {
+			mutex_unlock(&kvm->lock);
 			return -EINVAL;
+		}
 		kvm->arch.crypto.dea_kw = 0;
 		memset(kvm->arch.crypto.crycb->dea_wrapping_key_mask, 0,
 			sizeof(kvm->arch.crypto.crycb->dea_wrapping_key_mask));