From: Juergen Gross Date: Thu, 18 May 2017 15:28:48 +0000 (+0200) Subject: xen/blkback: don't free be structure too early X-Git-Tag: Ubuntu-snapdragon-4.4.0-1076.81~808 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=f6736b0cebd52f6d2d736b4110ebb0014decbb8c;p=mirror_ubuntu-artful-kernel.git xen/blkback: don't free be structure too early BugLink: http://bugs.launchpad.net/bugs/1710646 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 Tested-by: Steven Haigh Acked-by: Roger Pau Monné Signed-off-by: Konrad Rzeszutek Wilk Signed-off-by: Greg Kroah-Hartman Signed-off-by: Stefan Bader Signed-off-by: Thadeu Lima de Souza Cascardo --- diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index f53cff42f8da..58f151e283ff 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c @@ -266,9 +266,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 */ BUG_ON(blkif->persistent_gnt_c != 0); @@ -445,8 +446,6 @@ static int xen_blkbk_remove(struct xenbus_device *dev) xen_blkif_put(be->blkif); } - kfree(be->mode); - kfree(be); return 0; }