]> git.karo-electronics.de Git - mv-sheeva.git/commitdiff
vhost-net: fix range checking in mrg bufs case
authorMichael S. Tsirkin <mst@redhat.com>
Tue, 14 Sep 2010 13:15:52 +0000 (15:15 +0200)
committerMichael S. Tsirkin <mst@redhat.com>
Tue, 14 Sep 2010 13:22:41 +0000 (15:22 +0200)
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.

Reported-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
drivers/vhost/net.c

index 29e850a7a2f9871b7c9658e0717f8926dc5bc4ac..7c8008225ee3a47ebef2cecaf005c0631fa93da1 100644 (file)
@@ -243,7 +243,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;
                }