Skip to content

Commit 7922460

Browse files
Dan Carpentermstsirkin
authored andcommitted
vhost_vdpa: Return -EFAULT if copy_from_user() fails
The copy_to/from_user() functions return the number of bytes which we weren't able to copy but the ioctl should return -EFAULT if they fail. Fixes: a127c5b ("vhost-vdpa: fix backend feature ioctls") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Link: https://lore.kernel.org/r/20201023120853.GI282278@mwanda Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Cc: stable@vger.kernel.org Acked-by: Jason Wang <jasowang@redhat.com>
1 parent 70a62fc commit 7922460

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

drivers/vhost/vdpa.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,11 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
432432
void __user *argp = (void __user *)arg;
433433
u64 __user *featurep = argp;
434434
u64 features;
435-
long r;
435+
long r = 0;
436436

437437
if (cmd == VHOST_SET_BACKEND_FEATURES) {
438-
r = copy_from_user(&features, featurep, sizeof(features));
439-
if (r)
440-
return r;
438+
if (copy_from_user(&features, featurep, sizeof(features)))
439+
return -EFAULT;
441440
if (features & ~VHOST_VDPA_BACKEND_FEATURES)
442441
return -EOPNOTSUPP;
443442
vhost_set_backend_features(&v->vdev, features);
@@ -480,7 +479,8 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
480479
break;
481480
case VHOST_GET_BACKEND_FEATURES:
482481
features = VHOST_VDPA_BACKEND_FEATURES;
483-
r = copy_to_user(featurep, &features, sizeof(features));
482+
if (copy_to_user(featurep, &features, sizeof(features)))
483+
r = -EFAULT;
484484
break;
485485
case VHOST_VDPA_GET_IOVA_RANGE:
486486
r = vhost_vdpa_get_iova_range(v, argp);

0 commit comments

Comments
 (0)