linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@gmail.com>
To: Stefano Garzarella <sgarzare@redhat.com>
Cc: netdev@vger.kernel.org, kvm@vger.kernel.org,
	"Michael S. Tsirkin" <mst@redhat.com>,
	linux-kernel@vger.kernel.org,
	virtualization@lists.linux-foundation.org,
	Stefan Hajnoczi <stefanha@redhat.com>,
	"David S. Miller" <davem@davemloft.net>
Subject: Re: [PATCH v2 1/3] vsock/virtio: use RCU to avoid use-after-free on the_virtio_vsock
Date: Mon, 1 Jul 2019 15:54:12 +0100	[thread overview]
Message-ID: <20190701145412.GA11900@stefanha-x1.localdomain> (raw)
In-Reply-To: <20190628123659.139576-2-sgarzare@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1361 bytes --]

On Fri, Jun 28, 2019 at 02:36:57PM +0200, Stefano Garzarella wrote:
> Some callbacks used by the upper layers can run while we are in the
> .remove(). A potential use-after-free can happen, because we free
> the_virtio_vsock without knowing if the callbacks are over or not.
> 
> To solve this issue we move the assignment of the_virtio_vsock at the
> end of .probe(), when we finished all the initialization, and at the
> beginning of .remove(), before to release resources.
> For the same reason, we do the same also for the vdev->priv.
> 
> We use RCU to be sure that all callbacks that use the_virtio_vsock
> ended before freeing it. This is not required for callbacks that
> use vdev->priv, because after the vdev->config->del_vqs() we are sure
> that they are ended and will no longer be invoked.

->del_vqs() is only called at the very end, did you forget to move it
earlier?

In particular, the virtqueue handler callbacks schedule a workqueue.
The work functions use container_of() to get vsock.  We need to be sure
that the work item isn't freed along with vsock while the work item is
still pending.

How do we know that the virtqueue handler is never called in such a way
that it sees vsock != NULL (there is no explicit memory barrier on the
read side) and then schedules a work item after flush_work() has run?

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2019-07-01 14:54 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-28 12:36 [PATCH v2 0/3] vsock/virtio: several fixes in the .probe() and .remove() Stefano Garzarella
2019-06-28 12:36 ` [PATCH v2 1/3] vsock/virtio: use RCU to avoid use-after-free on the_virtio_vsock Stefano Garzarella
2019-07-01 14:54   ` Stefan Hajnoczi [this message]
2019-07-01 15:10   ` Stefan Hajnoczi
2019-07-03  9:53   ` Jason Wang
2019-07-03 10:41     ` Stefano Garzarella
2019-07-04  3:58       ` Jason Wang
2019-07-04  9:20         ` Stefano Garzarella
2019-07-05  0:18           ` Jason Wang
2019-07-04 10:17       ` Stefan Hajnoczi
2019-06-28 12:36 ` [PATCH v2 2/3] vsock/virtio: stop workers during the .remove() Stefano Garzarella
2019-07-04  4:00   ` Jason Wang
2019-06-28 12:36 ` [PATCH v2 3/3] vsock/virtio: fix flush of works " Stefano Garzarella
2019-07-01 15:08   ` Stefan Hajnoczi
2019-07-01 15:09   ` Stefan Hajnoczi
2019-07-01 15:11 ` [PATCH v2 0/3] vsock/virtio: several fixes in the .probe() and .remove() Stefan Hajnoczi
2019-07-01 17:03   ` Stefano Garzarella
2019-07-03  9:14     ` Stefan Hajnoczi
2019-07-03 10:07       ` Stefano Garzarella

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=20190701145412.GA11900@stefanha-x1.localdomain \
    --to=stefanha@gmail.com \
    --cc=davem@davemloft.net \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=sgarzare@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    /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 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).