stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch-for-4.4] xen/blkback: don't free be structure too early
@ 2017-08-02  9:27 Juergen Gross
  2017-08-02  9:27 ` [Patch-for-4.4] xen/blkback: don't use xen_blkif_get() in xen-blkback kthread Juergen Gross
  0 siblings, 1 reply; 3+ messages in thread
From: Juergen Gross @ 2017-08-02  9:27 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 commit 71df1d7ccad1c36f7321d6b3b48f2ea42681c363
for linux-4.4.y branch.
---
 drivers/block/xen-blkback/xenbus.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

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;
 }
 
-- 
2.12.3

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

* [Patch-for-4.4] xen/blkback: don't use xen_blkif_get() in xen-blkback kthread
  2017-08-02  9:27 [Patch-for-4.4] xen/blkback: don't free be structure too early Juergen Gross
@ 2017-08-02  9:27 ` Juergen Gross
  2017-08-04 19:57   ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Juergen Gross @ 2017-08-02  9:27 UTC (permalink / raw)
  To: stable; +Cc: Juergen Gross, Konrad Rzeszutek Wilk

There is no need to use xen_blkif_get()/xen_blkif_put() in the kthread
of xen-blkback. Thread stopping is synchronous and using the blkif
reference counting in the kthread will avoid to ever let the reference
count drop to zero at the end of an I/O running concurrent to
disconnecting.

Setting ring->xenblkd to NULL after stopping the kthread isn't needed
as the kthread does this already.

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 commit a24fa22ce22ae302b3bf8f7008896d52d5d57b8d
for linux-4.4.y branch.
---
 drivers/block/xen-blkback/blkback.c | 3 ---
 drivers/block/xen-blkback/xenbus.c  | 1 -
 2 files changed, 4 deletions(-)

diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c
index 41fb1a917b17..33e23a7a691f 100644
--- a/drivers/block/xen-blkback/blkback.c
+++ b/drivers/block/xen-blkback/blkback.c
@@ -595,8 +595,6 @@ int xen_blkif_schedule(void *arg)
 	unsigned long timeout;
 	int ret;
 
-	xen_blkif_get(blkif);
-
 	while (!kthread_should_stop()) {
 		if (try_to_freeze())
 			continue;
@@ -650,7 +648,6 @@ purge_gnt_list:
 		print_stats(blkif);
 
 	blkif->xenblkd = NULL;
-	xen_blkif_put(blkif);
 
 	return 0;
 }
diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c
index 58f151e283ff..923308201375 100644
--- a/drivers/block/xen-blkback/xenbus.c
+++ b/drivers/block/xen-blkback/xenbus.c
@@ -221,7 +221,6 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)
 	if (blkif->xenblkd) {
 		kthread_stop(blkif->xenblkd);
 		wake_up(&blkif->shutdown_wq);
-		blkif->xenblkd = NULL;
 	}
 
 	/* The above kthread_stop() guarantees that at this point we
-- 
2.12.3

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

* Re: [Patch-for-4.4] xen/blkback: don't use xen_blkif_get() in xen-blkback kthread
  2017-08-02  9:27 ` [Patch-for-4.4] xen/blkback: don't use xen_blkif_get() in xen-blkback kthread Juergen Gross
@ 2017-08-04 19:57   ` Greg KH
  0 siblings, 0 replies; 3+ messages in thread
From: Greg KH @ 2017-08-04 19:57 UTC (permalink / raw)
  To: Juergen Gross; +Cc: stable, Konrad Rzeszutek Wilk

On Wed, Aug 02, 2017 at 11:27:45AM +0200, Juergen Gross wrote:
> There is no need to use xen_blkif_get()/xen_blkif_put() in the kthread
> of xen-blkback. Thread stopping is synchronous and using the blkif
> reference counting in the kthread will avoid to ever let the reference
> count drop to zero at the end of an I/O running concurrent to
> disconnecting.
> 
> Setting ring->xenblkd to NULL after stopping the kthread isn't needed
> as the kthread does this already.
> 
> 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 commit a24fa22ce22ae302b3bf8f7008896d52d5d57b8d
> for linux-4.4.y branch.

Both patches now applied, thanks.

greg k-h

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

end of thread, other threads:[~2017-08-04 19:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-02  9:27 [Patch-for-4.4] xen/blkback: don't free be structure too early Juergen Gross
2017-08-02  9:27 ` [Patch-for-4.4] xen/blkback: don't use xen_blkif_get() in xen-blkback kthread Juergen Gross
2017-08-04 19:57   ` 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).