mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
vhost-scsi: validate event queue descriptor direction
vhost_get_vq_desc() returns the number of device readable (output) and
device writable (input) iovec segments. A guest can submit an eventq
descriptor chain that fills vq->iov with output segments, setting out
to ARRAY_SIZE(vq->iov) and in to zero.
When the host later queues a vhost-scsi event, vhost_scsi_do_evt_work()
uses out as the index of the first input segment. This accesses one element
beyond vq->iov and triggers an array-index-out-of-bounds report. With
panic_on_warn enabled, the report panics the host.
The event queue accepts device writable buffers only. Reject chains that
contain output segments or lack an input segment before using out as an
index. The input check prevents the out-of-bounds access, while the output
check validates the eventq descriptor direction.
I found the descriptor direction issue myself, though the patch was
written with AI assistance. The out-of-bounds read with an
output-only chain was separately reported by Jia Jia.
Fixes: a6c9af8736 ("tcm_vhost: Add hotplug/hotunplug support")
Reported-by: Jia Jia <physicalmtea@gmail.com>
Assisted-by: OpenAI-Codex:GPT-5
Signed-off-by: Linfeng Sun <linfeng.sun.dev@gmail.com>
Message-ID: <20261009-fix-arrary-index-out-of-bounds-in-vhost_scsi_complete_events-v2-1-1f7689a54735@gmail.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
1f5bc40e33
commit
3d8c5b714c
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user