linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] xen-netback: avoid race that can lead to NULL pointer dereference
@ 2019-12-12 12:37 Paul Durrant
  2019-12-12 18:10 ` Wei Liu
  2019-12-12 19:00 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Paul Durrant @ 2019-12-12 12:37 UTC (permalink / raw)
  To: netdev, xen-devel, linux-kernel
  Cc: Paul Durrant, Juergen Gross, Jakub Kicinski, Wei Liu, David S. Miller

Commit 2ac061ce97f4 ("xen/netback: cleanup init and deinit code")
introduced a problem. In function xenvif_disconnect_queue(), the value of
queue->rx_irq is zeroed *before* queue->task is stopped. Unfortunately that
task may call notify_remote_via_irq(queue->rx_irq) and calling that
function with a zero value results in a NULL pointer dereference in
evtchn_from_irq().

This patch simply re-orders things, stopping all tasks before zero-ing the
irq values, thereby avoiding the possibility of the race.

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
---
Cc: Juergen Gross <jgross@suse.com>
Cc: Jakub Kicinski <jakub.kicinski@netronome.com>
Cc: Wei Liu <wei.liu@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>
---
 drivers/net/xen-netback/interface.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c
index 68dd7bb07ca6..f15ba3de6195 100644
--- a/drivers/net/xen-netback/interface.c
+++ b/drivers/net/xen-netback/interface.c
@@ -628,18 +628,6 @@ int xenvif_connect_ctrl(struct xenvif *vif, grant_ref_t ring_ref,
 
 static void xenvif_disconnect_queue(struct xenvif_queue *queue)
 {
-	if (queue->tx_irq) {
-		unbind_from_irqhandler(queue->tx_irq, queue);
-		if (queue->tx_irq == queue->rx_irq)
-			queue->rx_irq = 0;
-		queue->tx_irq = 0;
-	}
-
-	if (queue->rx_irq) {
-		unbind_from_irqhandler(queue->rx_irq, queue);
-		queue->rx_irq = 0;
-	}
-
 	if (queue->task) {
 		kthread_stop(queue->task);
 		queue->task = NULL;
@@ -655,6 +643,18 @@ static void xenvif_disconnect_queue(struct xenvif_queue *queue)
 		queue->napi.poll = NULL;
 	}
 
+	if (queue->tx_irq) {
+		unbind_from_irqhandler(queue->tx_irq, queue);
+		if (queue->tx_irq == queue->rx_irq)
+			queue->rx_irq = 0;
+		queue->tx_irq = 0;
+	}
+
+	if (queue->rx_irq) {
+		unbind_from_irqhandler(queue->rx_irq, queue);
+		queue->rx_irq = 0;
+	}
+
 	xenvif_unmap_frontend_data_rings(queue);
 }
 
-- 
2.20.1


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

* Re: [PATCH net] xen-netback: avoid race that can lead to NULL pointer dereference
  2019-12-12 12:37 [PATCH net] xen-netback: avoid race that can lead to NULL pointer dereference Paul Durrant
@ 2019-12-12 18:10 ` Wei Liu
  2019-12-12 19:00 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Wei Liu @ 2019-12-12 18:10 UTC (permalink / raw)
  To: Paul Durrant
  Cc: netdev, xen-devel, linux-kernel, Juergen Gross, Jakub Kicinski,
	Wei Liu, David S. Miller

On Thu, Dec 12, 2019 at 12:37:23PM +0000, Paul Durrant wrote:
> Commit 2ac061ce97f4 ("xen/netback: cleanup init and deinit code")
> introduced a problem. In function xenvif_disconnect_queue(), the value of
> queue->rx_irq is zeroed *before* queue->task is stopped. Unfortunately that
> task may call notify_remote_via_irq(queue->rx_irq) and calling that
> function with a zero value results in a NULL pointer dereference in
> evtchn_from_irq().
> 
> This patch simply re-orders things, stopping all tasks before zero-ing the
> irq values, thereby avoiding the possibility of the race.
> 
> Signed-off-by: Paul Durrant <pdurrant@amazon.com>

Acked-by: Wei Liu <wei.liu@kernel.org>

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

* Re: [PATCH net] xen-netback: avoid race that can lead to NULL pointer dereference
  2019-12-12 12:37 [PATCH net] xen-netback: avoid race that can lead to NULL pointer dereference Paul Durrant
  2019-12-12 18:10 ` Wei Liu
@ 2019-12-12 19:00 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2019-12-12 19:00 UTC (permalink / raw)
  To: pdurrant; +Cc: netdev, xen-devel, linux-kernel, jgross, jakub.kicinski, wei.liu

From: Paul Durrant <pdurrant@amazon.com>
Date: Thu, 12 Dec 2019 12:37:23 +0000

> Commit 2ac061ce97f4 ("xen/netback: cleanup init and deinit code")
> introduced a problem. In function xenvif_disconnect_queue(), the value of
> queue->rx_irq is zeroed *before* queue->task is stopped. Unfortunately that
> task may call notify_remote_via_irq(queue->rx_irq) and calling that
> function with a zero value results in a NULL pointer dereference in
> evtchn_from_irq().
> 
> This patch simply re-orders things, stopping all tasks before zero-ing the
> irq values, thereby avoiding the possibility of the race.
> 
> Signed-off-by: Paul Durrant <pdurrant@amazon.com>

Please repost this with an appropriate Fixes: tag.

And then you can removed the explicit commit reference from the log message
and simply say "The commit mentioned in the Fixes tag introduced a problen ..."

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

end of thread, other threads:[~2019-12-12 19:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-12 12:37 [PATCH net] xen-netback: avoid race that can lead to NULL pointer dereference Paul Durrant
2019-12-12 18:10 ` Wei Liu
2019-12-12 19:00 ` David Miller

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).