[Openvpn-devel] ovpn-dco: fix IPv6 VPN address comparison in peer lookup

Message ID tencent_DB0ADABF741A42D32620ADE82AF77005FC09@qq.com
State New
Headers
Series [Openvpn-devel] ovpn-dco: fix IPv6 VPN address comparison in peer lookup |

Commit Message

Liu Chong Nov. 19, 2026, 4:40 a.m. UTC
  In ovpn_peer_lookup_vpn_addr6() the word-by-word comparison uses
'continue' on mismatch, but it only skips to the next word of the
inner loop, not to the next peer. The comparison therefore has no
effect and the first holdable peer in the bucket is returned even
if its IPv6 address does not match.

In multi-peer mode a packet can be sent to the wrong peer whenever
two IPv6 peers share a hash bucket (with a single peer per bucket
the bug is masked).

Replace the broken loop with ipv6_addr_equal(), like in the IPv4
lookup path.

Fixes: 94581f0cb760 ("ovpn-dco: restructure code to allow supporting multiple link to peers")
Signed-off-by: Liu Chong <979504756@qq.com>
---
 drivers/net/ovpn-dco/peer.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
  

Patch

diff --git a/drivers/net/ovpn-dco/peer.c b/drivers/net/ovpn-dco/peer.c
index cecbbb4..aee9f11 100644
--- a/drivers/net/ovpn-dco/peer.c
+++ b/drivers/net/ovpn-dco/peer.c
@@ -355,14 +355,11 @@  static struct ovpn_peer *ovpn_peer_lookup_vpn_addr4(struct hlist_head *head, __b
 static struct ovpn_peer *ovpn_peer_lookup_vpn_addr6(struct hlist_head *head, struct in6_addr *addr)
 {
 	struct ovpn_peer *tmp, *peer = NULL;
-	int i;
 
 	rcu_read_lock();
 	hlist_for_each_entry_rcu(tmp, head, hash_entry_addr6) {
-		for (i = 0; i < 4; i++) {
-			if (addr->s6_addr32[i] != tmp->vpn_addrs.ipv6.s6_addr32[i])
-				continue;
-		}
+		if (!ipv6_addr_equal(addr, &tmp->vpn_addrs.ipv6))
+			continue;
 
 		if (!ovpn_peer_hold(tmp))
 			continue;