pull request: ovpn 2025-05-21
Subsystems (5)
Antonio Quartulli
maintainercover pull request: ovpn 2025-05-21
Hello netdev-team,
Here is (most likely) the last pull request for net-next for this round.
Patch 1 substitutes a call to setup_udp_tunnel_sock() along the cleanup path with cleanup_udp_tunnel_sock(). The latter is introduced in this patch as well.
Patch 2 fixes a critical race condition (leading to null-ptr-deref) triggered by ovpn removing a peer, while userspace is concurrently closing the transport socket.
An earlier revision of this patch was already discussed on the netdev mailing list and this version is the final result.
Finally patch 3 is fixing the TCP test case in the ovpn kselftests, accidentally broken by the introduction of the UDP IPv6 test case.
Please pull or let me know of any issue.
Thanks a lot!
Antonio,
The following changes since commit 9ab0ac0e532afd167b3bec39b2eb25c53486dcb5:
octeontx2-pf: Add tracepoint for NIX_PARSE_S (2025-05-20 12:37:37 +0200)
are available in the Git repository at:
https://github.com/OpenVPN/ovpn-net-next tags/ovpn-net-next-20250521
for you to fetch changes up to cb4cc0e4a5d0ddb655f72fb9626408f060c2c15c:
selftest/net/ovpn: fix TCP socket creation (2025-05-21 01:35:07 +0200)
----------------------------------------------------------------
This bugfix batch includes the following changes:
* dropped call to setup_udp_tunnel_sock() during cleanup ** substituted by new cleanup_udp_tunnel_sock()
* fixed race condition between peer removal (by kernel space) and socket closing (by userspace)
* fixed TCP kselftests
----------------------------------------------------------------
Antonio Quartulli (3):
ovpn: properly deconfigure UDP-tunnel
ovpn: ensure sk is still valid during cleanup selftest/net/ovpn: fix TCP socket creation
drivers/net/ovpn/io.c | 8 ++-- drivers/net/ovpn/netlink.c | 25 ++++++----- drivers/net/ovpn/peer.c | 4 +- drivers/net/ovpn/socket.c | 68 ++++++++++++++++------------- drivers/net/ovpn/socket.h | 4 +- drivers/net/ovpn/tcp.c | 65 ++++++++++++++------------- drivers/net/ovpn/tcp.h | 3 +- drivers/net/ovpn/udp.c | 37 +++++----------- drivers/net/ovpn/udp.h | 4 +- include/net/udp.h | 1 + include/net/udp_tunnel.h | 1 + net/ipv4/udp_tunnel_core.c | 28 ++++++++++++ net/ipv6/udp.c | 6 +++ tools/testing/selftests/net/ovpn/ovpn-cli.c | 1 + 14 files changed, 146 insertions(+), 109 deletions(-)
Antonio Quartulli
maintainerPATCH 1/3 ovpn: properly deconfigure UDP-tunnel
When deconfiguring a UDP-tunnel from a socket, we cannot call setup_udp_tunnel_sock(), as it is expected to be invoked only during setup.
Implement a new function named cleanup_udp_tunnel_sock(), that reverts was what done during setup, and invoke it.
This new function takes care of reverting everything that was done by setup_udp_tunnel_sock() (i.e. unsetting various members and cleaning up the encap state in the kernel).
Note that cleanup_udp_tunnel_sock() takes 'struct sock' as argument in preparation for a follow up patch, where 'struct ovpn' won't hold any reference to any 'struct socket' any more, but rather to its 'struct sock' member only.
Moreover implement udpv6_encap_disable() in order to allow udpv6_encap_needed_key to be decreased outside of ipv6.ko (similarly to udp_encap_disable() for IPv4).
--- drivers/net/ovpn/udp.c | 5 +---- include/net/udp.h | 1 + include/net/udp_tunnel.h | 1 + net/ipv4/udp_tunnel_core.c | 28 ++++++++++++++++++++++++++++ net/ipv6/udp.c | 6 ++++++ 5 files changed, 37 insertions(+), 4 deletions(-)
drivers/net/ovpn/udp.c +1 -4
@@ -442,8 +442,5 @@ int ovpn_udp_socket_attach(struct ovpn_socket *ovpn_sock,*/ void ovpn_udp_socket_detach (struct ovpn_socket *ovpn_sock) { -struct udp_tunnel_sock_cfg cfg = { }; - -setup_udp_tunnel_sock (sock_net (ovpn_sock->sock->sk), ovpn_sock->sock, - &cfg); +cleanup_udp_tunnel_sock (ovpn_sock->sock->sk); }
include/net/udp.h +1 -0
@@ -580,6 +580,7 @@ void udp_encap_disable(void);#if IS_ENABLED (CONFIG_IPV6 )DECLARE_STATIC_KEY_FALSE (udpv6_encap_needed_key);void udpv6_encap_enable (void ); +void udpv6_encap_disable (void );#endif static inline struct sk_buff *udp_rcv_segment(struct sock *sk,
include/net/udp_tunnel.h +1 -0
@@ -92,6 +92,7 @@ struct udp_tunnel_sock_cfg {/* Setup the given (UDP) sock to receive UDP encapsulated packets */ void setup_udp_tunnel_sock (struct net *net,struct socket *sock,struct udp_tunnel_sock_cfg *sock_cfg); +void cleanup_udp_tunnel_sock (struct sock *sk);/* -- List of parsable UDP tunnel types -- *
net/ipv4/udp_tunnel_core.c +28 -0
@@ -98,6 +98,34 @@ void setup_udp_tunnel_sock(struct net *net, struct socket *sock, }EXPORT_SYMBOL_GPL (setup_udp_tunnel_sock); +void cleanup_udp_tunnel_sock (struct sock *sk) +{ +/* Re-enable multicast loopback */ +inet_set_bit (MC_LOOP , sk); + +/* Disable CHECKSUM_UNNECESSARY to CHECKSUM_COMPLETE conversion */ +inet_dec_convert_csum (sk); + +rcu_assign_sk_user_data (sk,NULL ); + +udp_sk (sk)->encap_type =0 ; +udp_sk (sk)->encap_rcv =NULL ; +udp_sk (sk)->encap_err_rcv =NULL ; +udp_sk (sk)->encap_err_lookup =NULL ; +udp_sk (sk)->encap_destroy =NULL ; +udp_sk (sk)->gro_receive =NULL ; +udp_sk (sk)->gro_complete =NULL ; + +udp_clear_bit (ENCAP_ENABLED , sk); +#if IS_ENABLED (CONFIG_IPV6 ) +if (READ_ONCE (sk->sk_family) ==PF_INET6 ) +udpv6_encap_disable (); +#endif +udp_encap_disable (); +udp_tunnel_cleanup_gro (sk); +} +EXPORT_SYMBOL_GPL (cleanup_udp_tunnel_sock); +void udp_tunnel_push_rx_port (struct net_device *dev,struct socket *sock,unsigned short type) {
net/ipv6/udp.c +6 -0
@@ -602,6 +602,12 @@ void udpv6_encap_enable(void) }EXPORT_SYMBOL (udpv6_encap_enable); +void udpv6_encap_disable (void ) +{ +static_branch_dec (&udpv6_encap_needed_key); +} +EXPORT_SYMBOL (udpv6_encap_disable); +/* Handler for tunnels with arbitrary destination ports: no socket lookup, go * through error handlers in encapsulations looking for a match. */
Signature · 1 line
2.49.0
kernel test robot
build botRe: [PATCH net-next 1/3] ovpn: properly deconfigure UDP-tunnel
kernel test robot noticed the following build errors:
Hi Antonio,
kernel test robot noticed the following build errors:
[auto build test ERROR on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Antonio-Quartulli/ovpn-properly-deconfigure-UDP-tunnel/20250521-081355 base: net-next/main patch link: https://lore.kernel.org/r/20250520233937.5161-2-antonio%40openvpn.net patch subject: [PATCH net-next 1/3] ovpn: properly deconfigure UDP-tunnel config: sparc-randconfig-001-20250522 (https://download.01.org/0day-ci/archive/20250522/[email protected]/config) compiler: sparc-linux-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250522/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
sparc-linux-ld: net/ipv4/udp_tunnel_core.o: in function `cleanup_udp_tunnel_sock':
>> net/ipv4/udp_tunnel_core.c:122:(.text+0x880): undefined reference to `udpv6_encap_disable'
vim +122 net/ipv4/udp_tunnel_core.c
100
101 void cleanup_udp_tunnel_sock(struct sock *sk)
102 {
103 /* Re-enable multicast loopback */
104 inet_set_bit(MC_LOOP, sk);
105
106 /* Disable CHECKSUM_UNNECESSARY to CHECKSUM_COMPLETE conversion */
107 inet_dec_convert_csum(sk);
108
109 rcu_assign_sk_user_data(sk, NULL);
110
111 udp_sk(sk)->encap_type = 0;
112 udp_sk(sk)->encap_rcv = NULL;
113 udp_sk(sk)->encap_err_rcv = NULL;
114 udp_sk(sk)->encap_err_lookup = NULL;
115 udp_sk(sk)->encap_destroy = NULL;
116 udp_sk(sk)->gro_receive = NULL;
117 udp_sk(sk)->gro_complete = NULL;
118
119 udp_clear_bit(ENCAP_ENABLED, sk);
120 #if IS_ENABLED(CONFIG_IPV6)
121 if (READ_ONCE(sk->sk_family) == PF_INET6)
> 122 udpv6_encap_disable();
123 #endif
124 udp_encap_disable();
125 udp_tunnel_cleanup_gro(sk);
126 }
127 EXPORT_SYMBOL_GPL(cleanup_udp_tunnel_sock);
128
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Antonio Quartulli
maintainerPATCH 2/3 ovpn: ensure sk is still valid during cleanup
In reply to Antonio QuartulliRemoving a peer while userspace attempts to close its transport socket triggers a race condition resulting in the following crash:
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000077: 0000 [#1] SMP KASAN KASAN: null-ptr-deref in range [0x00000000000003b8-0x00000000000003bf] CPU: 12 UID: 0 PID: 162 Comm: kworker/12:1 Tainted: G O 6.15.0-rc2-00635-g521139ac3840 #272 PREEMPT(full) Tainted: [O]=OOT_MODULE Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-20240910_120124-localhost 04/01/2014 Workqueue: events ovpn_peer_keepalive_work [ovpn] RIP: 0010:ovpn_socket_release+0x23c/0x500 [ovpn] Code: ea 03 80 3c 02 00 0f 85 71 02 00 00 48 b8 00 00 00 00 00 fc ff df 4d 8b 64 24 18 49 8d bc 24 be 03 00 00 48 89 fa 48 c1 ea 03 <0f> b6 14 02 48 89 f8 83 e0 07 83 c0 01 38 d0 7c 08 84 d2 0f 85 30 RSP: 0018:ffffc90000c9fb18 EFLAGS: 00010217 RAX: dffffc0000000000 RBX: ffff8881148d7940 RCX: ffffffff817787bb RDX: 0000000000000077 RSI: 0000000000000008 RDI: 00000000000003be RBP: ffffc90000c9fb30 R08: 0000000000000000 R09: fffffbfff0d3e840 R10: ffffffff869f4207 R11: 0000000000000000 R12: 0000000000000000 R13: ffff888115eb9300 R14: ffffc90000c9fbc8 R15: 000000000000000c FS: 0000000000000000(0000) GS:ffff8882b0151000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f37266b6114 CR3: 00000000054a8000 CR4: 0000000000750ef0 PKRU: 55555554 Call Trace: <TASK> unlock_ovpn+0x8b/0xe0 [ovpn] ovpn_peer_keepalive_work+0xe3/0x540 [ovpn] ? ovpn_peers_free+0x780/0x780 [ovpn] ? lock_acquire+0x56/0x70 ? process_one_work+0x888/0x1740 process_one_work+0x933/0x1740 ? pwq_dec_nr_in_flight+0x10b0/0x10b0 ? move_linked_works+0x12d/0x2c0 ? assign_work+0x163/0x270 worker_thread+0x4d6/0xd90 ? preempt_count_sub+0x4c/0x70 ? process_one_work+0x1740/0x1740 kthread+0x36c/0x710 ? trace_preempt_on+0x8c/0x1e0 ? kthread_is_per_cpu+0xc0/0xc0 ? preempt_count_sub+0x4c/0x70 ? _raw_spin_unlock_irq+0x36/0x60 ? calculate_sigpending+0x7b/0xa0 ? kthread_is_per_cpu+0xc0/0xc0 ret_from_fork+0x3a/0x80 ? kthread_is_per_cpu+0xc0/0xc0 ret_from_fork_asm+0x11/0x20 </TASK> Modules linked in: ovpn(O)
This happens because the peer deletion operation reaches ovpn_socket_release() while ovpn_sock->sock (struct socket *) and its sk member (struct sock *) are still both valid. Here synchronize_rcu() is invoked, after which ovpn_sock->sock->sk becomes NULL, due to the concurrent socket closing triggered from userspace.
After having invoked synchronize_rcu(), ovpn_socket_release() will attempt dereferencing ovpn_sock->sock->sk, triggering the crash reported above.
The reason for accessing sk is that we need to retrieve its protocol and continue the cleanup routine accordingly.
This crash can be easily produced by running openvpn userspace in client mode with --keepalive 10 20, while entirely omitting this option on the server side.
After 20 seconds ovpn will assume the peer (server) to be dead, will start removing it and will notify userspace. The latter will receive the notification and close the transport socket, thus triggering the crash.
To fix the race condition for good, we need to refactor ovpn_socket. Since we are always only interested in the sock->sk member (struct sock *) we can directly hold a reference to it, raher than relying on sock->sk.
This means changing ovpn_socket->sock to ovpn_socket->sk.
While holding a reference to sk, we can increase its refcounter without affecting the socket close()/destroy() notification (which we rely on when userspace closes a socket we are using).
By increasing sk's refcounter we know we can dereference it in ovpn_socket_release() without incurring in any race condition anymore.
ovpn_socket_release() will ultimately decrease the reference counter.
--- drivers/net/ovpn/io.c | 8 ++--- drivers/net/ovpn/netlink.c | 25 ++++++++------ drivers/net/ovpn/peer.c | 4 +-- drivers/net/ovpn/socket.c | 68 +++++++++++++++++++++----------------- drivers/net/ovpn/socket.h | 4 +-- drivers/net/ovpn/tcp.c | 65 ++++++++++++++++++------------------ drivers/net/ovpn/tcp.h | 3 +- drivers/net/ovpn/udp.c | 34 +++++++------------ drivers/net/ovpn/udp.h | 4 +-- 9 files changed, 109 insertions(+), 106 deletions(-)
drivers/net/ovpn/io.c +4 -4
@@ -134,7 +134,7 @@ void ovpn_decrypt_post(void *data, int ret)rcu_read_lock (); sock =rcu_dereference (peer->sock); -if (sock && sock->sock->sk->sk_protocol ==IPPROTO_UDP ) +if (sock && sock->sk->sk_protocol ==IPPROTO_UDP )/* check if this peer changed local or remote endpoint */ ovpn_peer_endpoints_update (peer, skb);rcu_read_unlock ();
@@ -270,12 +270,12 @@ void ovpn_encrypt_post(void *data, int ret)if (unlikely (!sock)) goto err_unlock; -switch (sock->sock->sk->sk_protocol) { +switch (sock->sk->sk_protocol) {case IPPROTO_UDP : -ovpn_udp_send_skb (peer, sock->sock, skb); +ovpn_udp_send_skb (peer, sock->sk, skb);break ;case IPPROTO_TCP : -ovpn_tcp_send_skb (peer, sock->sock, skb); +ovpn_tcp_send_skb (peer, sock->sk, skb);break ;default :/* no transport configured yet */
drivers/net/ovpn/netlink.c +15 -10
@@ -423,9 +423,14 @@ int ovpn_nl_peer_new_doit(struct sk_buff *skb, struct genl_info *info) ovpn_sock =ovpn_socket_new (sock, peer);/* at this point we unconditionally drop the reference to the socket: * - in case of error, the socket has to be dropped -* - if case of success, the socket is configured and let +* - if case of success, the socket is configured and we let * userspace own the reference, so that the latter can -* trigger the final close() +* trigger the final close(). +* +* NOTE: at this point ovpn_socket_new() has acquired a reference +* to sock->sk. That's needed especially to avoid race conditions +* during cleanup, where sock may still be alive, but sock->sk may be +* getting released concurrently. */ sockfd_put (sock);if (IS_ERR (ovpn_sock)) {
@@ -501,7 +506,7 @@ int ovpn_nl_peer_set_doit(struct sk_buff *skb, struct genl_info *info)/* when using a TCP socket the remote IP is not expected */ rcu_read_lock (); sock =rcu_dereference (peer->sock); -if (sock && sock->sock->sk->sk_protocol ==IPPROTO_TCP && +if (sock && sock->sk->sk_protocol ==IPPROTO_TCP && (attrs[OVPN_A_PEER_REMOTE_IPV4 ] || attrs[OVPN_A_PEER_REMOTE_IPV6 ])) {rcu_read_unlock ();
@@ -559,14 +564,14 @@ static int ovpn_nl_send_peer(struct sk_buff *skb, const struct genl_info *info, goto err_unlock; } -if (!net_eq (genl_info_net (info),sock_net (sock->sock->sk))) { +if (!net_eq (genl_info_net (info),sock_net (sock->sk))) { id =peernet2id_alloc (genl_info_net (info), -sock_net (sock->sock->sk), +sock_net (sock->sk),GFP_ATOMIC );if (nla_put_s32 (skb,OVPN_A_PEER_SOCKET_NETNSID , id)) goto err_unlock; } - local_port =inet_sk (sock->sock->sk)->inet_sport; + local_port =inet_sk (sock->sk)->inet_sport;rcu_read_unlock ();if (nla_put_u32 (skb,OVPN_A_PEER_ID , peer->id))
@@ -1153,8 +1158,8 @@ int ovpn_nl_peer_del_notify(struct ovpn_peer *peer) ret = -EINVAL ; goto err_unlock; } -genlmsg_multicast_netns (&ovpn_nl_family,sock_net (sock->sock->sk), - msg,0 ,OVPN_NLGRP_PEERS ,GFP_ATOMIC ); +genlmsg_multicast_netns (&ovpn_nl_family,sock_net (sock->sk), msg,0 , +OVPN_NLGRP_PEERS ,GFP_ATOMIC );rcu_read_unlock ();return 0 ;
@@ -1218,8 +1223,8 @@ int ovpn_nl_key_swap_notify(struct ovpn_peer *peer, u8 key_id) ret = -EINVAL ; goto err_unlock; } -genlmsg_multicast_netns (&ovpn_nl_family,sock_net (sock->sock->sk), - msg,0 ,OVPN_NLGRP_PEERS ,GFP_ATOMIC ); +genlmsg_multicast_netns (&ovpn_nl_family,sock_net (sock->sk), msg,0 , +OVPN_NLGRP_PEERS ,GFP_ATOMIC );rcu_read_unlock ();return 0 ;
drivers/net/ovpn/peer.c +2 -2
@@ -1145,7 +1145,7 @@ static void ovpn_peer_release_p2p(struct ovpn_priv *ovpn, struct sock *sk,if (sk) { ovpn_sock =rcu_access_pointer (peer->sock); -if (!ovpn_sock || ovpn_sock->sock->sk != sk) { +if (!ovpn_sock || ovpn_sock->sk != sk) {spin_unlock_bh (&ovpn->lock);ovpn_peer_put (peer);return ;
@@ -1175,7 +1175,7 @@ static void ovpn_peers_release_mp(struct ovpn_priv *ovpn, struct sock *sk,if (sk) {rcu_read_lock (); ovpn_sock =rcu_dereference (peer->sock); - remove = ovpn_sock && ovpn_sock->sock->sk == sk; + remove = ovpn_sock && ovpn_sock->sk == sk;rcu_read_unlock (); }
drivers/net/ovpn/socket.c +38 -30
162 lines not on this page · raw message
drivers/net/ovpn/socket.h +2 -2
@@ -22,7 +22,7 @@ struct ovpn_peer;* @ovpn: ovpn instance owning this socket (UDP only) * @dev_tracker: reference tracker for associated dev (UDP only) * @peer: unique peer transmitting over this socket (TCP only) -* @sock: the low level sock object +* @sk: the low level sock object * @refcount: amount of contexts currently referencing this object * @work: member used to schedule release routine (it may block) * @tcp_tx_work: work for deferring outgoing packet processing (TCP only)
@@ -36,7 +36,7 @@ struct ovpn_socket {struct ovpn_peer *peer; }; -struct socket *sock; +struct sock *sk;struct kref refcount;struct work_struct work;struct work_struct tcp_tx_work;
drivers/net/ovpn/tcp.c +32 -33
143 lines not on this page · raw message
drivers/net/ovpn/tcp.h +2 -1
@@ -30,7 +30,8 @@ void ovpn_tcp_socket_wait_finish(struct ovpn_socket *sock);* Required by the OpenVPN protocol in order to extract packets from * the TCP stream on the receiver side. */ -void ovpn_tcp_send_skb (struct ovpn_peer *peer,struct socket *sock,struct sk_buff *skb); +void ovpn_tcp_send_skb (struct ovpn_peer *peer,struct sock *sk, +struct sk_buff *skb);void ovpn_tcp_tx_work (struct work_struct *work);#endif /* _NET_OVPN_TCP_H_ */
drivers/net/ovpn/udp.c +12 -22
@@ -43,7 +43,7 @@ static struct ovpn_socket *ovpn_socket_from_udp_sock(struct sock *sk)return NULL ;/* make sure that sk matches our stored transport socket */ -if (unlikely (!ovpn_sock->sock || sk != ovpn_sock->sock->sk)) +if (unlikely (!ovpn_sock->sk || sk != ovpn_sock->sk))return NULL ;return ovpn_sock;
@@ -335,32 +335,22 @@ static int ovpn_udp_output(struct ovpn_peer *peer, struct dst_cache *cache,/** * ovpn_udp_send_skb - prepare skb and send it over via UDP * @peer: the destination peer -* @sock: the RCU protected peer socket +* @sk: peer socket * @skb: the packet to send */ -void ovpn_udp_send_skb (struct ovpn_peer *peer,struct socket *sock, +void ovpn_udp_send_skb (struct ovpn_peer *peer,struct sock *sk,struct sk_buff *skb) { -int ret =-1 ; +int ret; skb->dev = peer->ovpn->dev;/* no checksum performed at this layer */ skb->ip_summed =CHECKSUM_NONE ; -/* get socket info */ -if (unlikely (!sock)) { -net_warn_ratelimited ("%s: no sock for remote peer %u\n" , -netdev_name (peer->ovpn->dev), peer->id); - goto out; - } -/* crypto layer -> transport (UDP) */ - ret =ovpn_udp_output (peer, &peer->dst_cache, sock->sk, skb); -out: -if (unlikely (ret <0 )) { + ret =ovpn_udp_output (peer, &peer->dst_cache, sk, skb); +if (unlikely (ret <0 ))kfree_skb (skb); -return ; - } }static void ovpn_udp_encap_destroy (struct sock *sk)
@@ -383,6 +373,7 @@ static void ovpn_udp_encap_destroy(struct sock *sk)/** * ovpn_udp_socket_attach - set udp-tunnel CBs on socket and link it to ovpn * @ovpn_sock: socket to configure +* @sock: the socket container to be passed to setup_udp_tunnel_sock() * @ovpn: the openvp instance to link * * After invoking this function, the sock will be controlled by ovpn so that
@@ -390,7 +381,7 @@ static void ovpn_udp_encap_destroy(struct sock *sk)* * Return: 0 on success or a negative error code otherwise */ -int ovpn_udp_socket_attach (struct ovpn_socket *ovpn_sock, +int ovpn_udp_socket_attach (struct ovpn_socket *ovpn_sock,struct socket *sock,struct ovpn_priv *ovpn) {struct udp_tunnel_sock_cfg cfg = {
@@ -398,17 +389,16 @@ int ovpn_udp_socket_attach(struct ovpn_socket *ovpn_sock, .encap_rcv = ovpn_udp_encap_recv, .encap_destroy = ovpn_udp_encap_destroy, }; -struct socket *sock = ovpn_sock->sock;struct ovpn_socket *old_data;int ret;/* make sure no pre-existing encapsulation handler exists */ rcu_read_lock (); - old_data =rcu_dereference_sk_user_data (sock->sk); + old_data =rcu_dereference_sk_user_data (ovpn_sock->sk);if (!old_data) {/* socket is currently unused - we can take it */ rcu_read_unlock (); -setup_udp_tunnel_sock (sock_net (sock->sk), sock, &cfg); +setup_udp_tunnel_sock (sock_net (ovpn_sock->sk), sock, &cfg);return 0 ; }
@@ -421,7 +411,7 @@ int ovpn_udp_socket_attach(struct ovpn_socket *ovpn_sock,* Unlikely TCP, a single UDP socket can be used to talk to many remote * hosts and therefore openvpn instantiates one only for all its peers */ -if ((READ_ONCE (udp_sk (sock->sk)->encap_type) ==UDP_ENCAP_OVPNINUDP ) && +if ((READ_ONCE (udp_sk (ovpn_sock->sk)->encap_type) ==UDP_ENCAP_OVPNINUDP ) && old_data->ovpn == ovpn) {netdev_dbg (ovpn->dev,"provided socket already owned by this interface\n" );
@@ -442,5 +432,5 @@ int ovpn_udp_socket_attach(struct ovpn_socket *ovpn_sock,*/ void ovpn_udp_socket_detach (struct ovpn_socket *ovpn_sock) { -cleanup_udp_tunnel_sock (ovpn_sock->sock->sk); +cleanup_udp_tunnel_sock (ovpn_sock->sk); }
drivers/net/ovpn/udp.h +2 -2
@@ -15,11 +15,11 @@ struct ovpn_peer;struct ovpn_priv ;struct socket ; -int ovpn_udp_socket_attach (struct ovpn_socket *ovpn_sock, +int ovpn_udp_socket_attach (struct ovpn_socket *ovpn_sock,struct socket *sock,struct ovpn_priv *ovpn);void ovpn_udp_socket_detach (struct ovpn_socket *ovpn_sock); -void ovpn_udp_send_skb (struct ovpn_peer *peer,struct socket *sock, +void ovpn_udp_send_skb (struct ovpn_peer *peer,struct sock *sk,struct sk_buff *skb);#endif /* _NET_OVPN_UDP_H_ */
Signature · 1 line
2.49.0
Antonio Quartulli
maintainerPATCH 3/3 selftest/net/ovpn: fix TCP socket creation
In reply to Antonio QuartulliTCP sockets cannot be created with AF_UNSPEC, but
one among the supported family must be used.
Since commit 944f8b6abab6 ("selftest/net/ovpn: extend coverage with more test cases") the default address family for all tests was changed from AF_INET to AF_UNSPEC, thus breaking all TCP cases.
Restore AF_INET as default address family for TCP listeners.
--- tools/testing/selftests/net/ovpn/ovpn-cli.c | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/net/ovpn/ovpn-cli.c +1 -0
@@ -2166,6 +2166,7 @@ static int ovpn_parse_cmd_args(struct ovpn_ctx *ovpn, int argc, char *argv[]) ovpn->peers_file = argv[4 ]; + ovpn->sa_family =AF_INET ;if (argc >5 && !strcmp (argv[5 ],"ipv6" )) ovpn->sa_family =AF_INET6 ;break ;
Signature · 1 line
2.49.0