Skip to content

Commit 557602e

Browse files
committed
virtio-net: fix race between ndo_open() and virtio_device_ready()
Bugzilla: http://bugzilla.redhat.com/2153210 commit 50c0ada Author: Jason Wang <jasowang@redhat.com> Date: Fri Jun 17 15:29:49 2022 +0800 virtio-net: fix race between ndo_open() and virtio_device_ready() We currently call virtio_device_ready() 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 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: 4baf1e3 ("virtio_net: enable VQs early") Signed-off-by: Jason Wang <jasowang@redhat.com> Message-Id: <20220617072949.30734-1-jasowang@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Conflict in the context because of missing commit: c7114b1 ("drivers/net/virtio_net: Added basic RSS support.") Signed-off-by: Laurent Vivier <lvivier@redhat.com>
1 parent 032ef07 commit 557602e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/net/virtio_net.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3269,14 +3269,20 @@ static int virtnet_probe(struct virtio_device *vdev)
32693269
}
32703270
}
32713271

3272-
err = register_netdev(dev);
3272+
/* serialize netdev register + virtio_device_ready() with ndo_open() */
3273+
rtnl_lock();
3274+
3275+
err = register_netdevice(dev);
32733276
if (err) {
32743277
pr_debug("virtio_net: registering device failed\n");
3278+
rtnl_unlock();
32753279
goto free_failover;
32763280
}
32773281

32783282
virtio_device_ready(vdev);
32793283

3284+
rtnl_unlock();
3285+
32803286
err = virtnet_cpu_notif_add(vi);
32813287
if (err) {
32823288
pr_debug("virtio_net: registering cpu notifier failed\n");

0 commit comments

Comments
 (0)