Skip to contentSkip to conversation

xen-blkfront: plug device number leak in xlblk_init() error path

PATCH In review Laszlo Ersek 3 participants 3 messages Oct 7, 2011 – Oct 10, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen-blkfront: plug device number leak in xlblk_init() error path

... though after a failed xenbus_register_frontend() all may be lost.

---
 drivers/block/xen-blkfront.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
drivers/block/xen-blkfront.c +9 -1
index 9ea8c25..a5a9b1b 100644
@@ -1385,6 +1385,8 @@ static struct xenbus_driver blkfront = {
 
 static int __init xlblk_init(void)
 {
+	int ret;
+
 	if (!xen_domain())
 		return -ENODEV;
 
@@ -1394,7 +1396,13 @@ static int __init xlblk_init(void)
 		return -ENODEV;
 	}
 
-	return xenbus_register_frontend(&blkfront);
+	ret = xenbus_register_frontend(&blkfront);
+	if (ret) {
+		unregister_blkdev(XENVBD_MAJOR, DEV_NAME);
+		return ret;
+	}
+
+	return 0;
 }
 module_init(xlblk_init);
 
Signature · 1 line
1.7.4.4
Acked-by on v1 1/1
#1 lore raw

Cc'ing Konrad & Jeremy per get_maintainers.pl

Quoted 1 line · Laszlo Ersek

... though after a failed xenbus_register_frontend() all may be lost.

Indeed. But anyway:

{net,kbd,fb,pci}front seem to not have this issue. Although it's not 100% clear if the effect of pci_frontend_registrar(1) needs to be undone.

(is registrar a typo for register here?)

Quoted 33 lines
---
 drivers/block/xen-blkfront.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
drivers/block/xen-blkfront.c +9 -1
index 9ea8c25..a5a9b1b 100644
@@ -1385,6 +1385,8 @@ static struct xenbus_driver blkfront = {
 
 static int __init xlblk_init(void)
 {
+	int ret;
+
 	if (!xen_domain())
 		return -ENODEV;
 
@@ -1394,7 +1396,13 @@ static int __init xlblk_init(void)
 		return -ENODEV;
 	}
 
-	return xenbus_register_frontend(&blkfront);
+	ret = xenbus_register_frontend(&blkfront);
+	if (ret) {
+		unregister_blkdev(XENVBD_MAJOR, DEV_NAME);
+		return ret;
+	}
+
+	return 0;
 }
 module_init(xlblk_init);
 
#2 lore raw
Quoted 8 lines · Ian Campbell

Cc'ing Konrad & Jeremy per get_maintainers.pl

Quoted 1 line · Laszlo Ersek

... though after a failed xenbus_register_frontend() all may be lost.

Indeed. But anyway:

Queue up for 3.2.

Quoted 6 lines

{net,kbd,fb,pci}front seem to not have this issue. Although it's not 100% clear if the effect of pci_frontend_registrar(1) needs to be undone.

(is registrar a typo for register here?)

Yes.