Skip to contentSkip to conversation

vfio/fsl-mc: return -EFAULT if copy_to_user() fails

PATCH Applied Dan Carpenter 3 participants 5 messages Oct 23, 2020 – Nov 3, 2020

Subsystems (4)

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 vfio/fsl-mc: return -EFAULT if copy_to_user() fails

The copy_to_user() function returns the number of bytes remaining to be copied, but this code should return -EFAULT.

Fixes df747bcd5b21 ("vfio/fsl-mc: Implement VFIO_DEVICE_GET_REGION_INFO ioctl call")
---
 drivers/vfio/fsl-mc/vfio_fsl_mc.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/vfio/fsl-mc/vfio_fsl_mc.c +6 -2
index 0113a980f974..21f22e3da11f 100644
@@ -248,7 +248,9 @@ static long vfio_fsl_mc_ioctl(void *device_data, unsigned int cmd,
 		info.size = vdev->regions[info.index].size;
 		info.flags = vdev->regions[info.index].flags;
 
-		return copy_to_user((void __user *)arg, &info, minsz);
+		if (copy_to_user((void __user *)arg, &info, minsz))
+			return -EFAULT;
+		return 0;
 	}
 	case VFIO_DEVICE_GET_IRQ_INFO:
 	{
@@ -267,7 +269,9 @@ static long vfio_fsl_mc_ioctl(void *device_data, unsigned int cmd,
 		info.flags = VFIO_IRQ_INFO_EVENTFD;
 		info.count = 1;
 
-		return copy_to_user((void __user *)arg, &info, minsz);
+		if (copy_to_user((void __user *)arg, &info, minsz))
+			return -EFAULT;
+		return 0;
 	}
 	case VFIO_DEVICE_SET_IRQS:
 	{
Signature · 1 line
2.28.0
#1 lore raw

Thanks, Dan.

Diana, can I get an ack for this? Thanks,

Alex

Quoted 35 lines · On Fri, 23 Oct 2020 14:34:50 +0300 Dan Carpenter <[email protected]>…

The copy_to_user() function returns the number of bytes remaining to be copied, but this code should return -EFAULT.

Fixes df747bcd5b21 ("vfio/fsl-mc: Implement VFIO_DEVICE_GET_REGION_INFO ioctl call")
---
 drivers/vfio/fsl-mc/vfio_fsl_mc.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/vfio/fsl-mc/vfio_fsl_mc.c +6 -2
index 0113a980f974..21f22e3da11f 100644
@@ -248,7 +248,9 @@ static long vfio_fsl_mc_ioctl(void *device_data, unsigned int cmd,
 		info.size = vdev->regions[info.index].size;
 		info.flags = vdev->regions[info.index].flags;
 
-		return copy_to_user((void __user *)arg, &info, minsz);
+		if (copy_to_user((void __user *)arg, &info, minsz))
+			return -EFAULT;
+		return 0;
 	}
 	case VFIO_DEVICE_GET_IRQ_INFO:
 	{
@@ -267,7 +269,9 @@ static long vfio_fsl_mc_ioctl(void *device_data, unsigned int cmd,
 		info.flags = VFIO_IRQ_INFO_EVENTFD;
 		info.count = 1;
 
-		return copy_to_user((void __user *)arg, &info, minsz);
+		if (copy_to_user((void __user *)arg, &info, minsz))
+			return -EFAULT;
+		return 0;
 	}
 	case VFIO_DEVICE_SET_IRQS:
 	{
#2 lore raw
Quoted 4 lines · Alex Williamson

Thanks, Dan.

Diana, can I get an ack for this? Thanks,

Yes, sure, I apologize for not doing it earlier.

Thanks,
Diana

Quoted 42 lines

Alex

Quoted 35 lines · On Fri, 23 Oct 2020 14:34:50 +0300 Dan Carpenter <[email protected]>…

The copy_to_user() function returns the number of bytes remaining to be copied, but this code should return -EFAULT.

Fixes df747bcd5b21 ("vfio/fsl-mc: Implement VFIO_DEVICE_GET_REGION_INFO ioctl call")
---
  drivers/vfio/fsl-mc/vfio_fsl_mc.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
drivers/vfio/fsl-mc/vfio_fsl_mc.c +6 -2
index 0113a980f974..21f22e3da11f 100644
@@ -248,7 +248,9 @@ static long vfio_fsl_mc_ioctl(void *device_data, unsigned int cmd,
  		info.size = vdev->regions[info.index].size;
  		info.flags = vdev->regions[info.index].flags;
 
-		return copy_to_user((void __user *)arg, &info, minsz);
+		if (copy_to_user((void __user *)arg, &info, minsz))
+			return -EFAULT;
+		return 0;
  	}
  	case VFIO_DEVICE_GET_IRQ_INFO:
  	{
@@ -267,7 +269,9 @@ static long vfio_fsl_mc_ioctl(void *device_data, unsigned int cmd,
  		info.flags = VFIO_IRQ_INFO_EVENTFD;
  		info.count = 1;
 
-		return copy_to_user((void __user *)arg, &info, minsz);
+		if (copy_to_user((void __user *)arg, &info, minsz))
+			return -EFAULT;
+		return 0;
  	}
  	case VFIO_DEVICE_SET_IRQS:
  	{
Acked-by on v1 1/2
#3 lore raw
In reply to Dan Carpenter
Quoted 36 lines · Dan Carpenter

The copy_to_user() function returns the number of bytes remaining to be copied, but this code should return -EFAULT.

Fixes df747bcd5b21 ("vfio/fsl-mc: Implement VFIO_DEVICE_GET_REGION_INFO ioctl call")
---
  drivers/vfio/fsl-mc/vfio_fsl_mc.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
drivers/vfio/fsl-mc/vfio_fsl_mc.c +6 -2
index 0113a980f974..21f22e3da11f 100644
@@ -248,7 +248,9 @@ static long vfio_fsl_mc_ioctl(void *device_data, unsigned int cmd,
  		info.size = vdev->regions[info.index].size;
  		info.flags = vdev->regions[info.index].flags;
 
-		return copy_to_user((void __user *)arg, &info, minsz);
+		if (copy_to_user((void __user *)arg, &info, minsz))
+			return -EFAULT;
+		return 0;
  	}
  	case VFIO_DEVICE_GET_IRQ_INFO:
  	{
@@ -267,7 +269,9 @@ static long vfio_fsl_mc_ioctl(void *device_data, unsigned int cmd,
  		info.flags = VFIO_IRQ_INFO_EVENTFD;
  		info.count = 1;
 
-		return copy_to_user((void __user *)arg, &info, minsz);
+		if (copy_to_user((void __user *)arg, &info, minsz))
+			return -EFAULT;
+		return 0;
  	}
  	case VFIO_DEVICE_SET_IRQS:
  	{
#4 lore raw
In reply to Dan Carpenter
Quoted 8 lines · On Fri, 23 Oct 2020 14:34:50 +0300 Dan Carpenter <[email protected]>…

The copy_to_user() function returns the number of bytes remaining to be copied, but this code should return -EFAULT.

Fixes df747bcd5b21 ("vfio/fsl-mc: Implement VFIO_DEVICE_GET_REGION_INFO ioctl call")
---
 drivers/vfio/fsl-mc/vfio_fsl_mc.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Applied this and the following patch to vfio for-linus branch with Diana's acks for v5.10. Thanks,

Alex

Quoted 26 lines
drivers/vfio/fsl-mc/vfio_fsl_mc.c +6 -2
index 0113a980f974..21f22e3da11f 100644
@@ -248,7 +248,9 @@ static long vfio_fsl_mc_ioctl(void *device_data, unsigned int cmd,
 		info.size = vdev->regions[info.index].size;
 		info.flags = vdev->regions[info.index].flags;
 
-		return copy_to_user((void __user *)arg, &info, minsz);
+		if (copy_to_user((void __user *)arg, &info, minsz))
+			return -EFAULT;
+		return 0;
 	}
 	case VFIO_DEVICE_GET_IRQ_INFO:
 	{
@@ -267,7 +269,9 @@ static long vfio_fsl_mc_ioctl(void *device_data, unsigned int cmd,
 		info.flags = VFIO_IRQ_INFO_EVENTFD;
 		info.count = 1;
 
-		return copy_to_user((void __user *)arg, &info, minsz);
+		if (copy_to_user((void __user *)arg, &info, minsz))
+			return -EFAULT;
+		return 0;
 	}
 	case VFIO_DEVICE_SET_IRQS:
 	{