From: "Jan Beulich" Subject: [PATCH] linux/blkfront: don't access freed struct xenbus_device Date: Thu, 04 Feb 2010 09:22:07 +0000 Message-ID: <4B6A9FCF020000780002DABC@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part775D5BAF.0__=" 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: 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. --=__Part775D5BAF.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Unfortunately c/s 983 still wasn't quite right - there was a reference to freed memory left from blkfront_closing(). As usual, written against 2.6.32.7 and made apply to the 2.6.18 tree without further testing. Signed-off-by: Jan Beulich --- a/drivers/xen/blkfront/blkfront.c 2010-02-04 09:29:42.000000000 = +0100 +++ b/drivers/xen/blkfront/blkfront.c 2010-02-04 09:31:52.000000000 = +0100 @@ -63,7 +63,7 @@ #define GRANT_INVALID_REF 0 =20 static void connect(struct blkfront_info *); -static void blkfront_closing(struct xenbus_device *); +static void blkfront_closing(struct blkfront_info *); static int blkfront_remove(struct xenbus_device *); static int talk_to_backend(struct xenbus_device *, struct blkfront_info = *); static int setup_blkring(struct xenbus_device *, struct blkfront_info *); @@ -302,7 +302,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); #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17) up(&bd->bd_sem); #else @@ -387,12 +387,11 @@ static void connect(struct blkfront_info * 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->dev.driver_data; unsigned long flags; =20 - DPRINTK("blkfront_closing: %s removed\n", dev->nodename); + DPRINTK("blkfront_closing: %d removed\n", info->vdevice); =20 if (info->rq =3D=3D NULL) goto out; @@ -414,7 +413,8 @@ static void blkfront_closing(struct xenb xlvbd_del(info); =20 out: - xenbus_frontend_closed(dev); + if (info->xbdev) + xenbus_frontend_closed(info->xbdev); } =20 =20 @@ -429,7 +429,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; } @@ -498,7 +498,7 @@ int blkif_open(struct block_device *bd,=20 { struct blkfront_info *info =3D inode->i_bdev->bd_disk->private_data= ; =20 - if(info->is_ready < 0) + if (!info->xbdev) return -ENODEV; info->users++; return 0; @@ -521,13 +521,13 @@ int blkif_release(struct gendisk *disk,=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; } @@ -920,7 +920,7 @@ int blkfront_is_ready(struct xenbus_devi { struct blkfront_info *info =3D dev->dev.driver_data; =20 - return info->is_ready > 0; + return info->is_ready && info->xbdev; } =20 =20 --=__Part775D5BAF.0__= Content-Type: text/plain; name="xenlinux-blkfront-forced-detach-2.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xenlinux-blkfront-forced-detach-2.patch" Subject: blkfront: don't access freed struct xenbus_device=0A=0AUnfortunate= ly c/s 983 still wasn't quite right - there was a reference=0Ato freed = memory left from blkfront_closing().=0A=0AAs usual, written against = 2.6.32.7 and made apply to the 2.6.18=0Atree without further testing.=0A=0A= Signed-off-by: Jan Beulich =0A=0A--- a/drivers/xen/blk= front/blkfront.c 2010-02-04 09:29:42.000000000 +0100=0A+++ = b/drivers/xen/blkfront/blkfront.c 2010-02-04 09:31:52.000000000 = +0100=0A@@ -63,7 +63,7 @@=0A #define GRANT_INVALID_REF 0=0A =0A static = void connect(struct blkfront_info *);=0A-static void blkfront_closing(struc= t xenbus_device *);=0A+static void blkfront_closing(struct blkfront_info = *);=0A static int blkfront_remove(struct xenbus_device *);=0A static int = talk_to_backend(struct xenbus_device *, struct blkfront_info *);=0A static = int setup_blkring(struct xenbus_device *, struct blkfront_info *);=0A@@ = -302,7 +302,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(in= fo);=0A #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17)=0A = up(&bd->bd_sem);=0A #else=0A@@ -387,12 +387,11 @@ static void connect(struc= t blkfront_info=0A * the backend. Once is this done, we can switch to = Closed in=0A * acknowledgement.=0A */=0A-static void blkfront_closing(str= uct xenbus_device *dev)=0A+static void blkfront_closing(struct blkfront_inf= o *info)=0A {=0A- struct blkfront_info *info =3D dev->dev.driver_data= ;=0A unsigned long flags;=0A =0A- DPRINTK("blkfront_closing: %s = removed\n", dev->nodename);=0A+ DPRINTK("blkfront_closing: %d removed\n", = info->vdevice);=0A =0A if (info->rq =3D=3D NULL)=0A goto = out;=0A@@ -414,7 +413,8 @@ static void blkfront_closing(struct xenb=0A = xlvbd_del(info);=0A =0A out:=0A- xenbus_frontend_closed(dev);=0A+ = if (info->xbdev)=0A+ xenbus_frontend_closed(info->xbdev);=0A = }=0A =0A =0A@@ -429,7 +429,7 @@ static int blkfront_remove(struct = 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@@ -498,7 +498,7 @@ int blkif_open= (struct block_device *bd, =0A {=0A struct blkfront_info *info =3D = inode->i_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@@ -521,13 +521,13 @@ int blkif_release(struct gendisk *disk, = =0A have ignored this request initially, as the device = was=0A still mounted. */=0A struct xenbus_devic= e * 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_closing(dev);=0A+ = if (!dev) {=0A+ blkfront_closing(info);=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@@ -920,7 +920,7 = @@ int blkfront_is_ready(struct xenbus_devi=0A {=0A struct blkfront_inf= o *info =3D dev->dev.driver_data;=0A =0A- return info->is_ready > = 0;=0A+ return info->is_ready && info->xbdev;=0A }=0A =0A =0A --=__Part775D5BAF.0__= 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 --=__Part775D5BAF.0__=--