aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Beulich2012-12-20 04:31:11 -0600
committerGreg Kroah-Hartman2013-03-03 16:09:04 -0600
commit975398374dac831d5d5c2825615c489aee24ea3a (patch)
tree1a4e120177b9d1ebc0847452ecb65f3ddcf0e781
parentad315127433dc9a8147e7f6b43f21b3d0061003a (diff)
downloadkernel-common-975398374dac831d5d5c2825615c489aee24ea3a.tar.gz
kernel-common-975398374dac831d5d5c2825615c489aee24ea3a.tar.xz
kernel-common-975398374dac831d5d5c2825615c489aee24ea3a.zip
xen-blkback: do not leak mode property
commit 9d092603cc306ee6edfe917bf9ab8beb5f32d7bc upstream. "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: Olaf Hering <olaf@aepfle.de> Signed-off-by: Jan Beulich <jbeulich@suse.com> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/block/xen-blkback/xenbus.c49
1 files changed, 24 insertions, 25 deletions
diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c
index 6cc0db1bf52..97ded2552d9 100644
--- a/drivers/block/xen-blkback/xenbus.c
+++ b/drivers/block/xen-blkback/xenbus.c
@@ -400,6 +400,7 @@ static int xen_blkbk_remove(struct xenbus_device *dev)
400 be->blkif = NULL; 400 be->blkif = NULL;
401 } 401 }
402 402
403 kfree(be->mode);
403 kfree(be); 404 kfree(be);
404 dev_set_drvdata(&dev->dev, NULL); 405 dev_set_drvdata(&dev->dev, NULL);
405 return 0; 406 return 0;
@@ -482,6 +483,7 @@ static void backend_changed(struct xenbus_watch *watch,
482 = container_of(watch, struct backend_info, backend_watch); 483 = container_of(watch, struct backend_info, backend_watch);
483 struct xenbus_device *dev = be->dev; 484 struct xenbus_device *dev = be->dev;
484 int cdrom = 0; 485 int cdrom = 0;
486 unsigned long handle;
485 char *device_type; 487 char *device_type;
486 488
487 DPRINTK(""); 489 DPRINTK("");
@@ -501,10 +503,10 @@ static void backend_changed(struct xenbus_watch *watch,
501 return; 503 return;
502 } 504 }
503 505
504 if ((be->major || be->minor) && 506 if (be->major | be->minor) {
505 ((be->major != major) || (be->minor != minor))) { 507 if (be->major != major || be->minor != minor)
506 pr_warn(DRV_PFX "changing physical device (from %x:%x to %x:%x) not supported.\n", 508 pr_warn(DRV_PFX "changing physical device (from %x:%x to %x:%x) not supported.\n",
507 be->major, be->minor, major, minor); 509 be->major, be->minor, major, minor);
508 return; 510 return;
509 } 511 }
510 512
@@ -522,36 +524,33 @@ static void backend_changed(struct xenbus_watch *watch,
522 kfree(device_type); 524 kfree(device_type);
523 } 525 }
524 526
525 if (be->major == 0 && be->minor == 0) { 527 /* Front end dir is a number, which is used as the handle. */
526 /* Front end dir is a number, which is used as the handle. */ 528 err = strict_strtoul(strrchr(dev->otherend, '/') + 1, 0, &handle);
527 529 if (err)
528 char *p = strrchr(dev->otherend, '/') + 1; 530 return;
529 long handle;
530 err = strict_strtoul(p, 0, &handle);
531 if (err)
532 return;
533 531
534 be->major = major; 532 be->major = major;
535 be->minor = minor; 533 be->minor = minor;
536 534
537 err = xen_vbd_create(be->blkif, handle, major, minor, 535 err = xen_vbd_create(be->blkif, handle, major, minor,
538 (NULL == strchr(be->mode, 'w')), cdrom); 536 !strchr(be->mode, 'w'), cdrom);
539 if (err) {
540 be->major = 0;
541 be->minor = 0;
542 xenbus_dev_fatal(dev, err, "creating vbd structure");
543 return;
544 }
545 537
538 if (err)
539 xenbus_dev_fatal(dev, err, "creating vbd structure");
540 else {
546 err = xenvbd_sysfs_addif(dev); 541 err = xenvbd_sysfs_addif(dev);
547 if (err) { 542 if (err) {
548 xen_vbd_free(&be->blkif->vbd); 543 xen_vbd_free(&be->blkif->vbd);
549 be->major = 0;
550 be->minor = 0;
551 xenbus_dev_fatal(dev, err, "creating sysfs entries"); 544 xenbus_dev_fatal(dev, err, "creating sysfs entries");
552 return;
553 } 545 }
546 }
554 547
548 if (err) {
549 kfree(be->mode);
550 be->mode = NULL;
551 be->major = 0;
552 be->minor = 0;
553 } else {
555 /* We're potentially connected now */ 554 /* We're potentially connected now */
556 xen_update_blkif_status(be->blkif); 555 xen_update_blkif_status(be->blkif);
557 } 556 }