Skip to content

Commit

Permalink
xen-netback: avoid race that can lead to NULL pointer dereference
Browse files Browse the repository at this point in the history
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.

Fixes: 2ac061c ("xen/netback: cleanup init and deinit code")
Signed-off-by: Paul Durrant <[email protected]>
Acked-by: Wei Liu <[email protected]>
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
Paul Durrant authored and Jakub Kicinski committed Dec 15, 2019
1 parent 858ce8c commit fd42bfd
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions drivers/net/xen-netback/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down

0 comments on commit fd42bfd

Please sign in to comment.