All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vhost-vdpa: return -EFAULT on copy_to_user() failure
@ 2022-05-23  8:33 ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2022-05-23  8:33 UTC (permalink / raw)
  To: Michael S. Tsirkin, Gautam Dawar
  Cc: Jason Wang, kvm, virtualization, kernel-janitors, Christophe JAILLET

The copy_to_user() function returns the number of bytes remaining to be
copied.  However, we need to return a negative error code, -EFAULT, to
the user.

Fixes: 87f4c217413a ("vhost-vdpa: introduce uAPI to get the number of virtqueue groups")
Fixes: e96ef636f154 ("vhost-vdpa: introduce uAPI to get the number of address spaces")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/vhost/vdpa.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index 3e86080041fc..935a1d0ddb97 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -609,11 +609,13 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
 		r = vhost_vdpa_get_vring_num(v, argp);
 		break;
 	case VHOST_VDPA_GET_GROUP_NUM:
-		r = copy_to_user(argp, &v->vdpa->ngroups,
-				 sizeof(v->vdpa->ngroups));
+		if (copy_to_user(argp, &v->vdpa->ngroups,
+				 sizeof(v->vdpa->ngroups)))
+			r = -EFAULT;
 		break;
 	case VHOST_VDPA_GET_AS_NUM:
-		r = copy_to_user(argp, &v->vdpa->nas, sizeof(v->vdpa->nas));
+		if (copy_to_user(argp, &v->vdpa->nas, sizeof(v->vdpa->nas)))
+			r = -EFAULT;
 		break;
 	case VHOST_SET_LOG_BASE:
 	case VHOST_SET_LOG_FD:
-- 
2.35.1


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

* [PATCH] vhost-vdpa: return -EFAULT on copy_to_user() failure
@ 2022-05-23  8:33 ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2022-05-23  8:33 UTC (permalink / raw)
  To: Michael S. Tsirkin, Gautam Dawar
  Cc: Christophe JAILLET, kernel-janitors, kvm, virtualization

The copy_to_user() function returns the number of bytes remaining to be
copied.  However, we need to return a negative error code, -EFAULT, to
the user.

Fixes: 87f4c217413a ("vhost-vdpa: introduce uAPI to get the number of virtqueue groups")
Fixes: e96ef636f154 ("vhost-vdpa: introduce uAPI to get the number of address spaces")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/vhost/vdpa.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index 3e86080041fc..935a1d0ddb97 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -609,11 +609,13 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
 		r = vhost_vdpa_get_vring_num(v, argp);
 		break;
 	case VHOST_VDPA_GET_GROUP_NUM:
-		r = copy_to_user(argp, &v->vdpa->ngroups,
-				 sizeof(v->vdpa->ngroups));
+		if (copy_to_user(argp, &v->vdpa->ngroups,
+				 sizeof(v->vdpa->ngroups)))
+			r = -EFAULT;
 		break;
 	case VHOST_VDPA_GET_AS_NUM:
-		r = copy_to_user(argp, &v->vdpa->nas, sizeof(v->vdpa->nas));
+		if (copy_to_user(argp, &v->vdpa->nas, sizeof(v->vdpa->nas)))
+			r = -EFAULT;
 		break;
 	case VHOST_SET_LOG_BASE:
 	case VHOST_SET_LOG_FD:
-- 
2.35.1

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

* Re: [PATCH] vhost-vdpa: return -EFAULT on copy_to_user() failure
  2022-05-23  8:33 ` Dan Carpenter
@ 2022-05-23 10:44   ` Stefano Garzarella
  -1 siblings, 0 replies; 4+ messages in thread
From: Stefano Garzarella @ 2022-05-23 10:44 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Michael S. Tsirkin, Gautam Dawar, Christophe JAILLET,
	kernel-janitors, kvm, virtualization

On Mon, May 23, 2022 at 11:33:26AM +0300, Dan Carpenter wrote:
>The copy_to_user() function returns the number of bytes remaining to be
>copied.  However, we need to return a negative error code, -EFAULT, to
>the user.
>
>Fixes: 87f4c217413a ("vhost-vdpa: introduce uAPI to get the number of virtqueue groups")
>Fixes: e96ef636f154 ("vhost-vdpa: introduce uAPI to get the number of address spaces")
>Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>---
> drivers/vhost/vdpa.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>

