1
0
Fork 0
mirror of https://passt.top/passt synced 2025-05-20 00:15:34 +02:00

tcp_vu: Fix off-by one in header count array adjustment

head_cnt represents the number of frames we're going to forward to the
guest in tcp_vu_sock_recv(), each of which could require multiple
buffers ("elements").  We initialise it with as many frames as we can
find space for in vu buffers, and we then need to adjust it down to
the number of frames we actually (partially) filled.

We adjust it down based on number of individual buffers used by the
data from recvmsg().  At this point 'i' is *one greater than* that
number of buffers, so we need to discard all (unused) frames with a
buffer index >= i, instead of > i.

Reported-by: David Gibson <david@gibson.dropbear.id.au>
[david: Contributed actual commit message]
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
Laurent Vivier 2025-02-11 20:43:32 +01:00 committed by Stefano Brivio
parent 90f91fe726
commit def7de4690

View file

@ -261,7 +261,7 @@ static ssize_t tcp_vu_sock_recv(const struct ctx *c,
len -= iov->iov_len;
}
/* adjust head count */
while (head_cnt > 0 && head[head_cnt - 1] > i)
while (head_cnt > 0 && head[head_cnt - 1] >= i)
head_cnt--;
/* mark end of array */
head[head_cnt] = i;