All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: kvm@vger.kernel.org, netdev@vger.kernel.org,
	Dan Carpenter <dan.carpenter@oracle.com>
Subject: Re: [PATCH] VSOCK: fix vhost virtio_vsock_pkt use-after-free
Date: Thu, 4 Aug 2016 19:34:43 +0300	[thread overview]
Message-ID: <20160804193338-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <1470318773-10414-1-git-send-email-stefanha@redhat.com>

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

  reply	other threads:[~2016-08-04 16:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2016-08-05  8:44   ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160804193338-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=dan.carpenter@oracle.com \
    --cc=kvm@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.