Skip to contentSkip to conversation

xen/blkback: don't free be structure too early

PATCH Applied Juergen Gross 2 participants 2 messages Jul 3, 2017

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

PATCH 1/1 xen/blkback: don't free be structure too early

The be structure must not be freed when freeing the blkif structure isn't done. Otherwise a use-after-free of be when unmapping the ring used for communicating with the frontend will occur in case of a late call of xenblk_disconnect() (e.g. due to an I/O still active when trying to disconnect).

---
This is a backport of upstream commit 71df1d7ccad1c3.

---
 drivers/block/xen-blkback/xenbus.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/block/xen-blkback/xenbus.c +3 -3
index dcabf52425ff..31046c2c39f1 100644
@@ -316,8 +316,10 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)
 static void xen_blkif_free(struct xen_blkif *blkif)
 {
 
-	xen_blkif_disconnect(blkif);
+	WARN_ON(xen_blkif_disconnect(blkif));
 	xen_vbd_free(&blkif->vbd);
+	kfree(blkif->be->mode);
+	kfree(blkif->be);
 
 	/* Make sure everything is drained before shutting down */
 	kmem_cache_free(xen_blkif_cachep, blkif);
@@ -512,8 +514,6 @@ static int xen_blkbk_remove(struct xenbus_device *dev)
 
 	/* Put the reference we set in xen_blkif_alloc(). */
 	xen_blkif_put(be->blkif);
-	kfree(be->mode);
-	kfree(be);
 	return 0;
 }
 
Signature · 1 line
2.12.3
maintainer Applied
#1 lore raw
Quoted 6 lines · Juergen Gross

The be structure must not be freed when freeing the blkif structure isn't done. Otherwise a use-after-free of be when unmapping the ring used for communicating with the frontend will occur in case of a late call of xenblk_disconnect() (e.g. due to an I/O still active when trying to disconnect).

Quoted 6 lines

---
This is a backport of upstream commit 71df1d7ccad1c3.

Thanks, applied to 4.9 and 4.11-stable queues. If you want it to go to 4.4, can you please provide a backport for that?

thanks,

greg k-h