Skip to contentSkip to conversation

vhost-net: fix range checking in mrg bufs case

PATCH In review Michael S. Tsirkin 2 participants 2 messages Sep 14, 2010 – Sep 16, 2010

Subsystems (5)
lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

PATCH 1/1 vhost-net: fix range checking in mrg bufs case

In mergeable buffer case, we use headcount, log_num and seg as indexes in same-size arrays, and we know that headcount <= seg and
log_num equals either 0 or seg.

Therefore, the right thing to do is range-check seg, not headcount as we do now: these will be different if guest chains s/g descriptors (this does not happen now, but we can not trust the guest).

Long term, we should add BUG_ON checks to verify two other indexes are what we think they should be.

---

Dave, I'll queue this on my tree, no need to bother.

 drivers/vhost/net.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/vhost/net.c +1 -1
index 6400cd5..f095de6 100644
@@ -245,7 +245,7 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
 	int r, nlogs = 0;
 
 	while (datalen > 0) {
-		if (unlikely(headcount >= VHOST_NET_MAX_SG)) {
+		if (unlikely(seg >= VHOST_NET_MAX_SG)) {
 			r = -ENOBUFS;
 			goto err;
 		}
Signature · 1 line
1.7.3.rc1.5.ge5969
Tested-by on v1 1/1
#1 lore raw
Quoted 42 lines · ----- "Michael S. Tsirkin

In mergeable buffer case, we use headcount, log_num and seg as indexes in same-size arrays, and we know that headcount <= seg and
log_num equals either 0 or seg.

Therefore, the right thing to do is range-check seg, not headcount as we do now: these will be different if guest chains s/g descriptors (this does not happen now, but we can not trust the guest).

Long term, we should add BUG_ON checks to verify two other indexes are what we think they should be.

---

Dave, I'll queue this on my tree, no need to bother.

 drivers/vhost/net.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/vhost/net.c +1 -1
index 6400cd5..f095de6 100644
@@ -245,7 +245,7 @@ static int get_rx_bufs(struct vhost_virtqueue
 *vq,
 	int r, nlogs = 0;
 
 	while (datalen > 0) {
-		if (unlikely(headcount >= VHOST_NET_MAX_SG)) {
+		if (unlikely(seg >= VHOST_NET_MAX_SG)) {
 			r = -ENOBUFS;
 			goto err;

}

Signature · 5 lines
1.7.3.rc1.5.ge5969
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/virtualization