pull request: fixes for ovpn 2026-04-22
Subsystems (3)
Antonio Quartulli
maintainercover pull request: fixes for ovpn 2026-04-22
Hello netdev team,
This PR is a new version of the one sent on March 20th.
We are trying to address a remote, yet possible, race condition between tearing down an ovpn interface and adding new peers via netlink.
After further discussion including Jakub and Sabrina, the following patch came up.
It should address all raised concerns.
Sorry for taking so long to get back to this.
Please pull or let mw know of any issue!
Thanks a lot,
Antonio
The following changes since commit 478ed6b7d2577439c610f91fa8759a4c878a4264:
net/sched: sch_dualpi2: drain both C-queue and L-queue in dualpi2_change() (2026-04-21 15:00:39 +0200)
are available in the Git repository at:
https://github.com/OpenVPN/ovpn-net-next.git tags/ovpn-net-20260422
for you to fetch changes up to eac0dfc41d179d5f78d6d7ee401c63f48ba04b5a:
ovpn: fix race between deleting interface and adding new peer (2026-04-22 14:30:17 +0200)
----------------------------------------------------------------
Included change:
* fix race condition between interface teardown and new peer being added via netlink
----------------------------------------------------------------
Antonio Quartulli (1):
ovpn: fix race between deleting interface and adding new peer
drivers/net/ovpn/main.c | 12 ++---------- drivers/net/ovpn/peer.c | 8 ++++++++ 2 files changed, 10 insertions(+), 10 deletions(-)
Antonio Quartulli
maintainerPATCH 1/1 ovpn: fix race between deleting interface and adding new peer
While deleting an existing ovpn interface, there is a very narrow window where adding a new peer via netlink may cause the netdevice to hang and prevent its unregistration.
It may happen during ovpn_dellink(), when all existing peers are freed and the device is queued for deregistration, but a CMD_PEER_NEW message comes in adding a new peer that takes again a reference to the netdev.
At this point there is no way to release the device because we are under the assumption that all peers were already released.
Fix the race condition by releasing all peers in ndo_uninit(), when the netdevice has already been removed from the netdev list. Also ovpn_peer_add() has now an extra check that forces the function to bail out if the device reg_state is UNREGISTERING (or later state).
This way any incoming CMD_PEER_NEW racing with the interface deletion routine will simply stop before adding the peer.
At this point ovpn_dellink() becomes empty and can just be removed.
--- drivers/net/ovpn/main.c | 12 ++---------- drivers/net/ovpn/peer.c | 8 ++++++++ 2 files changed, 10 insertions(+), 10 deletions(-)
drivers/net/ovpn/main.c +2 -10
@@ -92,6 +92,8 @@ static void ovpn_net_uninit(struct net_device *dev) {struct ovpn_priv *ovpn =netdev_priv (dev); +cancel_delayed_work_sync (&ovpn->keepalive_work); +ovpn_peers_free (ovpn,NULL ,OVPN_DEL_PEER_REASON_TEARDOWN );gro_cells_destroy (&ovpn->gro_cells); }
@@ -208,15 +210,6 @@ static int ovpn_newlink(struct net_device *dev,return register_netdevice (dev); } -static void ovpn_dellink (struct net_device *dev,struct list_head *head) -{ -struct ovpn_priv *ovpn =netdev_priv (dev); - -cancel_delayed_work_sync (&ovpn->keepalive_work); -ovpn_peers_free (ovpn,NULL ,OVPN_DEL_PEER_REASON_TEARDOWN ); -unregister_netdevice_queue (dev, head); -} -static int ovpn_fill_info (struct sk_buff *skb,const struct net_device *dev) {struct ovpn_priv *ovpn =netdev_priv (dev);
@@ -235,7 +228,6 @@ static struct rtnl_link_ops ovpn_link_ops = { .policy = ovpn_policy, .maxtype = IFLA_OVPN_MAX, .newlink = ovpn_newlink, - .dellink = ovpn_dellink, .fill_info = ovpn_fill_info, };
drivers/net/ovpn/peer.c +8 -0
@@ -1034,6 +1034,14 @@ static int ovpn_peer_add_p2p(struct ovpn_priv *ovpn, struct ovpn_peer *peer)*/ int ovpn_peer_add (struct ovpn_priv *ovpn,struct ovpn_peer *peer) { +/* Prevent adding new peers while destroying the ovpn interface. +* Failing to do so would end up holding the device reference +* endlessly hostage of the new peer object with no chance of +* release.. +*/ +if (ovpn->dev->reg_state >=NETREG_UNREGISTERING ) +return -ENODEV ; +switch (ovpn->mode) {case OVPN_MODE_MP :return ovpn_peer_add_mp (ovpn, peer);
Signature · 1 line
2.53.0
Jakub Kicinski
maintainerRe: [PATCH net 1/1] ovpn: fix race between deleting interface and adding new peer
drivers/net/ovpn/peer.c static int ovpn_peer_add_p2p(struct ovpn_priv *ovpn, struct ovpn_peer *peer) · line 1043
Quoted 7 lines · On Wed, 22 Apr 2026 14:32:42 +0200 Antonio Quartulli wrote:
drivers/net/ovpn/peer.c +7
-0+/* Prevent adding new peers while destroying the ovpn interface. +* Failing to do so would end up holding the device reference +* endlessly hostage of the new peer object with no chance of +* release.. +*/ +if (ovpn->dev->reg_state >=NETREG_UNREGISTERING ) +return -ENODEV ;
AI review suggests wrapping reg_state read in READ_ONCE(), I think that's legit. Also nit: I think > or != REGISTERED would be more idiomatic than comparing >= UNREGSITERING ?
If you agree make sure Sashiko doesn't complain about anything else once it's public:
https://sashiko.dev/#/patchset/[email protected]
Antonio Quartulli
maintainerRe: [PATCH net 1/1] ovpn: fix race between deleting interface and adding new peer
Quoted 12 lines · Jakub Kicinski
drivers/net/ovpn/peer.c static int ovpn_peer_add_p2p(struct ovpn_priv *ovpn, struct ovpn_peer *peer) · line 1043
Quoted 7 lines · On Wed, 22 Apr 2026 14:32:42 +0200 Antonio Quartulli wrote:
drivers/net/ovpn/peer.c +7
-0+/* Prevent adding new peers while destroying the ovpn interface. +* Failing to do so would end up holding the device reference +* endlessly hostage of the new peer object with no chance of +* release.. +*/ +if (ovpn->dev->reg_state >=NETREG_UNREGISTERING ) +return -ENODEV ;AI review suggests wrapping
reg_stateread inREAD_ONCE(), I think that's legit. Also nit: I think > or != REGISTERED would be more idiomatic than comparing >= UNREGSITERING ?
Agreed on READ_ONCE. Will fix it.
As for your second point, I am fine with "!= REGISTERED" as that's the only state we should be accepting new peers in any case.
Quoted 4 lines
If you agree make sure Sashiko doesn't complain about anything else once it's public:
https://sashiko.dev/#/patchset/[email protected]
Is there any way to get earlier access to these reviews? (at least for patches somehow related to me/ovpn)
Thanks!
Regards,
Signature · 2 lines
Antonio Quartulli OpenVPN Inc.
Antonio Quartulli
maintainerRe: [PATCH net 1/1] ovpn: fix race between deleting interface and adding new peer
Quoted 16 lines · Antonio Quartulli
Quoted 9 lines · Jakub Kicinski
Quoted 7 lines · On Wed, 22 Apr 2026 14:32:42 +0200 Antonio Quartulli wrote:
+ /* Prevent adding new peers while destroying the ovpn interface. + * Failing to do so would end up holding the device reference + * endlessly hostage of the new peer object with no chance of + * release..
+ */
+ if (ovpn->dev->reg_state>=NETREG_UNREGISTERING)
+ return-ENODEV;Quoted 3 lines
AI review suggests wrapping
reg_stateread inREAD_ONCE(), I think that's legit. Also nit: I think > or != REGISTERED would be more idiomatic than comparing >= UNREGSITERING ?Agreed on
READ_ONCE. Will fix it.
Quoted 9 lines
As for your second point, I am fine with "!= REGISTERED" as that's the only state we should be accepting new peers in any case.
Quoted 4 lines
If you agree make sure Sashiko doesn't complain about anything else once it's public:
https://sashiko.dev/#/patchset/20260422123242.530882-2- [email protected]Is there any way to get earlier access to these reviews? (at least for patches somehow related to me/ovpn)
Dang! sashiko reminded me that I should swap cancel_delayed_work_sync with disable_delayed_work_sync. Will fix that.
As for the second remarks..It has convincing arguments, but I need some more time to think about it.
Sabrina, do you have an opinion?
Cheers,
Quoted 4 lines
Thanks!
Regards,
Signature · 2 lines
Antonio Quartulli OpenVPN Inc.
Sabrina Dubroca
reviewerRe: [PATCH net 1/1] ovpn: fix race between deleting interface and adding new peer
Quoted 32 lines · Antonio Quartulli
Quoted 20 lines · Antonio Quartulli
Quoted 9 lines · Jakub Kicinski
Quoted 7 lines · On Wed, 22 Apr 2026 14:32:42 +0200 Antonio Quartulli wrote:
+ /* Prevent adding new peers while destroying the ovpn interface. + * Failing to do so would end up holding the device reference + * endlessly hostage of the new peer object with no chance of + * release..
+ */
+ if (ovpn->dev->reg_state>=NETREG_UNREGISTERING)
+ return-ENODEV;Quoted 3 lines
AI review suggests wrapping
reg_stateread inREAD_ONCE(), I think that's legit. Also nit: I think > or != REGISTERED would be more idiomatic than comparing >= UNREGSITERING ?Agreed on
READ_ONCE. Will fix it.As for your second point, I am fine with "!= REGISTERED" as that's the only state we should be accepting new peers in any case.
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
If you agree make sure Sashiko doesn't complain about anything else once it's public:
https://sashiko.dev/#/patchset/20260422123242.530882-2-
[email protected]Is there any way to get earlier access to these reviews? (at least for patches somehow related to me/ovpn)
Quoted 8 lines
Dang! sashiko reminded me that I should swap
cancel_delayed_work_syncwithdisable_delayed_work_sync. Will fix that.As for the second remarks..It has convincing arguments, but I need some more time to think about it.
Sabrina, do you have an opinion?
Sadly, it seems possible.
I wanted to add rcu_read_lock around everything ovpn_peer_add() does, so that unregister_netdevice_many_notify() gets stuck on the synchronize_net() call after setting UNREGISTERING, but ovpn_peer_add_p2p needs to be able to sleep [1]. If we move the ovpn->lock from ovpn_peer_add_* to ovpn_peer_add, so that we check reg_state and insert the new peer without being preempted, we should be ok. But maybe submit that to netdev as RFC (not directly a pull request) so that sashiko tells me how wrong I am?
We could also wrap all of ovpn_peer_add (including the new reg_state check) in netdev_lock, since we can't move to NETREG_UNREGISTERING until netdev_lock is released (then I think we wouldn't need the READ_ONCE(reg_state)). But I don't know if that's an acceptable use of netdev_lock.
[1] maybe we should add a might_sleep() annotation directly in unlock_ovpn (instead of/in addition to the one already in ovpn_socket_release), I'm already getting a bit rusty on the locking :/
Signature · 1 line
Sabrina
Jakub Kicinski
maintainerRe: [PATCH net 1/1] ovpn: fix race between deleting interface and adding new peer
Quoted 5 lines · On Thu, 23 Apr 2026 18:37:49 +0200 Sabrina Dubroca wrote:
We could also wrap all of
ovpn_peer_add(including the newreg_statecheck) innetdev_lock, since we can't move toNETREG_UNREGISTERINGuntilnetdev_lockis released (then I think we wouldn't need theREAD_ONCE(reg_state)). But I don't know if that's an acceptable use ofnetdev_lock.
Yup, fwiw it's a perfectly legitimate use case.
Sabrina Dubroca
reviewerRe: [PATCH net 1/1] ovpn: fix race between deleting interface and adding new peer
Quoted 8 lines · Jakub Kicinski
Quoted 5 lines · On Thu, 23 Apr 2026 18:37:49 +0200 Sabrina Dubroca wrote:
We could also wrap all of
ovpn_peer_add(including the newreg_statecheck) innetdev_lock, since we can't move toNETREG_UNREGISTERINGuntilnetdev_lockis released (then I think we wouldn't need theREAD_ONCE(reg_state)). But I don't know if that's an acceptable use ofnetdev_lock.Yup, fwiw it's a perfectly legitimate use case.
Ok. There's still a worrying bit in nesting lock_sock under netdev_lock (ovpn_peer_add -> netdev_lock -> ovpn_peer_add_p2p -> unlock_ovpn -> ovpn_socket_release -> lock_sock).
Signature · 1 line
Sabrina
Jakub Kicinski
maintainerRe: [PATCH net 1/1] ovpn: fix race between deleting interface and adding new peer
Quoted 8 lines · On Fri, 24 Apr 2026 00:27:10 +0200 Sabrina Dubroca wrote:
Quoted 7 lines · Jakub Kicinski
Quoted 5 lines · On Thu, 23 Apr 2026 18:37:49 +0200 Sabrina Dubroca wrote:
We could also wrap all of
ovpn_peer_add(including the newreg_statecheck) innetdev_lock, since we can't move toNETREG_UNREGISTERINGuntilnetdev_lockis released (then I think we wouldn't need theREAD_ONCE(reg_state)). But I don't know if that's an acceptable use ofnetdev_lock.
Quoted 5 lines
Quoted 1 line
Yup, fwiw it's a perfectly legitimate use case.
Ok. There's still a worrying bit in nesting
lock_sockundernetdev_lock(ovpn_peer_add->netdev_lock->ovpn_peer_add_p2p->unlock_ovpn->ovpn_socket_release->lock_sock).
No opinion on socket lock, TBH. It does indeed increase the potential for hard to trace deadlocks. But I'd think the ordering is intuitive - netdev lock "feels" heavier than socket lock.
Jakub Kicinski
maintainerRe: [PATCH net 1/1] ovpn: fix race between deleting interface and adding new peer
In reply to Antonio QuartulliQuoted 6 lines · On Thu, 23 Apr 2026 14:16:52 +0200 Antonio Quartulli wrote:
Quoted 3 lines
If you agree make sure Sashiko doesn't complain about anything else once it's public:
https://sashiko.dev/#/patchset/[email protected]Is there any way to get earlier access to these reviews? (at least for patches somehow related to me/ovpn)
netdev ones are blocked because noobs spam the list for a test. Which you also appear to be trying to do :D So I shall count that as a win, I guess? :)
The LLM is mostly just using the review prompts -
https://github.com/masoncl/review-prompts
point you favorite coding agent at that and ask it questions...