Commit 9d092603 authored by Jan Beulich's avatar Jan Beulich Committed by Konrad Rzeszutek Wilk

xen-blkback: do not leak mode property

"be->mode" is obtained from xenbus_read(), which does a kmalloc() for
the message body. The short string is never released, so do it along
with freeing "be" itself, and make sure the string isn't kept when
backend_changed() doesn't complete successfully (which made it
desirable to slightly re-structure that function, so that the error
cleanup can be done in one place).
Reported-by: default avatarOlaf Hering <olaf@aepfle.de>
CC: stable@vger.kernel.org
Signed-off-by: default avatarJan Beulich <jbeulich@suse.com>
Signed-off-by: default avatarKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
parent 836dc9e3
...@@ -367,6 +367,7 @@ static int xen_blkbk_remove(struct xenbus_device *dev) ...@@ -367,6 +367,7 @@ static int xen_blkbk_remove(struct xenbus_device *dev)
be->blkif = NULL; be->blkif = NULL;
} }
kfree(be->mode);
kfree(be); kfree(be);
dev_set_drvdata(&dev->dev, NULL); dev_set_drvdata(&dev->dev, NULL);
return 0; return 0;
...@@ -502,6 +503,7 @@ static void backend_changed(struct xenbus_watch *watch, ...@@ -502,6 +503,7 @@ static void backend_changed(struct xenbus_watch *watch,
= container_of(watch, struct backend_info, backend_watch); = container_of(watch, struct backend_info, backend_watch);
struct xenbus_device *dev = be->dev; struct xenbus_device *dev = be->dev;
int cdrom = 0; int cdrom = 0;
unsigned long handle;
char *device_type; char *device_type;
DPRINTK(""); DPRINTK("");
...@@ -521,10 +523,10 @@ static void backend_changed(struct xenbus_watch *watch, ...@@ -521,10 +523,10 @@ static void backend_changed(struct xenbus_watch *watch,
return; return;
} }
if ((be->major || be->minor) && if (be->major | be->minor) {
((be->major != major) || (be->minor != minor))) { if (be->major != major || be->minor != minor)
pr_warn(DRV_PFX "changing physical device (from %x:%x to %x:%x) not supported.\n", pr_warn(DRV_PFX "changing physical device (from %x:%x to %x:%x) not supported.\n",
be->major, be->minor, major, minor); be->major, be->minor, major, minor);
return; return;
} }
...@@ -542,36 +544,33 @@ static void backend_changed(struct xenbus_watch *watch, ...@@ -542,36 +544,33 @@ static void backend_changed(struct xenbus_watch *watch,
kfree(device_type); kfree(device_type);
} }
if (be->major == 0 && be->minor == 0) { /* Front end dir is a number, which is used as the handle. */
/* Front end dir is a number, which is used as the handle. */ err = strict_strtoul(strrchr(dev->otherend, '/') + 1, 0, &handle);
if (err)
char *p = strrchr(dev->otherend, '/') + 1; return;
long handle;
err = strict_strtoul(p, 0, &handle);
if (err)
return;
be->major = major; be->major = major;
be->minor = minor; be->minor = minor;
err = xen_vbd_create(be->blkif, handle, major, minor, err = xen_vbd_create(be->blkif, handle, major, minor,
(NULL == strchr(be->mode, 'w')), cdrom); !strchr(be->mode, 'w'), cdrom);
if (err) {
be->major = 0;
be->minor = 0;
xenbus_dev_fatal(dev, err, "creating vbd structure");
return;
}
if (err)
xenbus_dev_fatal(dev, err, "creating vbd structure");
else {
err = xenvbd_sysfs_addif(dev); err = xenvbd_sysfs_addif(dev);
if (err) { if (err) {
xen_vbd_free(&be->blkif->vbd); xen_vbd_free(&be->blkif->vbd);
be->major = 0;
be->minor = 0;
xenbus_dev_fatal(dev, err, "creating sysfs entries"); xenbus_dev_fatal(dev, err, "creating sysfs entries");
return;
} }
}
if (err) {
kfree(be->mode);
be->mode = NULL;
be->major = 0;
be->minor = 0;
} else {
/* We're potentially connected now */ /* We're potentially connected now */
xen_update_blkif_status(be->blkif); xen_update_blkif_status(be->blkif);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment