ovpn-dco: fix IPv6 VPN address comparison in peer lookup
PATCH 1/1 ovpn-dco: fix IPv6 VPN address comparison in peer lookup
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.
--- drivers/net/ovpn-dco/peer.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/ovpn-dco/peer.c +2 -5
@@ -355,14 +355,11 @@ static struct ovpn_peer *ovpn_peer_lookup_vpn_addr4(struct hlist_head *head, __bstatic 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 ;
Signature · 8 lines
2.43.0 _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Hi,
Thanks for the patch.
Quoted 10 lines · Liu Chong via Openvpn-devel
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).
Quoted 5 lines
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 <[email protected]>
Regards,
Signature · 8 lines
Ralf Lici Mandelbit Srl _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Antonio Quartulli
AppliedFrom: Antonio Quartulli <[email protected]>
Quoted 11 lines · Liu Chong via Openvpn-devel
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).
[...]
Applied, thanks!
[1/1] ovpn-dco: fix IPv6 VPN address comparison in peer lookup
commit: 846f066640bb16abdc8a8b0f9cf0efc8437be774
Best regards,
Signature · 7 lines
Antonio Quartulli <[email protected]> _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Hi Liu,
thanks for your patches.
Out of curiosity, why are you still on ovpn-dco-v2 and haven't transitioned to the new ovpn kernel module yet?
Best,
Quoted 40 lines · Liu Chong via Openvpn-devel
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 <[email protected]>--- drivers/net/ovpn-dco/peer.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)drivers/net/ovpn-dco/peer.c +2
-5@@ -355,14 +355,11 @@ static struct ovpn_peer *ovpn_peer_lookup_vpn_addr4(struct hlist_head *head, __bstatic 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 ;
Signature · 8 lines
Antonio Quartulli _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel