Commit 3fda5d6e authored by Stefan Hajnoczi's avatar Stefan Hajnoczi Committed by Michael S. Tsirkin

vhost/vsock: fix vhost virtio_vsock_pkt use-after-free

Stash the packet length in a local variable before handing over
ownership of the packet to virtio_transport_recv_pkt() or
virtio_transport_free_pkt().

This patch solves the use-after-free since pkt is no longer guaranteed
to be alive.
Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent 1b8553c0
...@@ -307,6 +307,8 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work) ...@@ -307,6 +307,8 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)
vhost_disable_notify(&vsock->dev, vq); vhost_disable_notify(&vsock->dev, vq);
for (;;) { for (;;) {
u32 len;
if (!vhost_vsock_more_replies(vsock)) { if (!vhost_vsock_more_replies(vsock)) {
/* Stop tx until the device processes already /* Stop tx until the device processes already
* pending replies. Leave tx virtqueue * pending replies. Leave tx virtqueue
...@@ -334,13 +336,15 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work) ...@@ -334,13 +336,15 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)
continue; continue;
} }
len = pkt->len;
/* Only accept correctly addressed packets */ /* Only accept correctly addressed packets */
if (le64_to_cpu(pkt->hdr.src_cid) == vsock->guest_cid) if (le64_to_cpu(pkt->hdr.src_cid) == vsock->guest_cid)
virtio_transport_recv_pkt(pkt); virtio_transport_recv_pkt(pkt);
else else
virtio_transport_free_pkt(pkt); virtio_transport_free_pkt(pkt);
vhost_add_used(vq, head, sizeof(pkt->hdr) + pkt->len); vhost_add_used(vq, head, sizeof(pkt->hdr) + len);
added = true; added = true;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment