ovpn: fix race between deleting interface and adding new peer
Subsystems (2)
PATCH 1/1 ovpn: fix race between deleting interface and adding new peer
From: Antonio Quartulli <[email protected]...>
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 and thus an incoming CMD_PEER_NEW cannot have any effect anymore.
At this point ovpn_dellink() becomes empty and can just be removed.
--- drivers/net/ovpn/main.c | 12 ++---------- 1 file changed, 2 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, };
Signature · 1 line
2.52.0
Quoted 22 lines · Antonio Quartulli
From: Antonio Quartulli <[email protected]...>
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 aCMD_PEER_NEWmessage 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 and thus an incomingCMD_PEER_NEWcannot have any effect anymore.At this point
ovpn_dellink()becomes empty and can just be removed.
Quoted 8 lines
Reported-by Hyunwoo Kim <[email protected]...>Suggested-by Sabrina Dubroca <[email protected]...>Fixes 80747caef33d ("ovpn: introduce the ovpn_peer object")Signed-off-by Antonio Quartulli <[email protected]...>--- drivers/net/ovpn/main.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
Thanks. This issue probably got introduced when I made you move some stuff from the UNREGISTER notifier into deletion, during the initial review.
Signature · 1 line
Sabrina
Quoted 32 lines · Sabrina Dubroca
Quoted 22 lines · Antonio Quartulli
From: Antonio Quartulli <[email protected]...>
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 aCMD_PEER_NEWmessage 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 and thus an incomingCMD_PEER_NEWcannot have any effect anymore.At this point
ovpn_dellink()becomes empty and can just be removed.Quoted 8 lines
Reported-by Hyunwoo Kim <[email protected]...>Suggested-by Sabrina Dubroca <[email protected]...>Fixes 80747caef33d ("ovpn: introduce the ovpn_peer object")Signed-off-by Antonio Quartulli <[email protected]...>--- drivers/net/ovpn/main.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
Quoted 6 lines
Reviewed-by Sabrina Dubroca <[email protected]...>Thanks. This issue probably got introduced when I made you move some stuff from the UNREGISTER notifier into deletion, during the initial review.
I also think it was around those times.
This area has been reshuffled quite a bit :)
Will send to net ASAP.
Thanks!
Regards,
Signature · 1 line
Antonio Quartulli