stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xen/blkback: don't free be structure too early
@ 2017-07-03  8:59 Juergen Gross
  2017-07-03  9:04 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Juergen Gross @ 2017-07-03  8:59 UTC (permalink / raw)
  To: stable; +Cc: Juergen Gross, Konrad Rzeszutek Wilk

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>
---
This is a backport of upstream commit 71df1d7ccad1c3.
---
 drivers/block/xen-blkback/xenbus.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c
index dcabf52425ff..31046c2c39f1 100644
--- a/drivers/block/xen-blkback/xenbus.c
+++ b/drivers/block/xen-blkback/xenbus.c
@@ -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;
 }
 
-- 
2.12.3

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] xen/blkback: don't free be structure too early
  2017-07-03  8:59 [PATCH] xen/blkback: don't free be structure too early Juergen Gross
@ 2017-07-03  9:04 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2017-07-03  9:04 UTC (permalink / raw)
  To: Juergen Gross; +Cc: stable, Konrad Rzeszutek Wilk

On Mon, Jul 03, 2017 at 10:59:17AM +0200, Juergen Gross wrote:
> 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>
> ---
> 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-07-03  9:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-03  8:59 [PATCH] xen/blkback: don't free be structure too early Juergen Gross
2017-07-03  9:04 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).