* [PATCH] VSOCK: fix vhost virtio_vsock_pkt use-after-free
@ 2016-08-04 13:52 Stefan Hajnoczi
2016-08-04 16:34 ` Michael S. Tsirkin
0 siblings, 1 reply; 3+ messages in thread
From: Stefan Hajnoczi @ 2016-08-04 13:52 UTC (permalink / raw)
To: kvm; +Cc: netdev, Michael S. Tsirkin, Dan Carpenter, Stefan Hajnoczi
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>
---
drivers/vhost/vsock.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
index 0ddf3a2..e3b30ea 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)
vhost_disable_notify(&vsock->dev, vq);
for (;;) {
+ u32 len;
+
if (!vhost_vsock_more_replies(vsock)) {
/* Stop tx until the device processes already
* pending replies. Leave tx virtqueue
@@ -334,13 +336,15 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)
continue;
}
+ len = pkt->len;
+
/* Only accept correctly addressed packets */
if (le64_to_cpu(pkt->hdr.src_cid) == vsock->guest_cid)
virtio_transport_recv_pkt(pkt);
else
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;
}
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] VSOCK: fix vhost virtio_vsock_pkt use-after-free
2016-08-04 13:52 [PATCH] VSOCK: fix vhost virtio_vsock_pkt use-after-free Stefan Hajnoczi
@ 2016-08-04 16:34 ` Michael S. Tsirkin
2016-08-05 8:44 ` Stefan Hajnoczi
0 siblings, 1 reply; 3+ messages in thread
From: Michael S. Tsirkin @ 2016-08-04 16:34 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: kvm, netdev, Dan Carpenter
On Thu, Aug 04, 2016 at 02:52:53PM +0100, Stefan Hajnoczi wrote:
> 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>
Thanks!
I'd prefer a lower-case prefix, mentioning vhost, such as vhost/vsock.
I'll tweak it for now.
> ---
> drivers/vhost/vsock.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
> index 0ddf3a2..e3b30ea 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)
>
> vhost_disable_notify(&vsock->dev, vq);
> for (;;) {
> + u32 len;
> +
> if (!vhost_vsock_more_replies(vsock)) {
> /* Stop tx until the device processes already
> * pending replies. Leave tx virtqueue
> @@ -334,13 +336,15 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)
> continue;
> }
>
> + len = pkt->len;
> +
> /* Only accept correctly addressed packets */
> if (le64_to_cpu(pkt->hdr.src_cid) == vsock->guest_cid)
> virtio_transport_recv_pkt(pkt);
> else
> 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;
> }
>
> --
> 2.7.4
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] VSOCK: fix vhost virtio_vsock_pkt use-after-free
2016-08-04 16:34 ` Michael S. Tsirkin
@ 2016-08-05 8:44 ` Stefan Hajnoczi
0 siblings, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2016-08-05 8:44 UTC (permalink / raw)
To: Michael S. Tsirkin; +Cc: kvm, netdev, Dan Carpenter
[-- Attachment #1: Type: text/plain, Size: 704 bytes --]
On Thu, Aug 04, 2016 at 07:34:43PM +0300, Michael S. Tsirkin wrote:
> On Thu, Aug 04, 2016 at 02:52:53PM +0100, Stefan Hajnoczi wrote:
> > 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>
>
>
> Thanks!
> I'd prefer a lower-case prefix, mentioning vhost, such as vhost/vsock.
> I'll tweak it for now.
Thanks, I will use vhost/vsock in the future.
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-08-05 8:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-04 13:52 [PATCH] VSOCK: fix vhost virtio_vsock_pkt use-after-free Stefan Hajnoczi
2016-08-04 16:34 ` Michael S. Tsirkin
2016-08-05 8:44 ` Stefan Hajnoczi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).