From: Michael S. Tsirkin Date: Tue, 14 Sep 2010 13:15:52 +0000 (+0200) Subject: vhost-net: fix range checking in mrg bufs case X-Git-Tag: upstream/snapshot3+hdmi~12792^2~41^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ee05d6939ed17b55e9c2466af32c208e0d547eb8;p=platform%2Fadaptation%2Frenesas_rcar%2Frenesas_kernel.git 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. Reported-by: Jason Wang Signed-off-by: Michael S. Tsirkin --- diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index 29e850a..7c80082 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -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; }