>
>diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
>index 3e86080041fc..935a1d0ddb97 100644
>--- a/drivers/vhost/vdpa.c
>+++ b/drivers/vhost/vdpa.c
>@@ -609,11 +609,13 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
> 		r = vhost_vdpa_get_vring_num(v, argp);
> 		break;
> 	case VHOST_VDPA_GET_GROUP_NUM:
>-		r = copy_to_user(argp, &v->vdpa->ngroups,
>-				 sizeof(v->vdpa->ngroups));
>+		if (copy_to_user(argp, &v->vdpa->ngroups,
>+				 sizeof(v->vdpa->ngroups)))
>+			r = -EFAULT;
> 		break;
> 	case VHOST_VDPA_GET_AS_NUM:
>-		r = copy_to_user(argp, &v->vdpa->nas, sizeof(v->vdpa->nas));
>+		if (copy_to_user(argp, &v->vdpa->nas, sizeof(v->vdpa->nas)))
>+			r = -EFAULT;
> 		break;
> 	case VHOST_SET_LOG_BASE:
> 	case VHOST_SET_LOG_FD:
>-- 
>2.35.1
>
>_______________________________________________
>Virtualization mailing list
>Virtualization@lists.linux-foundation.org
>https://lists.linuxfoundation.org/mailman/listinfo/virtualization
>


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

* Re: [PATCH] vhost-vdpa: return -EFAULT on copy_to_user() failure
@ 2022-05-23 10:44   ` Stefano Garzarella
  0 siblings, 0 replies; 4+ messages in thread
From: Stefano Garzarella @ 2022-05-23 10:44 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: kvm, Michael S. Tsirkin, kernel-janitors, virtualization,
	Christophe JAILLET, Gautam Dawar

On Mon, May 23, 2022 at 11:33:26AM +0300, Dan Carpenter wrote:
>The copy_to_user() function returns the number of bytes remaining to be
>copied.  However, we need to return a negative error code, -EFAULT, to
>the user.
>
>Fixes: 87f4c217413a ("vhost-vdpa: introduce uAPI to get the number of virtqueue groups")
>Fixes: e96ef636f154 ("vhost-vdpa: introduce uAPI to get the number of address spaces")
>Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>---
> drivers/vhost/vdpa.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>

>
>diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
>index 3e86080041fc..935a1d0ddb97 100644
>--- a/drivers/vhost/vdpa.c
>+++ b/drivers/vhost/vdpa.c
>@@ -609,11 +609,13 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
> 		r = vhost_vdpa_get_vring_num(v, argp);
> 		break;
> 	case VHOST_VDPA_GET_GROUP_NUM:
>-		r = copy_to_user(argp, &v->vdpa->ngroups,
>-				 sizeof(v->vdpa->ngroups));
>+		if (copy_to_user(argp, &v->vdpa->ngroups,
>+				 sizeof(v->vdpa->ngroups)))
>+			r = -EFAULT;
> 		break;
> 	case VHOST_VDPA_GET_AS_NUM:
>-		r = copy_to_user(argp, &v->vdpa->nas, sizeof(v->vdpa->nas));
>+		if (copy_to_user(argp, &v->vdpa->nas, sizeof(v->vdpa->nas)))
>+			r = -EFAULT;
> 		break;
> 	case VHOST_SET_LOG_BASE:
> 	case VHOST_SET_LOG_FD:
>-- 
>2.35.1
>
>_______________________________________________
>Virtualization mailing list
>Virtualization@lists.linux-foundation.org
>https://lists.linuxfoundation.org/mailman/listinfo/virtualization
>

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

end of thread, other threads:[~2022-05-23 10:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-23  8:33 [PATCH] vhost-vdpa: return -EFAULT on copy_to_user() failure Dan Carpenter
2022-05-23  8:33 ` Dan Carpenter
2022-05-23 10:44 ` Stefano Garzarella
2022-05-23 10:44   ` Stefano Garzarella

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.