pull request: ovpn 2025-05-22
Subsystems (6)
Antonio Quartulli
maintainercover pull request: ovpn 2025-05-22
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, with attention to the CONFIG_IPV6=m case.
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.
Patch 3 is fixing the TCP test case in the ovpn kselftests, accidentally broken by the introduction of the UDP IPv6 test case.
Patch 4 is adding a missing kselftest script which is already referenced by the Makefile.
Please pull or let me know of any issue.
Thanks a lot!
Antonio,
Antonio Quartulli (4):
ovpn: properly deconfigure UDP-tunnel
ovpn: ensure sk is still valid during cleanup
selftest/net/ovpn: fix TCP socket creation
selftest/net/ovpn: fix missing file
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/ipv6_stubs.h | 1 + include/net/udp.h | 1 + include/net/udp_tunnel.h | 13 ++++ net/ipv4/udp_tunnel_core.c | 22 ++++++ net/ipv6/af_inet6.c | 1 + net/ipv6/udp.c | 6 ++ tools/testing/selftests/net/ovpn/ovpn-cli.c | 1 + .../selftests/net/ovpn/test-large-mtu.sh | 9 +++ 17 files changed, 163 insertions(+), 109 deletions(-) create mode 100755 tools/testing/selftests/net/ovpn/test-large-mtu.sh
Signature · 48 lines
2.49.0
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-20250522
for you to fetch changes up to 35c3e81b334ed76093d5318238e869b46e3a0e21:
selftest/net/ovpn: fix missing file (2025-05-22 15:59:08 +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)
* minor fixes for ovpn kselftests
----------------------------------------------------------------
Antonio Quartulli (4):
ovpn: properly deconfigure UDP-tunnel
ovpn: ensure sk is still valid during cleanup
selftest/net/ovpn: fix TCP socket creation
selftest/net/ovpn: fix missing file
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/ipv6_stubs.h | 1 +
include/net/udp.h | 1 +
include/net/udp_tunnel.h | 13 +++++
net/ipv4/udp_tunnel_core.c | 22 +++++++
net/ipv6/af_inet6.c | 1 +
net/ipv6/udp.c | 6 ++
tools/testing/selftests/net/ovpn/ovpn-cli.c | 1 +
tools/testing/selftests/net/ovpn/test-large-mtu.sh | 9 +++
17 files changed, 163 insertions(+), 109 deletions(-)
create mode 100755 tools/testing/selftests/net/ovpn/test-large-mtu.shAntonio Quartulli
maintainerPATCH 1/4 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/ipv6_stubs.h | 1 + include/net/udp.h | 1 + include/net/udp_tunnel.h | 13 +++++++++++++ net/ipv4/udp_tunnel_core.c | 22 ++++++++++++++++++++++ net/ipv6/af_inet6.c | 1 + net/ipv6/udp.c | 6 ++++++ 7 files changed, 45 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/ipv6_stubs.h +1 -0
@@ -55,6 +55,7 @@ struct ipv6_stub { struct nl_info *info);void (*udpv6_encap_enable)(void ); +void (*udpv6_encap_disable)(void );void (*ndisc_send_na)(struct net_device *dev,const struct in6_addr *daddr,const struct in6_addr *solicited_addr,bool router,bool solicited,bool override,bool inc_opt);
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 +13 -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 -- *
@@ -218,6 +219,18 @@ static inline void udp_tunnel_encap_enable(struct sock *sk)udp_encap_enable (); } +static inline void udp_tunnel_encap_disable (struct sock *sk) +{ +if (udp_test_and_set_bit (ENCAP_ENABLED , sk)) +return ; + +#if IS_ENABLED (CONFIG_IPV6 ) +if (READ_ONCE (sk->sk_family) ==PF_INET6 ) + ipv6_stub->udpv6_encap_disable (); +#endif +udp_encap_disable (); +} +#define UDP_TUNNEL_NIC_MAX_TABLES 4enum udp_tunnel_nic_info_flags {
net/ipv4/udp_tunnel_core.c +22 -0
@@ -98,6 +98,28 @@ 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); + +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 ; + +rcu_assign_sk_user_data (sk,NULL ); +udp_tunnel_encap_disable (sk); +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/af_inet6.c +1 -0
@@ -1049,6 +1049,7 @@ static const struct ipv6_stub ipv6_stub_impl = { .fib6_rt_update = fib6_rt_update, .ip6_del_rt = ip6_del_rt, .udpv6_encap_enable = udpv6_encap_enable, + .udpv6_encap_disable = udpv6_encap_disable, .ndisc_send_na = ndisc_send_na, #if IS_ENABLED(CONFIG_XFRM) .xfrm6_local_rxpmtu = xfrm6_local_rxpmtu,
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
Antonio Quartulli
maintainerRe: [PATCH net-next 1/4] ovpn: properly deconfigure UDP-tunnel
Hi Jakub,
please refrain from pulling this series.
While stress testing the code in this patch, we realized that:
1) udp_tunnel_encap_disable() is calling the wrong bit-related function (copy/paste error);
2) cleanup_udp_tunnel_sock() can race with udp_destroy_socket() and lead to a double decrease of udp_encap_needed_key.
We have already developed and verified the fixes, which I will send with a following PR.
Should I already target 'net' (even though there is no 6.16-rc1 yet)?
Regards,
Quoted 169 lines · Antonio Quartulli
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 allowudpv6_encap_needed_keyto be decreased outside of ipv6.ko (similarly toudp_encap_disable()for IPv4).Cc Willem de Bruijn <[email protected]>Cc Simon Horman <[email protected]>Cc David Ahern <[email protected]>Cc Sabrina Dubroca <[email protected]>Cc Oleksandr Natalenko <[email protected]>Reported-by Paolo Abeni <[email protected]>Signed-off-by Antonio Quartulli <[email protected]>--- drivers/net/ovpn/udp.c | 5 +---- include/net/ipv6_stubs.h | 1 + include/net/udp.h | 1 + include/net/udp_tunnel.h | 13 +++++++++++++ net/ipv4/udp_tunnel_core.c | 22 ++++++++++++++++++++++ net/ipv6/af_inet6.c | 1 + net/ipv6/udp.c | 6 ++++++ 7 files changed, 45 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/ipv6_stubs.h +1
-0@@ -55,6 +55,7 @@ struct ipv6_stub { struct nl_info *info);void (*udpv6_encap_enable)(void ); +void (*udpv6_encap_disable)(void );void (*ndisc_send_na)(struct net_device *dev,const struct in6_addr *daddr,const struct in6_addr *solicited_addr,bool router,bool solicited,bool override,bool inc_opt);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 +13
-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 -- * @@ -218,6 +219,18 @@ static inline void udp_tunnel_encap_enable(struct sock *sk)udp_encap_enable (); } +static inline void udp_tunnel_encap_disable (struct sock *sk) +{ +if (udp_test_and_set_bit (ENCAP_ENABLED , sk)) +return ; + +#if IS_ENABLED (CONFIG_IPV6 ) +if (READ_ONCE (sk->sk_family) ==PF_INET6 ) + ipv6_stub->udpv6_encap_disable (); +#endif +udp_encap_disable (); +} +#define UDP_TUNNEL_NIC_MAX_TABLES 4enum udp_tunnel_nic_info_flags {net/ipv4/udp_tunnel_core.c +22
-0@@ -98,6 +98,28 @@ 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); + +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 ; + +rcu_assign_sk_user_data (sk,NULL ); +udp_tunnel_encap_disable (sk); +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/af_inet6.c +1
-0@@ -1049,6 +1049,7 @@ static const struct ipv6_stub ipv6_stub_impl = { .fib6_rt_update = fib6_rt_update, .ip6_del_rt = ip6_del_rt, .udpv6_encap_enable = udpv6_encap_enable, + .udpv6_encap_disable = udpv6_encap_disable, .ndisc_send_na = ndisc_send_na, #if IS_ENABLED(CONFIG_XFRM) .xfrm6_local_rxpmtu = xfrm6_local_rxpmtu,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 · 2 lines
Antonio Quartulli OpenVPN Inc.
Antonio Quartulli
maintainerPATCH 2/4 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/4 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
Antonio Quartulli
maintainerPATCH 4/4 selftest/net/ovpn: fix missing file
In reply to Antonio Quartullitest-large-mtu.sh is referenced by the Makefile
but does not exist.
Add it along the other scripts.
--- tools/testing/selftests/net/ovpn/test-large-mtu.sh | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100755 tools/testing/selftests/net/ovpn/test-large-mtu.sh
tools/testing/selftests/net/ovpn/test-large-mtu.sh new file +9 -0
@@ -0,0 +1,9 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2025 OpenVPN, Inc. +# +# Author: Antonio Quartulli <[email protected]> + +MTU="1500" + +source test.sh
Signature · 1 line
2.49.0