Skip to contentSkip to conversation

xen/blkfront: avoid NULL blkfront_info dereference on device removal

PATCH Superseded Vasilis Liaskovitis 2 participants 5 messages Oct 11, 2018 – Oct 15, 2018

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/blkfront: avoid NULL blkfront_info dereference on device removal

If a block device is hot-added when we are out of grants, gnttab_grant_foreign_access fails with -ENOSPC (log message "28 granting access to ring page") in this code path:

talk_to_blkback ->

	setup_blkring ->
		xenbus_grant_ring ->
			gnttab_grant_foreign_access

and the failing path in talk_to_blkback sets the driver_data to NULL:

destroy_blkring:

        blkif_free(info, 0);

        mutex_lock(&blkfront_mutex);
        free_info(info);
        mutex_unlock(&blkfront_mutex);

        dev_set_drvdata(&dev->dev, NULL);

This results in a NULL pointer BUG when blkfront_remove and blkif_free try to access the failing device's NULL struct blkfront_info.

---
 drivers/block/xen-blkfront.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/block/xen-blkfront.c +4 -0
index 429d20131c7e..92cc6cb6b078 100644
@@ -2493,6 +2493,9 @@ static int blkfront_remove(struct xenbus_device *xbdev)
 
 	dev_dbg(&xbdev->dev, "%s removed", xbdev->nodename);
 
+	if (!info)
+		goto out;
+
 	blkif_free(info, 0);
 
 	mutex_lock(&info->mutex);
@@ -2535,6 +2538,7 @@ static int blkfront_remove(struct xenbus_device *xbdev)
 	mutex_unlock(&bdev->bd_mutex);
 	bdput(bdev);
 
+out:
 	return 0;
 }
 
Signature · 7 lines
2.19.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 33 lines · Vasilis Liaskovitis

If a block device is hot-added when we are out of grants, gnttab_grant_foreign_access fails with -ENOSPC (log message "28 granting access to ring page") in this code path:

talk_to_blkback ->

	setup_blkring ->
		xenbus_grant_ring ->
			gnttab_grant_foreign_access

and the failing path in talk_to_blkback sets the driver_data to NULL:

destroy_blkring:

        blkif_free(info, 0);

        mutex_lock(&blkfront_mutex);
        free_info(info);
        mutex_unlock(&blkfront_mutex);

        dev_set_drvdata(&dev->dev, NULL);

This results in a NULL pointer BUG when blkfront_remove and blkif_free try to access the failing device's NULL struct blkfront_info.

---
 drivers/block/xen-blkfront.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/block/xen-blkfront.c +0 -0
index 429d20131c7e..92cc6cb6b078 100644

drivers/block/xen-blkfront.c static int blkfront_remove(struct xenbus_device *xbdev) · line 2497

Quoted 5 lines
drivers/block/xen-blkfront.c +2 -0
@@ -2493,6 +2493,9 @@ static int blkfront_remove(struct xenbus_device *xbdev)
 
 	dev_dbg(&xbdev->dev, "%s removed", xbdev->nodename);
 
+	if (!info)
+		goto out;

I don't see the point in adding the 'out' label. Can you just return 0 here?

Thanks, Roger.

#2 lore raw
Quoted 5 lines · Roger Pau Monné

--- a/drivers/block/xen-blkfront.c

Quoted 4 lines

+++ b/drivers/block/xen-blkfront.c

(quoted diff) +0 -0
@@ -2493,6 +2493,9 @@ static int blkfront_remove(struct
 xenbus_device *xbdev)
 
Quoted 8 lines

drivers/block/xen-blkfront.c static int blkfront_remove(struct xenbus_device *xbdev) · line 2497

Quoted 4 lines
drivers/block/xen-blkfront.c +2 -0
 	dev_dbg(&xbdev->dev, "%s removed", xbdev->nodename);
 
+	if (!info)
+		goto out;

I don't see the point in adding the 'out' label. Can you just return 0
here?

of course, I will send a second version.

thanks for the review,

- Vasilis

Quoted 7 lines

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
In reply to Roger Pau Monné
Quoted 5 lines · Roger Pau Monné

--- a/drivers/block/xen-blkfront.c

Quoted 4 lines

+++ b/drivers/block/xen-blkfront.c

(quoted diff) +0 -0
@@ -2493,6 +2493,9 @@ static int blkfront_remove(struct
 xenbus_device *xbdev)
 
Quoted 8 lines

drivers/block/xen-blkfront.c static int blkfront_remove(struct xenbus_device *xbdev) · line 2497

Quoted 4 lines
drivers/block/xen-blkfront.c +2 -0
 	dev_dbg(&xbdev->dev, "%s removed", xbdev->nodename);
 
+	if (!info)
+		goto out;

I don't see the point in adding the 'out' label. Can you just return 0
here?

of course, I will send a second version.

thanks for the review,

- Vasilis

Quoted 7 lines

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw
In reply to Vasilis Liaskovitis
Quoted 33 lines · Vasilis Liaskovitis

If a block device is hot-added when we are out of grants, gnttab_grant_foreign_access fails with -ENOSPC (log message "28 granting access to ring page") in this code path:

talk_to_blkback ->

	setup_blkring ->
		xenbus_grant_ring ->
			gnttab_grant_foreign_access

and the failing path in talk_to_blkback sets the driver_data to NULL:

destroy_blkring:

        blkif_free(info, 0);

        mutex_lock(&blkfront_mutex);
        free_info(info);
        mutex_unlock(&blkfront_mutex);

        dev_set_drvdata(&dev->dev, NULL);

This results in a NULL pointer BUG when blkfront_remove and blkif_free try to access the failing device's NULL struct blkfront_info.

---
 drivers/block/xen-blkfront.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/block/xen-blkfront.c +0 -0
index 429d20131c7e..92cc6cb6b078 100644

drivers/block/xen-blkfront.c static int blkfront_remove(struct xenbus_device *xbdev) · line 2497

Quoted 5 lines
drivers/block/xen-blkfront.c +2 -0
@@ -2493,6 +2493,9 @@ static int blkfront_remove(struct xenbus_device *xbdev)
 
 	dev_dbg(&xbdev->dev, "%s removed", xbdev->nodename);
 
+	if (!info)
+		goto out;

I don't see the point in adding the 'out' label. Can you just return 0 here?

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel