diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index 2e060c76ce76..7a168de61001 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c @@ -638,6 +638,16 @@ vhost_scsi_do_evt_work(struct vhost_scsi *vs, struct vhost_scsi_evt *evt) return; } + /* + * Eventq buffers are device-writable only. A nonzero in count + * guarantees that out is within the bounds of vq->iov. + */ + if (unlikely(out || !in)) { + vq_err(vq, "Invalid event buffer: out %u, in %u\n", out, in); + vs->vs_events_missed = true; + return; + } + if ((vq->iov[out].iov_len != sizeof(struct virtio_scsi_event))) { vq_err(vq, "Expecting virtio_scsi_event, got %zu bytes\n", vq->iov[out].iov_len);