lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 12 Mar 2015 07:36:13 +0100
From:	"Michael S. Tsirkin" <mst@...hat.com>
To:	Rusty Russell <rusty@...tcorp.com.au>
Cc:	linux-kernel@...r.kernel.org,
	virtualization@...ts.linux-foundation.org,
	Eric Van Hensbergen <ericvh@...il.com>,
	Ron Minnich <rminnich@...dia.gov>,
	Latchesar Ionkov <lucho@...kov.net>,
	"David S. Miller" <davem@...emloft.net>,
	v9fs-developer@...ts.sourceforge.net, netdev@...r.kernel.org
Subject: Re: [PATCH] 9p/trans_virtio: fix hot-unplug

On Thu, Mar 12, 2015 at 11:54:10AM +1030, Rusty Russell wrote:
> "Michael S. Tsirkin" <mst@...hat.com> writes:
> > On device hot-unplug, 9p/virtio currently will kfree channel while
> > it might still be in use.
> >
> > Of course, it might stay used forever, so it's an extremely ugly hack,
> > but it seems better than use-after-free that we have now.
> >
> > Signed-off-by: Michael S. Tsirkin <mst@...hat.com>
> 
> I'll apply it, but it looks like a bandaid.


Absolutely.

> The right answer would seem to be:
> 1) Use reference counting: 1 for client, 1 for transport.
> 2) When hot unplug, complete (ie. fail) all outstanding requests.
> 3) From then on, fail all incoming requests.
> 4) When refcount hits 0, free the structure.
> 
> Thanks,
> Rusty.

Right. Will try to do for 4.1.

> 
> 
> > ---
> >  net/9p/trans_virtio.c | 25 +++++++++++++++++++++----
> >  1 file changed, 21 insertions(+), 4 deletions(-)
> >
> > diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c
> > index d8e376a..d1b2f306 100644
> > --- a/net/9p/trans_virtio.c
> > +++ b/net/9p/trans_virtio.c
> > @@ -658,14 +658,31 @@ p9_virtio_create(struct p9_client *client, const char *devname, char *args)
> >  static void p9_virtio_remove(struct virtio_device *vdev)
> >  {
> >  	struct virtio_chan *chan = vdev->priv;
> > -
> > -	if (chan->inuse)
> > -		p9_virtio_close(chan->client);
> > -	vdev->config->del_vqs(vdev);
> > +	unsigned long warning_time;
> > +	bool inuse;
> >  
> >  	mutex_lock(&virtio_9p_lock);
> > +
> > +	/* Remove self from list so we don't get new users. */
> >  	list_del(&chan->chan_list);
> > +	warning_time = jiffies;
> > +
> > +	/* Wait for existing users to close. */
> > +	while (chan->inuse) {
> > +		mutex_unlock(&virtio_9p_lock);
> > +		msleep(250);
> > +               if (time_after(jiffies, warning_time + 10 * HZ)) {
> > +			dev_emerg(&vdev->dev, "p9_virtio_remove: "
> > +				  "waiting for device in use.\n");
> > +			warning_time = jiffies;
> > +               }
> > +		mutex_lock(&virtio_9p_lock);
> > +	}
> > +
> >  	mutex_unlock(&virtio_9p_lock);
> > +
> > +	vdev->config->del_vqs(vdev);
> > +
> >  	sysfs_remove_file(&(vdev->dev.kobj), &dev_attr_mount_tag.attr);
> >  	kobject_uevent(&(vdev->dev.kobj), KOBJ_CHANGE);
> >  	kfree(chan->tag);
> > -- 
> > MST
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