Skip to contentSkip to conversation

vhost_net: do not report a used len larger than receive buffer size

PATCH NAK Jason Wang 2 participants 2 messages Feb 12, 2014

Subsystems (5)
lore
Share & tools
lore

Jason Wang

author
#0 lore raw

PATCH 1/1 vhost_net: do not report a used len larger than receive buffer size

Currently, even if the packet were truncated by lower socket, we still report the packet size as the used len which may confuse guest driver. Fixes this by returning the size of guest receive buffer instead.

Fixes 3a4d5c94e959359ece6d6b55045c3f046677f55c
(vhost_net: a kernel-level virtio server)

Cc Michael S. Tsirkin <[email protected]>
---
 drivers/vhost/net.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/vhost/net.c +2 -1
index 9a68409..06268a0 100644
@@ -525,7 +525,8 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
 		++headcount;
 		seg += in;
 	}
-	heads[headcount - 1].len += datalen;
+	if (likely(datalen < 0))
+		heads[headcount - 1].len += datalen;
 	*iovcount = seg;
 	if (unlikely(log))
 		*log_num = nlogs;
Signature · 1 line
1.8.3.2
maintainer NAK
#1 lore raw
Quoted 9 lines · Jason Wang

Currently, even if the packet were truncated by lower socket, we still report the packet size as the used len which may confuse guest driver. Fixes this by returning the size of guest receive buffer instead.

Fixes 3a4d5c94e959359ece6d6b55045c3f046677f55c
(vhost_net: a kernel-level virtio server)

Cc Michael S. Tsirkin <[email protected]>

As discussed off-line:

NAK

and a fixed version will be sent.

Quoted 20 lines
---
 drivers/vhost/net.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/vhost/net.c +2 -1
index 9a68409..06268a0 100644
@@ -525,7 +525,8 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
 		++headcount;
 		seg += in;
 	}
-	heads[headcount - 1].len += datalen;
+	if (likely(datalen < 0))
+		heads[headcount - 1].len += datalen;
 	*iovcount = seg;
 	if (unlikely(log))
 		*log_num = nlogs;
Signature · 1 line
1.8.3.2