Skip to contentSkip to conversation

vfio/mlx5: fix error code in mlx5vf_precopy_ioctl()

PATCH Applied Dan Carpenter 3 participants 5 messages Dec 8, 2022

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 vfio/mlx5: fix error code in mlx5vf_precopy_ioctl()

The copy_to_user() function returns the number of bytes remaining to be copied but we want to return a negative error code here.

Fixes 0dce165b1adf ("vfio/mlx5: Introduce vfio precopy ioctl implementation")
---
 drivers/vfio/pci/mlx5/main.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/vfio/pci/mlx5/main.c +4 -1
index befdb0de32a1..83137228352e 100644
@@ -404,7 +404,10 @@ static long mlx5vf_precopy_ioctl(struct file *filp, unsigned int cmd,
 
 done:
 	mlx5vf_state_mutex_unlock(mvdev);
-	return copy_to_user((void __user *)arg, &info, minsz);
+	if (copy_to_user((void __user *)arg, &info, minsz))
+		return -EFAULT;
+	return 0;
+
 err_migf_unlock:
 	mutex_unlock(&migf->lock);
 err_state_unlock:
Signature · 1 line
2.35.1
#1 lore raw

PATCH 2/2 vfio/mlx5: error pointer dereference in error handling

This code frees the wrong "buf" variable and results in an error pointer dereference.

Fixes 34e2f27143d1 ("vfio/mlx5: Introduce multiple loads")

---
Why did get_maintainer.pl not add Yishai to the CC list?

 drivers/vfio/pci/mlx5/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vfio/pci/mlx5/main.c +1 -1
index 83137228352e..9feb89c6d939 100644
@@ -826,7 +826,7 @@ mlx5vf_pci_resume_device_data(struct mlx5vf_pci_core_device *mvdev)
 	spin_lock_init(&migf->list_lock);
 	return migf;
 out_buf:
-	mlx5vf_free_data_buffer(buf);
+	mlx5vf_free_data_buffer(migf->buf);
 out_pd:
 	mlx5vf_cmd_dealloc_pd(migf);
 out_free:
Signature · 1 line
2.35.1
maintainer Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] vfio/mlx5: error pointer dereference in error handling

Quoted 16 lines · Dan Carpenter

This code frees the wrong "buf" variable and results in an error pointer dereference.

Fixes 34e2f27143d1 ("vfio/mlx5: Introduce multiple loads")

---
Why did get_maintainer.pl not add Yishai to the CC list?

  drivers/vfio/pci/mlx5/main.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vfio/pci/mlx5/main.c +0 -0
index 83137228352e..9feb89c6d939 100644

drivers/vfio/pci/mlx5/main.c mlx5vf_pci_resume_device_data(struct mlx5vf_pci_core_device *mvdev) · line 832

Quoted 8 lines
drivers/vfio/pci/mlx5/main.c +1 -1
@@ -826,7 +826,7 @@ mlx5vf_pci_resume_device_data(struct mlx5vf_pci_core_device *mvdev)
  	spin_lock_init(&migf->list_lock);
  	return migf;
  out_buf:
-	mlx5vf_free_data_buffer(buf);
+	mlx5vf_free_data_buffer(migf->buf);
  out_pd:
  	mlx5vf_cmd_dealloc_pd(migf);
  out_free:

Thanks Dan

maintainer Reviewed-by on v1 1/2
#3 lore raw
In reply to Dan Carpenter
Quoted 15 lines · Dan Carpenter

The copy_to_user() function returns the number of bytes remaining to be copied but we want to return a negative error code here.

Fixes 0dce165b1adf ("vfio/mlx5: Introduce vfio precopy ioctl implementation")
---
  drivers/vfio/pci/mlx5/main.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/vfio/pci/mlx5/main.c +0 -0
index befdb0de32a1..83137228352e 100644
@@ -404,7 +404,10 @@ static long mlx5vf_precopy_ioctl(struct file *filp, unsigned int cmd,
 

drivers/vfio/pci/mlx5/main.c static long mlx5vf_precopy_ioctl(struct file *filp, unsigned int cmd, · line 413

Quoted 10 lines
drivers/vfio/pci/mlx5/main.c +4 -1
  done:
  	mlx5vf_state_mutex_unlock(mvdev);
-	return copy_to_user((void __user *)arg, &info, minsz);
+	if (copy_to_user((void __user *)arg, &info, minsz))
+		return -EFAULT;
+	return 0;
+
  err_migf_unlock:
  	mutex_unlock(&migf->lock);
  err_state_unlock:

Thanks Dan

#4 lore raw
In reply to Dan Carpenter
Quoted 8 lines · On Thu, 8 Dec 2022 19:01:26 +0300 Dan Carpenter <[email protected]> wrote:

The copy_to_user() function returns the number of bytes remaining to be copied but we want to return a negative error code here.

Fixes 0dce165b1adf ("vfio/mlx5: Introduce vfio precopy ioctl implementation")
---
 drivers/vfio/pci/mlx5/main.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Applied both to vfio next branch for v6.2. Thanks,

Alex