virtio-net: fix wild pointer when remove virtio-net queues
authorYunjian Wang <wangyunjian@huawei.com>
Wed, 26 Apr 2017 06:45:56 +0000 (14:45 +0800)
committerJason Wang <jasowang@redhat.com>
Tue, 23 May 2017 02:10:38 +0000 (10:10 +0800)
The tx_bh or tx_timer will free in virtio_net_del_queue() function, when
removing virtio-net queues if the guest doesn't support multiqueue. But
it might be still referenced by virtio_net_set_status(), which needs to
be set NULL. And also the tx_waiting needs to be set zero to prevent
virtio_net_set_status() accessing tx_bh or tx_timer.

Cc: qemu-stable@nongnu.org
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
hw/net/virtio-net.c

index 7d091c925962db71343c9762cd14b10fd6676491..98bd683f31b51892877a3118a5df54dd99d67118 100644 (file)
@@ -1522,9 +1522,12 @@ static void virtio_net_del_queue(VirtIONet *n, int index)
     if (q->tx_timer) {
         timer_del(q->tx_timer);
         timer_free(q->tx_timer);
+        q->tx_timer = NULL;
     } else {
         qemu_bh_delete(q->tx_bh);
+        q->tx_bh = NULL;
     }
+    q->tx_waiting = 0;
     virtio_del_queue(vdev, index * 2 + 1);
 }