vhost/scsi: Use copy_to_iter() to send control queue response

Uses copy_to_iter() instead of __copy_to_user() in order to ensure we
support arbitrary layouts and an input buffer split across iov entries.

Fixes: 0d02dbd68c47b ("vhost/scsi: Respond to control queue operations")
Signed-off-by: Bijan Mottahedeh <bijan.mottahedeh@oracle.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

authored by Bijan Mottahedeh and committed by Michael S. Tsirkin 8e5dadfe 74ad7419

Changed files
+12 -8
drivers
vhost
+12 -8
drivers/vhost/scsi.c
··· 1127 1127 struct vhost_virtqueue *vq, 1128 1128 struct vhost_scsi_ctx *vc) 1129 1129 { 1130 - struct virtio_scsi_ctrl_tmf_resp __user *resp; 1131 1130 struct virtio_scsi_ctrl_tmf_resp rsp; 1131 + struct iov_iter iov_iter; 1132 1132 int ret; 1133 1133 1134 1134 pr_debug("%s\n", __func__); 1135 1135 memset(&rsp, 0, sizeof(rsp)); 1136 1136 rsp.response = VIRTIO_SCSI_S_FUNCTION_REJECTED; 1137 - resp = vq->iov[vc->out].iov_base; 1138 - ret = __copy_to_user(resp, &rsp, sizeof(rsp)); 1139 - if (!ret) 1137 + 1138 + iov_iter_init(&iov_iter, READ, &vq->iov[vc->out], vc->in, sizeof(rsp)); 1139 + 1140 + ret = copy_to_iter(&rsp, sizeof(rsp), &iov_iter); 1141 + if (likely(ret == sizeof(rsp))) 1140 1142 vhost_add_used_and_signal(&vs->dev, vq, vc->head, 0); 1141 1143 else 1142 1144 pr_err("Faulted on virtio_scsi_ctrl_tmf_resp\n"); ··· 1149 1147 struct vhost_virtqueue *vq, 1150 1148 struct vhost_scsi_ctx *vc) 1151 1149 { 1152 - struct virtio_scsi_ctrl_an_resp __user *resp; 1153 1150 struct virtio_scsi_ctrl_an_resp rsp; 1151 + struct iov_iter iov_iter; 1154 1152 int ret; 1155 1153 1156 1154 pr_debug("%s\n", __func__); 1157 1155 memset(&rsp, 0, sizeof(rsp)); /* event_actual = 0 */ 1158 1156 rsp.response = VIRTIO_SCSI_S_OK; 1159 - resp = vq->iov[vc->out].iov_base; 1160 - ret = __copy_to_user(resp, &rsp, sizeof(rsp)); 1161 - if (!ret) 1157 + 1158 + iov_iter_init(&iov_iter, READ, &vq->iov[vc->out], vc->in, sizeof(rsp)); 1159 + 1160 + ret = copy_to_iter(&rsp, sizeof(rsp), &iov_iter); 1161 + if (likely(ret == sizeof(rsp))) 1162 1162 vhost_add_used_and_signal(&vs->dev, vq, vc->head, 0); 1163 1163 else 1164 1164 pr_err("Faulted on virtio_scsi_ctrl_an_resp\n");