xen-netback: avoid race that can lead to NULL pointer dereference
Subsystems (3)
PATCH 1/1 xen-netback: avoid race that can lead to NULL pointer dereference
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.
---
Cc: Juergen Gross <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "David S. Miller" <[email protected]>
--- drivers/net/xen-netback/interface.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/net/xen-netback/interface.c +12 -12
@@ -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); }
Signature · 1 line
2.20.1
Quoted 11 lines · Paul Durrant
Commit
2ac061ce97f4("xen/netback: cleanup init and deinit code") introduced a problem. In functionxenvif_disconnect_queue(), the value ofqueue->rx_irqis zeroed *before*queue->taskis stopped. Unfortunately that task may callnotify_remote_via_irq(queue->rx_irq)and calling that function with a zero value results in a NULL pointer dereference inevtchn_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 <[email protected]>
David Miller
maintainerFrom: Paul Durrant <[email protected]>
Date: Thu, 12 Dec 2019 12:37:23 +0000
Quoted 11 lines
Commit
2ac061ce97f4("xen/netback: cleanup init and deinit code") introduced a problem. In functionxenvif_disconnect_queue(), the value ofqueue->rx_irqis zeroed *before*queue->taskis stopped. Unfortunately that task may callnotify_remote_via_irq(queue->rx_irq)and calling that function with a zero value results in a NULL pointer dereference inevtchn_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 <[email protected]>
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 ..."