From: "Jan Beulich" Subject: [PATCH] blkfront: don't access freed struct xenbus_device Date: Mon, 01 Mar 2010 10:00:20 +0000 Message-ID: <4B8B9E440200007800031CEF@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part1C36D124.1__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Jeremy Fitzhardinge Cc: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part1C36D124.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Unfortunately commit eebc80638fe365a0386ed5ee57c7f0c6d5e56fb1 still wasn't quite right - there was a reference to freed memory left from blkfront_closing(). Signed-off-by: Jan Beulich --- drivers/block/xen-blkfront.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -981,13 +981,11 @@ static void blkfront_connect(struct blkf * the backend. Once is this done, we can switch to Closed in * acknowledgement. */ -static void blkfront_closing(struct xenbus_device *dev) +static void blkfront_closing(struct blkfront_info *info) { - struct blkfront_info *info =3D dev_get_drvdata(&dev->dev); unsigned int minor, nr_minors; unsigned long flags; =20 - dev_dbg(&dev->dev, "blkfront_closing: %s removed\n", dev->nodename)= ; =20 if (info->rq =3D=3D NULL) goto out; @@ -1013,7 +1011,8 @@ static void blkfront_closing(struct xenb xlbd_release_minors(minor, nr_minors); =20 out: - xenbus_frontend_closed(dev); + if (info->xbdev) + xenbus_frontend_closed(info->xbdev); } =20 /** @@ -1053,7 +1052,7 @@ static void backend_changed(struct xenbu xenbus_dev_error(dev, -EBUSY, "Device in use; refusing to = close"); else - blkfront_closing(dev); + blkfront_closing(info); mutex_unlock(&bd->bd_mutex); bdput(bd); break; @@ -1071,7 +1070,7 @@ static int blkfront_remove(struct xenbus if(info->users =3D=3D 0) kfree(info); else - info->is_ready =3D -1; + info->xbdev =3D NULL; =20 return 0; } @@ -1080,14 +1079,14 @@ static int blkfront_is_ready(struct xenb { struct blkfront_info *info =3D dev_get_drvdata(&dev->dev); =20 - return info->is_ready > 0; + return info->is_ready && info->xbdev; } =20 static int blkif_open(struct block_device *bdev, fmode_t mode) { struct blkfront_info *info =3D bdev->bd_disk->private_data; =20 - if(info->is_ready < 0) + if (!info->xbdev) return -ENODEV; info->users++; return 0; @@ -1102,13 +1101,13 @@ static int blkif_release(struct gendisk=20 have ignored this request initially, as the device was still mounted. */ struct xenbus_device *dev =3D info->xbdev; - enum xenbus_state state =3D xenbus_read_driver_state(dev->o= therend); =20 - if(info->is_ready < 0) { - blkfront_closing(dev); + if (!dev) { + blkfront_closing(info); kfree(info); - } else if (state =3D=3D XenbusStateClosing && info->is_read= y) - blkfront_closing(dev); + } else if (xenbus_read_driver_state(dev->otherend) + =3D=3D XenbusStateClosing && info->is_ready) + blkfront_closing(info); } return 0; } --=__Part1C36D124.1__= Content-Type: text/plain; name="linux-2.6.33-xen-blkfront-forced-detach-2.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="linux-2.6.33-xen-blkfront-forced-detach-2.patch" Subject: blkfront: don't access freed struct xenbus_device=0A=0AUnfortunate= ly commit eebc80638fe365a0386ed5ee57c7f0c6d5e56fb1 still=0Awasn't quite = right - there was a reference to freed memory left from=0Ablkfront_closing(= ).=0A=0ASigned-off-by: Jan Beulich =0A=0A---=0A = drivers/block/xen-blkfront.c | 25 ++++++++++++-------------=0A 1 file = changed, 12 insertions(+), 13 deletions(-)=0A=0A--- a/drivers/block/xen-blk= front.c=0A+++ b/drivers/block/xen-blkfront.c=0A@@ -981,13 +981,11 @@ = static void blkfront_connect(struct blkf=0A * the backend. Once is this = done, we can switch to Closed in=0A * acknowledgement.=0A */=0A-static = void blkfront_closing(struct xenbus_device *dev)=0A+static void blkfront_cl= osing(struct blkfront_info *info)=0A {=0A- struct blkfront_info *info = =3D dev_get_drvdata(&dev->dev);=0A unsigned int minor, nr_minors;=0A = unsigned long flags;=0A =0A- dev_dbg(&dev->dev, "blkfront_closing: %s = removed\n", dev->nodename);=0A =0A if (info->rq =3D=3D NULL)=0A = goto out;=0A@@ -1013,7 +1011,8 @@ static void blkfront_closing(struct = xenb=0A xlbd_release_minors(minor, nr_minors);=0A =0A out:=0A- = xenbus_frontend_closed(dev);=0A+ if (info->xbdev)=0A+ = xenbus_frontend_closed(info->xbdev);=0A }=0A =0A /**=0A@@ -1053,7 +1052,7 = @@ static void backend_changed(struct xenbu=0A xenbus_dev_= error(dev, -EBUSY,=0A "Device in use; = refusing to close");=0A else=0A- = blkfront_closing(dev);=0A+ blkfront_closing(info);=0A = mutex_unlock(&bd->bd_mutex);=0A bdput(bd);= =0A break;=0A@@ -1071,7 +1070,7 @@ static int blkfront_remove(s= truct xenbus=0A if(info->users =3D=3D 0)=0A kfree(info)= ;=0A else=0A- info->is_ready =3D -1;=0A+ = info->xbdev =3D NULL;=0A =0A return 0;=0A }=0A@@ -1080,14 +1079,14 @@ = static int blkfront_is_ready(struct xenb=0A {=0A struct blkfront_inf= o *info =3D dev_get_drvdata(&dev->dev);=0A =0A- return info->is_ready > = 0;=0A+ return info->is_ready && info->xbdev;=0A }=0A =0A static int = blkif_open(struct block_device *bdev, fmode_t mode)=0A {=0A struct = blkfront_info *info =3D bdev->bd_disk->private_data;=0A =0A- if(info->is= _ready < 0)=0A+ if (!info->xbdev)=0A return -ENODEV;=0A = info->users++;=0A return 0;=0A@@ -1102,13 +1101,13 @@ static int = blkif_release(struct gendisk =0A have ignored this = request initially, as the device was=0A still mounted. = */=0A struct xenbus_device *dev =3D info->xbdev;=0A- = enum xenbus_state state =3D xenbus_read_driver_state(dev->otherend);=0A = =0A- if(info->is_ready < 0) {=0A- blkfront_cl= osing(dev);=0A+ if (!dev) {=0A+ blkfront_closing(in= fo);=0A kfree(info);=0A- } else if = (state =3D=3D XenbusStateClosing && info->is_ready)=0A- = blkfront_closing(dev);=0A+ } else if (xenbus_read_driver_state= (dev->otherend)=0A+ =3D=3D XenbusStateClosing && = info->is_ready)=0A+ blkfront_closing(info);=0A = }=0A return 0;=0A }=0A --=__Part1C36D124.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__Part1C36D124.1__=--