Skip to contentSkip to conversation

vhost-vdpa: Set s.num in GET_VRING_GROUP

PATCH In review Dan Carpenter 3 participants 4 messages Sep 27, 2025 – Sep 29, 2025

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

PATCH 1/1 vhost-vdpa: Set s.num in GET_VRING_GROUP

The group is supposed to be copied to the user, but it wasn't assigned until after the copy_to_user(). Move the "s.num = group;" earlier.

Fixes ffc3634b6696 ("vduse: add vq group support")

---
This goes through the kvm tree I think.

 drivers/vhost/vdpa.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/vhost/vdpa.c +2 -2
index 6305382eacbb..25ab4d06e559 100644
@@ -667,9 +667,9 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
 		group = ops->get_vq_group(vdpa, idx);
 		if (group >= vdpa->ngroups || group > U32_MAX || group < 0)
 			return -EIO;
-		else if (copy_to_user(argp, &s, sizeof(s)))
-			return -EFAULT;
 		s.num = group;
+		if (copy_to_user(argp, &s, sizeof(s)))
+			return -EFAULT;
 		return 0;
 	}
 	case VHOST_VDPA_GET_VRING_DESC_GROUP:
Signature · 1 line
2.51.0
#1 lore raw
Quoted 7 lines · Dan Carpenter

The group is supposed to be copied to the user, but it wasn't assigned until after the copy_to_user(). Move the "s.num = group;" earlier.

Fixes ffc3634b6696 ("vduse: add vq group support")

---
This goes through the kvm tree I think.

Thanks for the patch!

IIUC this was in my tree for next, but more testing and review found issues (like this one) so I dropped it for now.

Quoted 21 lines
 drivers/vhost/vdpa.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/vhost/vdpa.c +2 -2
index 6305382eacbb..25ab4d06e559 100644
@@ -667,9 +667,9 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
 		group = ops->get_vq_group(vdpa, idx);
 		if (group >= vdpa->ngroups || group > U32_MAX || group < 0)
 			return -EIO;
-		else if (copy_to_user(argp, &s, sizeof(s)))
-			return -EFAULT;
 		s.num = group;
+		if (copy_to_user(argp, &s, sizeof(s)))
+			return -EFAULT;
 		return 0;
 	}
 	case VHOST_VDPA_GET_VRING_DESC_GROUP:
Signature · 1 line
2.51.0
#2 lore raw
Quoted 11 lines · Michael S. Tsirkin
Quoted 7 lines · Dan Carpenter

The group is supposed to be copied to the user, but it wasn't assigned until after the copy_to_user(). Move the "s.num = group;" earlier.

Fixes ffc3634b6696 ("vduse: add vq group support")

---
This goes through the kvm tree I think.

Quoted 5 lines

Thanks for the patch!

IIUC this was in my tree for next, but more testing and review found issues (like this one) so I dropped it for now.

Yes, that's fixed in v5.

Quoted 22 lines
Quoted 21 lines
 drivers/vhost/vdpa.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/vhost/vdpa.c +2 -3
index 6305382eacbb..25ab4d06e559 100644
@@ -667,9 +667,9 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
              group = ops->get_vq_group(vdpa, idx);
              if (group >= vdpa->ngroups || group > U32_MAX || group < 0)
                      return -EIO;
-             else if (copy_to_user(argp, &s, sizeof(s)))
-                     return -EFAULT;
              s.num = group;
+             if (copy_to_user(argp, &s, sizeof(s)))
+                     return -EFAULT;
              return 0;
      }
      case VHOST_VDPA_GET_VRING_DESC_GROUP:
--

2.51.0

#3 lore raw
In reply to Dan Carpenter
Quoted 18 lines · Dan Carpenter

The group is supposed to be copied to the user, but it wasn't assigned until after the copy_to_user(). Move the "s.num = group;" earlier.

Fixes ffc3634b6696 ("vduse: add vq group support")

---
This goes through the kvm tree I think.

 drivers/vhost/vdpa.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/vhost/vdpa.c +0 -0
index 6305382eacbb..25ab4d06e559 100644
@@ -667,9 +667,9 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
                group = ops->get_vq_group(vdpa, idx);

drivers/vhost/vdpa.c static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, · line 675

Quoted 10 lines
drivers/vhost/vdpa.c +2 -2
                if (group >= vdpa->ngroups || group > U32_MAX || group < 0)
                        return -EIO;
-               else if (copy_to_user(argp, &s, sizeof(s)))
-                       return -EFAULT;
                s.num = group;
+               if (copy_to_user(argp, &s, sizeof(s)))
+                       return -EFAULT;
                return 0;
        }
        case VHOST_VDPA_GET_VRING_DESC_GROUP:

Thank you very much for the report Dan! that should be fixed in v5.