Skip to content

Commit 7cf7ed8

Browse files
jasowanggregkh
authored andcommitted
caif_virtio: fix race between virtio_device_ready() and ndo_open()
commit 11a37eb upstream. We currently depend on probe() calling virtio_device_ready() - which happens after netdev registration. Since ndo_open() can be called immediately after register_netdev, this means there exists a race between ndo_open() and virtio_device_ready(): the driver may start to use the device (e.g. TX) before DRIVER_OK which violates the spec. Fix this by switching to use register_netdevice() and protect the virtio_device_ready() with rtnl_lock() to make sure ndo_open() can only be called after virtio_device_ready(). Fixes: 0d2e1a2 ("caif_virtio: Introduce caif over virtio") Signed-off-by: Jason Wang <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 4d50558 commit 7cf7ed8

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

drivers/net/caif/caif_virtio.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,13 +721,21 @@ static int cfv_probe(struct virtio_device *vdev)
721721
/* Carrier is off until netdevice is opened */
722722
netif_carrier_off(netdev);
723723

724+
/* serialize netdev register + virtio_device_ready() with ndo_open() */
725+
rtnl_lock();
726+
724727
/* register Netdev */
725-
err = register_netdev(netdev);
728+
err = register_netdevice(netdev);
726729
if (err) {
730+
rtnl_unlock();
727731
dev_err(&vdev->dev, "Unable to register netdev (%d)\n", err);
728732
goto err;
729733
}
730734

735+
virtio_device_ready(vdev);
736+
737+
rtnl_unlock();
738+
731739
debugfs_init(cfv);
732740

733741
return 0;

0 commit comments

Comments
 (0)