Skip to content

Commit b28d7b5

Browse files
jasowangmdroth
authored andcommitted
virtio-net: fix unmap leak
virtio_net_handle_ctrl() and other functions that process control vq request call iov_discard_front() which will shorten the iov. This will lead unmapping in virtqueue_push() leaks mapping. Fixes this by keeping the original iov untouched and using a temp variable in those functions. Cc: Wen Congyang <[email protected]> Cc: Stefano Stabellini <[email protected]> Cc: [email protected] Signed-off-by: Jason Wang <[email protected]> Reviewed-by: Stefano Stabellini <[email protected]> Reviewed-by: Fam Zheng <[email protected]> Reviewed-by: Michael S. Tsirkin <[email protected]> Message-id: [email protected] Signed-off-by: Peter Maydell <[email protected]> (cherry picked from commit 771b6ed) Signed-off-by: Michael Roth <[email protected]>
1 parent cd2f44c commit b28d7b5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

hw/net/virtio-net.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
798798
virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
799799
VirtQueueElement elem;
800800
size_t s;
801-
struct iovec *iov;
801+
struct iovec *iov, *iov2;
802802
unsigned int iov_cnt;
803803

804804
while (virtqueue_pop(vq, &elem)) {
@@ -808,8 +808,8 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
808808
exit(1);
809809
}
810810

811-
iov = elem.out_sg;
812811
iov_cnt = elem.out_num;
812+
iov2 = iov = g_memdup(elem.out_sg, sizeof(struct iovec) * elem.out_num);
813813
s = iov_to_buf(iov, iov_cnt, 0, &ctrl, sizeof(ctrl));
814814
iov_discard_front(&iov, &iov_cnt, sizeof(ctrl));
815815
if (s != sizeof(ctrl)) {
@@ -833,6 +833,7 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
833833

834834
virtqueue_push(vq, &elem, sizeof(status));
835835
virtio_notify(vdev, vq);
836+
g_free(iov2);
836837
}
837838
}
838839

0 commit comments

Comments
 (0)