Skip to contentSkip to conversation

xen/blkfront: avoid NULL blkfront_info dereference on device removal

PATCH Superseded Vasilis Liaskovitis 3 participants 7 messages Oct 15, 2018 – Oct 18, 2018

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

PATCH v2 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 | 3 +++
 1 file changed, 3 insertions(+)
drivers/block/xen-blkfront.c +3 -0
index 429d20131c7e..8871bf4c8a2e 100644
@@ -2493,6 +2493,9 @@ static int blkfront_remove(struct xenbus_device *xbdev)
 
 	dev_dbg(&xbdev->dev, "%s removed", xbdev->nodename);
 
+	if (!info)
+		return 0;
+
 	blkif_free(info, 0);
 
 	mutex_lock(&info->mutex);
Signature · 1 line
2.19.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 20 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);
Quoted 4 lines

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

Thanks.

I guess this is a candidate for backporting?

#2 lore raw
Quoted 8 lines · Roger Pau Monné
Quoted 6 lines

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

I guess this is a candidate for backporting?

yes, I think so. At least for kernels >=4.5, which could face this issue due to commit c31ecf6c12 (this frees the struct blkinfo in the failing path of talk_to_blkback).

thanks,

- Vasilis

#3 lore raw
Quoted 7 lines · Vasilis Liaskovitis
Quoted 6 lines · Roger Pau Monn�
Quoted 6 lines

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

Quoted 6 lines
Quoted 2 lines

I guess this is a candidate for backporting?

yes, I think so. At least for kernels >=4.5, which could face this issue due to commit c31ecf6c12 (this frees the struct blkinfo in the failing path of talk_to_blkback).

OK, applied with Cc: [email protected]

Quoted 6 lines

thanks,

- Vasilis

#4 lore raw
In reply to Vasilis Liaskovitis
Quoted 7 lines · Vasilis Liaskovitis
Quoted 6 lines · Roger Pau Monné
Quoted 6 lines

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

Quoted 6 lines
Quoted 2 lines

I guess this is a candidate for backporting?

yes, I think so. At least for kernels >=4.5, which could face this issue due to commit c31ecf6c12 (this frees the struct blkinfo in the failing path of talk_to_blkback).

OK, applied with Cc: [email protected]

Quoted 6 lines

thanks,

- Vasilis

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

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

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

I guess this is a candidate for backporting?

yes, I think so. At least for kernels >=4.5, which could face this issue due to commit c31ecf6c12 (this frees the struct blkinfo in the failing path of talk_to_blkback).

thanks,

- Vasilis

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

Reviewed-by on v2 1/1
#6 lore raw
In reply to Vasilis Liaskovitis
Quoted 20 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);
Quoted 4 lines

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

Thanks.

I guess this is a candidate for backporting?

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