Skip to content

Commit

Permalink
vhost-net: fix range checking in mrg bufs case
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
  • Loading branch information
mstsirkin committed Sep 14, 2010
1 parent 053d8f6 commit ee05d69
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/vhost/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit ee05d69

Please sign in to comment.