diff options
author | Stefan Hajnoczi <stefanha@redhat.com> | 2016-08-04 09:52:53 -0400 |
---|---|---|
committer | Michael S. Tsirkin <mst@redhat.com> | 2016-08-09 06:42:37 -0400 |
commit | 3fda5d6e580193fa005014355b3a61498f1b3ae0 (patch) | |
tree | 351ecd0bebf5e2e863ad233fe356cf54a08d9ce3 /drivers/vhost/vsock.c | |
parent | 1b8553c04bf95180eb91be94f089a1e8b38cfd62 (diff) |
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: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'drivers/vhost/vsock.c')
-rw-r--r-- | drivers/vhost/vsock.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index 0ddf3a2dbfc4..e3b30ea9ece5 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c | |||
@@ -307,6 +307,8 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work) | |||
307 | 307 | ||
308 | vhost_disable_notify(&vsock->dev, vq); | 308 | vhost_disable_notify(&vsock->dev, vq); |
309 | for (;;) { | 309 | for (;;) { |
310 | u32 len; | ||
311 | |||
310 | if (!vhost_vsock_more_replies(vsock)) { | 312 | if (!vhost_vsock_more_replies(vsock)) { |
311 | /* Stop tx until the device processes already | 313 | /* Stop tx until the device processes already |
312 | * pending replies. Leave tx virtqueue | 314 | * pending replies. Leave tx virtqueue |
@@ -334,13 +336,15 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work) | |||
334 | continue; | 336 | continue; |
335 | } | 337 | } |
336 | 338 | ||
339 | len = pkt->len; | ||
340 | |||
337 | /* Only accept correctly addressed packets */ | 341 | /* Only accept correctly addressed packets */ |
338 | if (le64_to_cpu(pkt->hdr.src_cid) == vsock->guest_cid) | 342 | if (le64_to_cpu(pkt->hdr.src_cid) == vsock->guest_cid) |
339 | virtio_transport_recv_pkt(pkt); | 343 | virtio_transport_recv_pkt(pkt); |
340 | else | 344 | else |
341 | virtio_transport_free_pkt(pkt); | 345 | virtio_transport_free_pkt(pkt); |
342 | 346 | ||
343 | vhost_add_used(vq, head, sizeof(pkt->hdr) + pkt->len); | 347 | vhost_add_used(vq, head, sizeof(pkt->hdr) + len); |
344 | added = true; | 348 | added = true; |
345 | } | 349 | } |
346 | 350 | ||