Netdev List
 help / color / mirror / Atom feed
* [PATCH] vhost/vringh: reject zero-length indirect descriptor tables
@ 2026-10-21  7:02 Fang Xieyan
  2026-11-02 17:30 ` Michael S. Tsirkin
  0 siblings, 1 reply; 5+ messages in thread
From: Fang Xieyan @ 2026-10-21  7:02 UTC (permalink / raw)
  To: Michael S . Tsirkin, Jason Wang, Eugenio Pérez
  Cc: Stefano Garzarella, virtualization, kvm, netdev, linux-kernel,
	stable, Guanglei Zhu

move_to_indirect() accepts an indirect descriptor with a zero length,
setting desc_max to 0. __vringh_iov() then reads descs[0] before
checking the descriptor bounds, resulting in an out-of-bounds read.

Reject a zero-length indirect table in move_to_indirect() so the
caller returns -EINVAL before dereferencing the table. Also use the
converted length in the warning to report invalid lengths correctly
when the vring byte order differs from the CPU byte order.

Fixes: f87d0fbb5798 ("vringh: host-side implementation of virtio rings.")
Cc: stable@vger.kernel.org
Reviewed-by: Guanglei Zhu <zhugl3@xiaopeng.com>
Signed-off-by: Fang Xieyan <fangxy@xiaopeng.com>
---
 drivers/vhost/vringh.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
index 9066f9f12ba1..ce4f5a02c8d2 100644
--- a/drivers/vhost/vringh.c
+++ b/drivers/vhost/vringh.c
@@ -197,8 +197,8 @@ 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 || len % sizeof(struct vring_desc))) {
+		vringh_bad("Strange indirect len %u", len);
 		return -EINVAL;
 	}
 
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] vhost/vringh: reject zero-length indirect descriptor tables
  2026-10-21  7:02 [PATCH] vhost/vringh: reject zero-length indirect descriptor tables Fang Xieyan
@ 2026-11-02 17:30 ` Michael S. Tsirkin
  2026-11-03  3:29   ` Fang Xieyan
  0 siblings, 1 reply; 5+ messages in thread
From: Michael S. Tsirkin @ 2026-11-02 17:30 UTC (permalink / raw)
  To: Fang Xieyan
  Cc: Jason Wang, Eugenio Pérez, Stefano Garzarella,
	virtualization, kvm, netdev, linux-kernel, stable, Guanglei Zhu

On Wed, Oct 21, 2026 at 03:02:42PM +0800, Fang Xieyan wrote:
> move_to_indirect() accepts an indirect descriptor with a zero length,
> setting desc_max to 0. __vringh_iov() then reads descs[0] before
> checking the descriptor bounds, resulting in an out-of-bounds read.
> 
> Reject a zero-length indirect table in move_to_indirect() so the
> caller returns -EINVAL before dereferencing the table. Also use the
> converted length in the warning to report invalid lengths correctly
> when the vring byte order differs from the CPU byte order.
> 
> Fixes: f87d0fbb5798 ("vringh: host-side implementation of virtio rings.")
> Cc: stable@vger.kernel.org
> Reviewed-by: Guanglei Zhu <zhugl3@xiaopeng.com>
> Signed-off-by: Fang Xieyan <fangxy@xiaopeng.com>


Isn't this already addressed by
Subject: [PATCH v2] vringh: reject empty / undersized indirect descriptor tables
that you posted previously?

> ---
>  drivers/vhost/vringh.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
> index 9066f9f12ba1..ce4f5a02c8d2 100644
> --- a/drivers/vhost/vringh.c
> +++ b/drivers/vhost/vringh.c
> @@ -197,8 +197,8 @@ 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 || len % sizeof(struct vring_desc))) {
> +		vringh_bad("Strange indirect len %u", len);
>  		return -EINVAL;
>  	}
>  
> -- 
> 2.50.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] vhost/vringh: reject zero-length indirect descriptor tables
  2026-11-02 17:30 ` Michael S. Tsirkin
@ 2026-11-03  3:29   ` Fang Xieyan
  2026-11-03 10:57     ` Michael S. Tsirkin
  0 siblings, 1 reply; 5+ messages in thread
From: Fang Xieyan @ 2026-11-03  3:29 UTC (permalink / raw)
  To: Michael S . Tsirkin
  Cc: Jason Wang, Eugenio Pérez, Stefano Garzarella,
	virtualization, kvm, netdev, linux-kernel, stable, Guanglei Zhu

Hi Michael,

Yes, same fix - sorry. The October 21 posting is a duplicate
of the v2 I posted on September 26:

https://lore.kernel.org/virtualization/20260926160755.21485-1-fangxy@xiaopeng.com/

I resent it as a new patch instead of a v3.

The !len form is equivalent to v2's len < sizeof(struct
vring_desc) check when combined with the modulo check -
zero is the only length below one descriptor that is also
a multiple of the descriptor size.

The diagnostic change is to pass the byte-order converted
len instead of the raw desc->len, so the reported length is
correct when the vring byte order differs from the CPU byte
order.

Would you prefer that I send a v3 on the original v2 thread
with this diagnostic correction, or should I drop the
October 21 posting and leave v2 as is?

Thanks,
Fang

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] vhost/vringh: reject zero-length indirect descriptor tables
  2026-11-03  3:29   ` Fang Xieyan
@ 2026-11-03 10:57     ` Michael S. Tsirkin
  2026-11-03 14:29       ` Fang Xieyan
  0 siblings, 1 reply; 5+ messages in thread
From: Michael S. Tsirkin @ 2026-11-03 10:57 UTC (permalink / raw)
  To: Fang Xieyan
  Cc: Jason Wang, Eugenio Pérez, Stefano Garzarella,
	virtualization, kvm, netdev, linux-kernel, stable, Guanglei Zhu

On Tue, Nov 03, 2026 at 11:29:35AM +0800, Fang Xieyan wrote:
> Hi Michael,
> 
> Yes, same fix - sorry. The October 21 posting is a duplicate
> of the v2 I posted on September 26:
> 
> https://lore.kernel.org/virtualization/20260926160755.21485-1-fangxy@xiaopeng.com/
> 
> I resent it as a new patch instead of a v3.
> 
> The !len form is equivalent to v2's len < sizeof(struct
> vring_desc) check when combined with the modulo check -
> zero is the only length below one descriptor that is also
> a multiple of the descriptor size.
> 
> The diagnostic change is to pass the byte-order converted
> len instead of the raw desc->len, so the reported length is
> correct when the vring byte order differs from the CPU byte
> order.
> 
> Would you prefer that I send a v3 on the original v2 thread
> with this diagnostic correction, or should I drop the
> October 21 posting and leave v2 as is?
> 
> Thanks,
> Fang

pls take a look at my tree, vhost branch. if you want any
changes made wrt that, pls let me know.

-- 
MST


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] vhost/vringh: reject zero-length indirect descriptor tables
  2026-11-03 10:57     ` Michael S. Tsirkin
@ 2026-11-03 14:29       ` Fang Xieyan
  0 siblings, 0 replies; 5+ messages in thread
From: Fang Xieyan @ 2026-11-03 14:29 UTC (permalink / raw)
  To: Michael S . Tsirkin
  Cc: Jason Wang, Eugenio Pérez, Stefano Garzarella,
	virtualization, kvm, netdev, linux-kernel, stable, Guanglei Zhu

Hi Michael,

Thanks. I checked the applied v2 (60a792b97933) in your
vhost branch and it looks good.

One small thing on top of it: vringh_bad() there still
passes the raw desc->len, so the reported length reads
wrong when the vring byte order differs from the CPU
byte order. The October 21 posting had this right; the
rest is fine as is.

Happy to send a one-line follow-up on top of your branch
if you want it; otherwise fine to leave as is.

Thanks,
Fang

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-03 14:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-21  7:02 [PATCH] vhost/vringh: reject zero-length indirect descriptor tables Fang Xieyan
2026-11-02 17:30 ` Michael S. Tsirkin
2026-11-03  3:29   ` Fang Xieyan
2026-11-03 10:57     ` Michael S. Tsirkin
2026-11-03 14:29       ` Fang Xieyan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox