]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[virtio] Ensure that device is closed before unmapping regions
authorMichael Brown <mcb30@ipxe.org>
Thu, 23 Apr 2026 22:03:26 +0000 (23:03 +0100)
committerMichael Brown <mcb30@ipxe.org>
Thu, 23 Apr 2026 22:10:24 +0000 (23:10 +0100)
Commit 988243c ("[virtio] Add virtio-net 1.0 support") erroneously
placed the code to unmap the device regions before the code to
unregister the network device.  In the common case that the network
device is still open at the time that we shut down to boot the OS,
this results in the regions being accessed after having been unmapped.

For 32-bit BIOS or for UEFI with no IOMMU enabled, the iounmap()
operation is a no-op and so the driver still happens to work despite
the ordering bug.  For 64-bit BIOS or for UEFI with an IOMMU enabled,
the iounmap() operation is not a no-op, and the driver will trigger a
page fault.

Fix by moving the call to unregister_netdev() to before the code that
unmaps the device regions.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/drivers/net/virtio-net.c

index e4700279887085888db305aaa1e3da8ec45a5682..32dad9ac064fd858b14aa2d29d127280dc32ebcc 100644 (file)
@@ -684,11 +684,12 @@ static void virtnet_remove ( struct pci_device *pci ) {
        struct net_device *netdev = pci_get_drvdata ( pci );
        struct virtnet_nic *virtnet = netdev->priv;
 
+       unregister_netdev ( netdev );
+
        virtio_pci_unmap_capability ( &virtnet->vdev.device );
        virtio_pci_unmap_capability ( &virtnet->vdev.isr );
        virtio_pci_unmap_capability ( &virtnet->vdev.common );
 
-       unregister_netdev ( netdev );
        netdev_nullify ( netdev );
        netdev_put ( netdev );
 }