History

ovpn: hash floated peer by transport identity only

The by_transp_addr table is keyed on the peer's remote transport address, but the float rehash hashed bind->remote directly, while the two other sites that touch the table build a clean key first: ovpn_peer_add_mp() and the lookup in ovpn_peer_get_by_transp_addr() both hash a sockaddr holding only family/address/port. For a link-local IPv6 peer, bind->remote carries sin6_scope_id (set from ipv6_iface_scope_id() when the endpoint is learned), and that field is folded into the jhash() over sizeof(struct sockaddr_in6). The lookup never sets sin6_scope_id, so after such a peer floats it is rehashed into a scope_id-dependent bucket that lookups (scope_id 0) never visit, making the peer unreachable through the by_transp_addr fallback. ovpn_peer_transp_match() only compares address and port, so the hash was keying on a field the match ignores. sin6_scope_id must stay in bind->remote because the TX path uses it as flowi6_oif, so it cannot just be cleared there. Instead build the hash key from family/address/port only, exactly like ovpn_peer_add_mp() and the lookup, so all three sites agree on the bucket.

Antonio Quartulli committed 3 months ago

Commit b47a52d1 parent 3f012bd1 file · +21 −4Browse files

Unified · Split

drivers/net/ovpn/peer.c+21−4
@@ -904,7 +904,10 @@ bool ovpn_peer_check_by_src(struct ovpn_priv *ovpn, struct sk_buff *skb, · 903 unmodified lines
904static void __ovpn_peer_hash_transp_addr(struct ovpn_peer *peer,904static void __ovpn_peer_hash_transp_addr(struct ovpn_peer *peer,
905 const struct ovpn_bind *bind)905 const struct ovpn_bind *bind)
906{906{
907 struct sockaddr_storage sa = {};
907 struct hlist_nulls_head *nhead;908 struct hlist_nulls_head *nhead;
909 struct sockaddr_in6 *sa6;
910 struct sockaddr_in *sa4;
908 size_t salen;911 size_t salen;
909 912
910 lockdep_assert_held(&peer->ovpn->lock);913 lockdep_assert_held(&peer->ovpn->lock);
@@ -920,12 +923,26 @@ static void __ovpn_peer_hash_transp_addr(struct ovpn_peer *peer, · 9 unmodified lines
920 if (unlikely(hlist_unhashed(&peer->hash_entry_id)))923 if (unlikely(hlist_unhashed(&peer->hash_entry_id)))
921 return;924 return;
922 925
926 /* Build the hash key from the transport identity only
927 * (family/address/port), matching ovpn_peer_add_mp() and the lookup
928 * in ovpn_peer_get_by_transp_addr(). Hashing bind->remote directly
929 * would fold in sin6_scope_id (set on the float path but never by the
930 * lookup), scattering the peer into a bucket lookups cannot reach.
931 */
923 switch (bind->remote.in4.sin_family) {932 switch (bind->remote.in4.sin_family) {
924 case AF_INET:933 case AF_INET:
925 salen = sizeof(struct sockaddr_in);934 sa4 = (struct sockaddr_in *)&sa;
935 sa4->sin_family = AF_INET;
936 sa4->sin_addr.s_addr = bind->remote.in4.sin_addr.s_addr;
937 sa4->sin_port = bind->remote.in4.sin_port;
938 salen = sizeof(*sa4);
926 break;939 break;
927 case AF_INET6:940 case AF_INET6:
928 salen = sizeof(struct sockaddr_in6);941 sa6 = (struct sockaddr_in6 *)&sa;
942 sa6->sin6_family = AF_INET6;
943 sa6->sin6_addr = bind->remote.in6.sin6_addr;
944 sa6->sin6_port = bind->remote.in6.sin6_port;
945 salen = sizeof(*sa6);
929 break;946 break;
930 default:947 default:
931 return;948 return;
@@ -934,8 +951,8 @@ static void __ovpn_peer_hash_transp_addr(struct ovpn_peer *peer, · 2 unmodified lines
934 /* remove old hashing (no-op if entry is not currently linked) */951 /* remove old hashing (no-op if entry is not currently linked) */
935 hlist_nulls_del_init_rcu(&peer->hash_entry_transp_addr);952 hlist_nulls_del_init_rcu(&peer->hash_entry_transp_addr);
936 /* re-add with current transport address */953 /* re-add with current transport address */
937 nhead = ovpn_get_hash_head(peer->ovpn->peers->by_transp_addr,954 nhead = ovpn_get_hash_head(peer->ovpn->peers->by_transp_addr, &sa,
938 &bind->remote, salen);955 salen);
939 hlist_nulls_add_head_rcu(&peer->hash_entry_transp_addr, nhead);956 hlist_nulls_add_head_rcu(&peer->hash_entry_transp_addr, nhead);
940}957}
941 958

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t