Skip to contentSkip to conversation

vhost/net: length miscalculation

PATCH In review Michael S. Tsirkin 3 participants 6 messages Jan 7, 2015 – Jan 8, 2015

Subsystems (5)
lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

PATCH 1/1 vhost/net: length miscalculation

commit 8b38694a2dc8b18374310df50174f1e4376d6824
vhost/net: virtio 1.0 byte swap
had this chunk:
- heads[headcount - 1].len += datalen;
+ heads[headcount - 1].len = cpu_to_vhost32(vq, len - datalen);

This adds datalen with the wrong sign, causing guest panics.

Fixes 8b38694a2dc8b18374310df50174f1e4376d6824

---

Alex, could you please confirm this fixes the crash for you?

 drivers/vhost/net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vhost/net.c +1 -1
index 14419a8..d415d69 100644
@@ -538,7 +538,7 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
 		++headcount;
 		seg += in;
 	}
-	heads[headcount - 1].len = cpu_to_vhost32(vq, len - datalen);
+	heads[headcount - 1].len = cpu_to_vhost32(vq, len + datalen);
 	*iovcount = seg;
 	if (unlikely(log))
 		*log_num = nlogs;
Signature · 1 line
MST
#1 lore raw
Quoted 8 lines · Michael S. Tsirkin

commit 8b38694a2dc8b18374310df50174f1e4376d6824
vhost/net: virtio 1.0 byte swap
had this chunk:

(quoted diff) +1 -1
-       heads[headcount - 1].len += datalen;
+       heads[headcount - 1].len = cpu_to_vhost32(vq, len - datalen);

This adds datalen with the wrong sign, causing guest panics.

Quoted 7 lines
Fixes 8b38694a2dc8b18374310df50174f1e4376d6824

---

Alex, could you please confirm this fixes the crash for you?

Confirmed, this works. Thanks,

Alex

Quoted 16 lines
 drivers/vhost/net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vhost/net.c +1 -1
index 14419a8..d415d69 100644
@@ -538,7 +538,7 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
 		++headcount;
 		seg += in;
 	}
-	heads[headcount - 1].len = cpu_to_vhost32(vq, len - datalen);
+	heads[headcount - 1].len = cpu_to_vhost32(vq, len + datalen);
 	*iovcount = seg;
 	if (unlikely(log))
 		*log_num = nlogs;
#2 lore raw
In reply to Michael S. Tsirkin
Quoted 8 lines · Michael S. Tsirkin

commit 8b38694a2dc8b18374310df50174f1e4376d6824
vhost/net: virtio 1.0 byte swap
had this chunk:

(quoted diff) +1 -1
-       heads[headcount - 1].len += datalen;
+       heads[headcount - 1].len = cpu_to_vhost32(vq, len - datalen);

This adds datalen with the wrong sign, causing guest panics.

Quoted 7 lines
Fixes 8b38694a2dc8b18374310df50174f1e4376d6824

---

Alex, could you please confirm this fixes the crash for you?

Confirmed, this works. Thanks,

Alex

Quoted 16 lines
 drivers/vhost/net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vhost/net.c +1 -1
index 14419a8..d415d69 100644
@@ -538,7 +538,7 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
 		++headcount;
 		seg += in;
 	}
-	heads[headcount - 1].len = cpu_to_vhost32(vq, len - datalen);
+	heads[headcount - 1].len = cpu_to_vhost32(vq, len + datalen);
 	*iovcount = seg;
 	if (unlikely(log))
 		*log_num = nlogs;
#3 lore raw
In reply to Michael S. Tsirkin

Hello.

Quoted 9 lines · Michael S. Tsirkin

commit 8b38694a2dc8b18374310df50174f1e4376d6824
vhost/net: virtio 1.0 byte swap
had this chunk:

(quoted diff) +1 -1
-       heads[headcount - 1].len += datalen;
+       heads[headcount - 1].len = cpu_to_vhost32(vq, len - datalen);

This adds datalen with the wrong sign, causing guest panics.

Fixes 8b38694a2dc8b18374310df50174f1e4376d6824

The format of this tag assumes 12-digit SHA1 hash and the commit
description enclosed in parens and double quotes. See Documentation/SubmittingPatches.

Quoted 3 lines

WBR, Sergei

#5 lore raw
In reply to Michael S. Tsirkin

Hello.

Quoted 9 lines · Michael S. Tsirkin

commit 8b38694a2dc8b18374310df50174f1e4376d6824
vhost/net: virtio 1.0 byte swap
had this chunk:

(quoted diff) +1 -1
-       heads[headcount - 1].len += datalen;
+       heads[headcount - 1].len = cpu_to_vhost32(vq, len - datalen);

This adds datalen with the wrong sign, causing guest panics.

Fixes 8b38694a2dc8b18374310df50174f1e4376d6824

The format of this tag assumes 12-digit SHA1 hash and the commit
description enclosed in parens and double quotes. See Documentation/SubmittingPatches.

Quoted 3 lines

WBR, Sergei

author maintainer
#4 lore raw
In reply to Sergei Shtylyov
Quoted 18 lines · Sergei Shtylyov

Hello.

Quoted 9 lines · Michael S. Tsirkin

commit 8b38694a2dc8b18374310df50174f1e4376d6824
vhost/net: virtio 1.0 byte swap
had this chunk:

(quoted diff) +1 -1
-       heads[headcount - 1].len += datalen;
+       heads[headcount - 1].len = cpu_to_vhost32(vq, len - datalen);

This adds datalen with the wrong sign, causing guest panics.

Fixes 8b38694a2dc8b18374310df50174f1e4376d6824

The format of this tag assumes 12-digit SHA1 hash and the commit
description enclosed in parens and double quotes. See Documentation/SubmittingPatches.

Quoted 5 lines
Quoted 3 lines

WBR, Sergei

I pushed the patches to Linus unfortunately - there's some urgency since many people are hitting the bug. Will do my best to do it right next time.

Signature · 1 line
MST