[Openvpn-devel,net,1/3] ovpn: reset dst cache before publishing a new bind

Message ID d537b82354d90522b462dc0ba40e61d0684965bf.1795703343.git.ralf@mandelbit.com
State New
Headers
Series ovpn: fix issues reported by Sashiko |

Commit Message

Ralf Lici Nov. 26, 2026, 2:45 p.m. UTC
  When the peer endpoint changes, the new bind is published with RCU
before the dst cache is reset. TX does not take peer->lock before the
cache lookup, so a concurrent transmitter can pick up the new bind and
still get a hit on the entry cached for the old one.

The packet then goes out over the old route and cached source address
but towards the new remote. On a cross-family float, dst_cache_get_ip4
or dst_cache_get_ip6 would also return a dst of the wrong family, which
is then passed to the other family's xmit helper.

Reset the cache before publishing the new bind, both when the endpoint
is updated from RX and when it is changed via netlink. Both run under
peer->lock, which a TX must hold to store a new dst, and the store
requires the bind to still be the current one. Therefore, once the new
bind is visible no stale entry can be repopulated. A failed bind update
at worst costs one extra cache miss.

Fixes: aea934a221ec ("ovpn: replace bind when learning local endpoint")
Fixes: 1d36a36f6d53 ("ovpn: implement peer add/get/dump/delete via netlink")
Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260921102215.3599702-1-antonio%40openvpn.net?part=5
Signed-off-by: Ralf Lici <ralf@mandelbit.com>
---
 drivers/net/ovpn/netlink.c |  7 ++++++-
 drivers/net/ovpn/peer.c    | 10 +++++-----
 2 files changed, 11 insertions(+), 6 deletions(-)
  

Patch

diff --git a/drivers/net/ovpn/netlink.c b/drivers/net/ovpn/netlink.c
index 5432bc2eb8e8..6231d87304e1 100644
--- a/drivers/net/ovpn/netlink.c
+++ b/drivers/net/ovpn/netlink.c
@@ -333,6 +333,12 @@  static int ovpn_nl_peer_modify(struct ovpn_peer *peer, struct genl_info *info,
 		 */
 		local_ip = ovpn_nl_attr_local_ip(attrs);
 
+		/* reset the cache before publishing the new bind, so that
+		 * concurrent TX cannot pair it with a route cached for the
+		 * old one
+		 */
+		dst_cache_reset(&peer->dst_cache);
+
 		/* set peer sockaddr */
 		ret = ovpn_peer_reset_sockaddr(peer, &ss, local_ip);
 		if (ret < 0) {
@@ -341,7 +347,6 @@  static int ovpn_nl_peer_modify(struct ovpn_peer *peer, struct genl_info *info,
 					       ret);
 			goto err_unlock;
 		}
-		dst_cache_reset(&peer->dst_cache);
 	}
 
 	/* In a multipeer-to-multipeer setup we may have asymmetric peer IDs,
diff --git a/drivers/net/ovpn/peer.c b/drivers/net/ovpn/peer.c
index 2067825bb5b6..07f3fd9cbed6 100644
--- a/drivers/net/ovpn/peer.c
+++ b/drivers/net/ovpn/peer.c
@@ -294,16 +294,16 @@  void ovpn_peer_endpoints_update(struct ovpn_peer *peer, struct sk_buff *skb)
 		goto unlock;
 	}
 
+	/* reset the cache before publishing the new bind, so that concurrent TX
+	 * cannot pair it with a route cached for the old one
+	 */
+	dst_cache_reset(&peer->dst_cache);
+
 	if (unlikely(ovpn_peer_reset_sockaddr(peer,
 					      (struct sockaddr_storage *)&ss,
 					      local_ip) < 0))
 		goto unlock;
 
-	/* reset the cache only after a successful bind update to avoid useless
-	 * cache misses on concurrent TX
-	 */
-	dst_cache_reset(&peer->dst_cache);
-
 	/* if only the local address changed, bail out now */
 	if (!floated)
 		goto unlock;