scsi_ioctl.c: switch SCSI_IOCTL_GET_IDLUN to copy_to_user()
authorAl Viro <viro@zeniv.linux.org.uk>
Wed, 12 Feb 2020 16:36:05 +0000 (11:36 -0500)
committerAl Viro <viro@zeniv.linux.org.uk>
Sat, 25 Apr 2020 22:06:39 +0000 (18:06 -0400)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
drivers/scsi/scsi_ioctl.c

index 8f3af87b6bb0c3a1f36ec0e45dc574cc4e40df14..45d04b7b26439896b3caa4654222d77255994750 100644 (file)
@@ -211,18 +211,18 @@ static int scsi_ioctl_common(struct scsi_device *sdev, int cmd, void __user *arg
        }
 
        switch (cmd) {
-       case SCSI_IOCTL_GET_IDLUN:
-               if (!access_ok(arg, sizeof(struct scsi_idlun)))
+       case SCSI_IOCTL_GET_IDLUN: {
+               struct scsi_idlun v = {
+                       .dev_id = (sdev->id & 0xff)
+                                + ((sdev->lun & 0xff) << 8)
+                                + ((sdev->channel & 0xff) << 16)
+                                + ((sdev->host->host_no & 0xff) << 24),
+                       .host_unique_id = sdev->host->unique_id
+               };
+               if (copy_to_user(arg, &v, sizeof(struct scsi_idlun)))
                        return -EFAULT;
-
-               __put_user((sdev->id & 0xff)
-                        + ((sdev->lun & 0xff) << 8)
-                        + ((sdev->channel & 0xff) << 16)
-                        + ((sdev->host->host_no & 0xff) << 24),
-                        &((struct scsi_idlun __user *)arg)->dev_id);
-               __put_user(sdev->host->unique_id,
-                        &((struct scsi_idlun __user *)arg)->host_unique_id);
                return 0;
+       }
        case SCSI_IOCTL_GET_BUS_NUMBER:
                return put_user(sdev->host->host_no, (int __user *)arg);
        case SCSI_IOCTL_PROBE_HOST: