Skip to content

Commit 53f5772

Browse files
jgross1gregkh
authored andcommitted
xen/blkback: don't free be structure too early
commit 71df1d7ccad1c36f7321d6b3b48f2ea42681c363 upstream. 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). Signed-off-by: Juergen Gross <jgross@suse.com> Tested-by: Steven Haigh <netwiz@crc.id.au> Acked-by: Roger Pau Monné <roger.pau@citrix.com> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6220870 commit 53f5772

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

drivers/block/xen-blkback/xenbus.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,10 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)
266266

267267
static void xen_blkif_free(struct xen_blkif *blkif)
268268
{
269-
270-
xen_blkif_disconnect(blkif);
269+
WARN_ON(xen_blkif_disconnect(blkif));
271270
xen_vbd_free(&blkif->vbd);
271+
kfree(blkif->be->mode);
272+
kfree(blkif->be);
272273

273274
/* Make sure everything is drained before shutting down */
274275
BUG_ON(blkif->persistent_gnt_c != 0);
@@ -445,8 +446,6 @@ static int xen_blkbk_remove(struct xenbus_device *dev)
445446
xen_blkif_put(be->blkif);
446447
}
447448

448-
kfree(be->mode);
449-
kfree(be);
450449
return 0;
451450
}
452451

0 commit comments

Comments
 (0)