Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xen-netback: avoid race that can lead to NULL pointer dereference

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: 2ac061ce97f4 ("xen/netback: cleanup init and deinit code")
Signed-off-by: Paul Durrant <pdurrant@amazon.com>
Acked-by: Wei Liu <wei.liu@kernel.org>
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>

authored by

Paul Durrant and committed by
Jakub Kicinski
fd42bfd1 858ce8ca

+12 -12
+12 -12
drivers/net/xen-netback/interface.c
··· 628 628 629 629 static void xenvif_disconnect_queue(struct xenvif_queue *queue) 630 630 { 631 - if (queue->tx_irq) { 632 - unbind_from_irqhandler(queue->tx_irq, queue); 633 - if (queue->tx_irq == queue->rx_irq) 634 - queue->rx_irq = 0; 635 - queue->tx_irq = 0; 636 - } 637 - 638 - if (queue->rx_irq) { 639 - unbind_from_irqhandler(queue->rx_irq, queue); 640 - queue->rx_irq = 0; 641 - } 642 - 643 631 if (queue->task) { 644 632 kthread_stop(queue->task); 645 633 queue->task = NULL; ··· 641 653 if (queue->napi.poll) { 642 654 netif_napi_del(&queue->napi); 643 655 queue->napi.poll = NULL; 656 + } 657 + 658 + if (queue->tx_irq) { 659 + unbind_from_irqhandler(queue->tx_irq, queue); 660 + if (queue->tx_irq == queue->rx_irq) 661 + queue->rx_irq = 0; 662 + queue->tx_irq = 0; 663 + } 664 + 665 + if (queue->rx_irq) { 666 + unbind_from_irqhandler(queue->rx_irq, queue); 667 + queue->rx_irq = 0; 644 668 } 645 669 646 670 xenvif_unmap_frontend_data_rings(queue);