aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2026-11-19 07:38:03 +0100
committerStefano Brivio <sbrivio@redhat.com>2026-11-23 00:39:37 +0100
commitbab97debe61e484b1d983e687fb5133fb6bd3c52 (patch)
tree542b47ab151a57c81f72bce4e75c6be6f1b2a293
parent9113dc6692f4c37d5d5363e640ee5340612123ea (diff)
downloadpasst-bab97debe61e484b1d983e687fb5133fb6bd3c52.tar
passt-bab97debe61e484b1d983e687fb5133fb6bd3c52.tar.gz
passt-bab97debe61e484b1d983e687fb5133fb6bd3c52.tar.bz2
passt-bab97debe61e484b1d983e687fb5133fb6bd3c52.tar.lz
passt-bab97debe61e484b1d983e687fb5133fb6bd3c52.tar.xz
passt-bab97debe61e484b1d983e687fb5133fb6bd3c52.tar.zst
passt-bab97debe61e484b1d983e687fb5133fb6bd3c52.zip
vhost-user: Abort right away on invalid queue indices from front-end
Mayur Agnihotri reports that, for vhost-user commands SET_VRING_NUM, SET_VRING_ADDR, SET_VRING_BASE, and GET_VRING_BASE, we use the queue index passed by the front-end without further validation. We have, however, only VHOST_USER_MAX_VQS (2) entries in vdev->vq[], which might lead to out-of-bound accesses. These are not security relevant, because the front-end (hypervisor) is trusted, and even the most critical robustness impact we could achieve is setting feature flags, or the equivalent outcome of other (unintended) commands that the vhost-user front-end could anyway issue. In any case, this is a set of CWE-129 weaknesses that we want to address, regardless of the impact, just like QEMU commit 758ef96a2dba ("libvhost-user: protect against OOB vring queue access") did for the equivalent implementation in QEMU: verify the indices before using them, and abort right away if they are invalid. On top of those four commands, note that the handlers for SET_VRING_KICK and SET_VRING_ERR have the same issue: fix them as well. We could simply ignore those commands, and that might appear a more graceful way of handling invalid values, but if we receive bad indices in these commands, we should assume that something went wrong with our state and, overall, we'll probably offer users a better behaviour by terminating and giving the hypervisor the chance to see that the back-end failed. At least in some cases (e.g. libvirt), by default, we would be restarted and the front-end would try to reconnect. While at it, change some indices to unsigned types, for consistency and for correctness. We would like to thank Mayur Agnihotri for the detailed report and for the insightful investigation. Reported-by: Mayur Agnihotri <mayur.agnihotri0021@gmail.com> Suggested-by: Mayur Agnihotri <mayur.agnihotri0021@gmail.com> Signed-off-by: Stefano Brivio <sbrivio@redhat.com> Reviewed-by: Laurent Vivier <lvivier@redhat.com>
-rw-r--r--vhost_user.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/vhost_user.c b/vhost_user.c
index 272295f..627bbee 100644
--- a/vhost_user.c
+++ b/vhost_user.c
@@ -639,6 +639,10 @@ static bool vu_set_vring_num_exec(struct vu_dev *vdev,
trace("State.index: %u", idx);
trace("State.num: %u", num);
+
+ if (idx >= VHOST_USER_MAX_VQS)
+ die("Invalid vhost-user queue index (SET_VRING_NUM): %u", idx);
+
vdev->vq[idx].vring.num = num;
return false;
@@ -659,7 +663,14 @@ static bool vu_set_vring_addr_exec(struct vu_dev *vdev,
* can be unaligned as it is packed.
*/
struct vhost_vring_addr addr = vmsg->payload.addr;
- struct vu_virtq *vq = &vdev->vq[addr.index];
+ struct vu_virtq *vq;
+
+ if (addr.index >= VHOST_USER_MAX_VQS) {
+ die("Invalid vhost-user queue index (SET_VRING_ADDR): %u",
+ addr.index);
+ }
+
+ vq = &vdev->vq[addr.index];
debug("vhost_vring_addr:");
debug(" index: %d", addr.index);
@@ -705,6 +716,10 @@ static bool vu_set_vring_base_exec(struct vu_dev *vdev,
debug("State.index: %u", idx);
debug("State.num: %u", num);
+
+ if (idx >= VHOST_USER_MAX_VQS)
+ die("Invalid vhost-user queue index (SET_VRING_BASE): %u", idx);
+
vdev->vq[idx].shadow_avail_idx = vdev->vq[idx].last_avail_idx = num;
return false;
@@ -724,6 +739,10 @@ static bool vu_get_vring_base_exec(struct vu_dev *vdev,
unsigned int idx = vmsg->payload.state.index;
debug("State.index: %u", idx);
+
+ if (idx >= VHOST_USER_MAX_VQS)
+ die("Invalid vhost-user queue index (GET_VRING_BASE): %u", idx);
+
vmsg->payload.state.num = vdev->vq[idx].last_avail_idx;
vmsg->hdr.size = sizeof(vmsg->payload.state);
@@ -792,11 +811,14 @@ static void vu_check_queue_msg_file(struct vhost_user_msg *vmsg)
static bool vu_set_vring_kick_exec(struct vu_dev *vdev,
struct vhost_user_msg *vmsg)
{
+ unsigned idx = vmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK;
bool nofd = vmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK;
- int idx = vmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK;
debug("u64: 0x%016"PRIx64, vmsg->payload.u64);
+ if (idx >= VHOST_USER_MAX_VQS)
+ die("Invalid vhost-user queue index (SET_VRING_KICK): %u", idx);
+
vu_check_queue_msg_file(vmsg);
if (vdev->vq[idx].kick_fd != -1) {
@@ -832,11 +854,14 @@ static bool vu_set_vring_kick_exec(struct vu_dev *vdev,
static bool vu_set_vring_call_exec(struct vu_dev *vdev,
struct vhost_user_msg *vmsg)
{
+ unsigned idx = vmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK;
bool nofd = vmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK;
- int idx = vmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK;
debug("u64: 0x%016"PRIx64, vmsg->payload.u64);
+ if (idx >= VHOST_USER_MAX_VQS)
+ die("Invalid vhost-user queue index (SET_VRING_ADDR): %u", idx);
+
vu_check_queue_msg_file(vmsg);
if (vdev->vq[idx].call_fd != -1) {
@@ -867,11 +892,14 @@ static bool vu_set_vring_call_exec(struct vu_dev *vdev,
static bool vu_set_vring_err_exec(struct vu_dev *vdev,
struct vhost_user_msg *vmsg)
{
+ unsigned idx = vmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK;
bool nofd = vmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK;
- int idx = vmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK;
debug("u64: 0x%016"PRIx64, vmsg->payload.u64);
+ if (idx >= VHOST_USER_MAX_VQS)
+ die("Invalid vhost-user queue index (SET_VRING_ERR): %u", idx);
+
vu_check_queue_msg_file(vmsg);
if (vdev->vq[idx].err_fd != -1) {