[PATCH v2] vringh: reject empty / undersized indirect descriptor tables

From: Fang Xieyan

Date: Sat Sep 26 2026 - 12:08:50 EST


move_to_indirect() validates an indirect descriptor table only with
"len % sizeof(struct vring_desc)". A descriptor flagged
VRING_DESC_F_INDIRECT with len == 0 passes that test, so *desc_max is
set to 0 while *descs points at the empty table. __vringh_iov() then
copies one struct vring_desc from descs[0] -- 16 bytes past the end of
the table -- before the "indirect_count > desc_max" loop detection
aborts the walk. The over-read value is discarded when the walk aborts
and is never used to map anything, but the access itself is out of
bounds.

Reject any len smaller than one descriptor, alongside the existing
stride check, so an empty table is refused with -EINVAL and no
descriptor is ever fetched from it.

Fixes: f87d0fbb5798 ("vringh: host-side implementation of virtio rings.")
Cc: stable@xxxxxxxxxxxxxxx
Assisted-by: Hawkeye:GLM-5.3-flash
Assisted-by: Qoder:Qwen3.8-Max
Signed-off-by: Fang Xieyan <fangxy@xxxxxxxxxxxx>
---
drivers/vhost/vringh.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

Changes in v2:
- Commit message rewritten per Michael's review: the over-read value
is copied into a local struct vring_desc and never reaches the
caller, so the security framing ("leak" etc.) is dropped and this
is presented as the plain out-of-bounds read fix it is.
- Code is unchanged; the diff is identical to v1.

Testing:
Userspace reproducer carrying the move_to_indirect()/__vringh_iov()
logic with an instrumented copy() (len == 0 indirect table, 2048-byte
mapped region followed by 64 guard bytes):

without the fix: reads 16 bytes past the table end, returns -ELOOP
with the fix: returns -EINVAL, no read past the table end

diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
index 9066f9f..0767748 100644
--- a/drivers/vhost/vringh.c
+++ b/drivers/vhost/vringh.c
@@ -197,8 +197,9 @@ static int move_to_indirect(const struct vringh *vrh,
}

len = vringh32_to_cpu(vrh, desc->len);
- if (unlikely(len % sizeof(struct vring_desc))) {
- vringh_bad("Strange indirect len %u", desc->len);
+ if (unlikely(len < sizeof(struct vring_desc) ||
+ len % sizeof(struct vring_desc))) {
+ vringh_bad("Invalid indirect len %u", desc->len);
return -EINVAL;
}

--
2.50.1