]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
openvswitch: vport: fix race between linking and the device notifier
authorIlya Maximets <i.maximets@ovn.org>
Thu, 14 May 2026 18:46:31 +0000 (20:46 +0200)
committerJakub Kicinski <kuba@kernel.org>
Mon, 18 May 2026 23:38:45 +0000 (16:38 -0700)
commitbae3ee802c21e83ad1eb805519e6f32ea528b4d2
tree91d2455df72f95f6ea6c5b47146ddcbf877bba4e
parentd00c953a8f69921f484b629801766da68f27f658
openvswitch: vport: fix race between linking and the device notifier

Sashiko reports that it is technically possible that we got the device
reference, but by the time we're linking it to the OVS datapath, it
may be already in the process of being deleted.  In this case if the
notifier wins the race for RTNL, it will see that the device is not
yet in the OVS datapath (ovs_netdev_get_vport() will fail in the
dp_device_event()) and will do nothing.  Then the ovs_netdev_link()
will take the RTNL and link the unregistering device to OVS datapath.

Eventually, netdev_wait_allrefs_any() will re-broadcast the event and
the device will be properly detached, but it will take at least a
second before that happens, so it's not something we should rely on.

Let's avoid linking the non-registered device in the first place.

Note: As per documentation, RTNL doesn't protect the reg_state, but
it actually does for all the state transitions we care about here,
so it should not be necessary to use READ_ONCE or taking the instance
lock.  We can still do that, but we have a few more places even in
this file where the reg_state is accessed without those while under
RTNL, and many more places like this across the kernel code, so it
might make more sense to change all of them in a more centralized
fashion in the future, if necessary.

Fixes: ccb1352e76cf ("net: Add Open vSwitch kernel components.")
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Reviewed-by: Aaron Conole <aconole@redhat.com>
Acked-by: Eelco Chaudron <echaudro@redhat.com>
Link: https://patch.msgid.link/20260514184702.2461435-1-i.maximets@ovn.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/openvswitch/vport-netdev.c