Skip to contentSkip to conversation

kvm/vfio: Fix potential deadlock problem in vfio

PATCH Applied Wan Jiabing 3 participants 3 messages May 17, 2022 – May 18, 2022 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm/vfio: Fix potential deadlock problem in vfio

Fix following coccicheck warning:
./virt/kvm/vfio.c:258:1-7: preceding lock on line 236

If kvm_vfio_file_iommu_group() failed, code would goto err_fdput with mutex_lock acquired and then return ret. It might cause potential deadlock. Move mutex_unlock bellow err_fdput tag to fix it.

Fixes d55d9e7a45721 ("kvm/vfio: Store the struct file in the kvm_vfio_group")
---
 virt/kvm/vfio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/vfio.c +1 -1
index 8f9f7fffb96a..ce1b01d02c51 100644
@@ -252,8 +252,8 @@ static int kvm_vfio_group_set_spapr_tce(struct kvm_device *dev,
 		break;
 	}
 
-	mutex_unlock(&kv->lock);
 err_fdput:
+	mutex_unlock(&kv->lock);
 	fdput(f);
 	return ret;
 }
Signature · 1 line
2.36.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Wan Jiabing

Fix following coccicheck warning:
./virt/kvm/vfio.c:258:1-7: preceding lock on line 236

If kvm_vfio_file_iommu_group() failed, code would goto err_fdput with mutex_lock acquired and then return ret. It might cause potential deadlock. Move mutex_unlock bellow err_fdput tag to fix it.

Quoted 5 lines
Fixes d55d9e7a45721 ("kvm/vfio: Store the struct file in the kvm_vfio_group")
---
 virt/kvm/vfio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Thanks,
Jason

#2 lore raw
In reply to Wan Jiabing
Quoted 18 lines · On Tue, 17 May 2022 10:34:41 +0800 Wan Jiabing <[email protected]> wrote:

Fix following coccicheck warning:
./virt/kvm/vfio.c:258:1-7: preceding lock on line 236

If kvm_vfio_file_iommu_group() failed, code would goto err_fdput with mutex_lock acquired and then return ret. It might cause potential deadlock. Move mutex_unlock bellow err_fdput tag to fix it.

Fixes d55d9e7a45721 ("kvm/vfio: Store the struct file in the kvm_vfio_group")
---
 virt/kvm/vfio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/vfio.c +0 -0
index 8f9f7fffb96a..ce1b01d02c51 100644

virt/kvm/vfio.c static int kvm_vfio_group_set_spapr_tce(struct kvm_device *dev, · line 259

Quoted 9 lines
virt/kvm/vfio.c +1 -1
@@ -252,8 +252,8 @@ static int kvm_vfio_group_set_spapr_tce(struct kvm_device *dev,
 		break;
 	}
 
-	mutex_unlock(&kv->lock);
 err_fdput:
+	mutex_unlock(&kv->lock);
 	fdput(f);
 	return ret;
 }

Applied to vfio next branch for v5.19. Thanks!

Alex