[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <c05d08c1-ed23-40d3-8950-d00aca49f480@openvpn.net>
Date: Wed, 4 Jun 2025 15:41:04 +0200
From: Antonio Quartulli <antonio@...nvpn.net>
To: Larysa Zaremba <larysa.zaremba@...el.com>
Cc: netdev@...r.kernel.org,
Michal Swiatkowski <michal.swiatkowski@...ux.intel.com>,
Sabrina Dubroca <sd@...asysnail.net>, "David S . Miller"
<davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
Oleksandr Natalenko <oleksandr@...alenko.name>
Subject: Re: [PATCH net 1/5] ovpn: properly deconfigure UDP-tunnel
Hello Larysa and thanks for chiming in,
On 04/06/2025 15:16, Larysa Zaremba wrote:
> On Tue, Jun 03, 2025 at 01:11:06PM +0200, Antonio Quartulli wrote:
>> When deconfiguring a UDP-tunnel from a socket, we cannot
>> call setup_udp_tunnel_sock() with an empty config, because
>> this helper is expected to be invoked only during setup.
>>
>> Get rid of the call to setup_udp_tunnel_sock() and just
>> revert what it did during socket initialization..
>>
>> Note that the global udp_encap_needed_key and the GRO state
>> are left untouched: udp_destroy_socket() will eventually
>> take care of them.
>>
>> Cc: Sabrina Dubroca <sd@...asysnail.net>
>> Cc: Oleksandr Natalenko <oleksandr@...alenko.name>
>> Fixes: ab66abbc769b ("ovpn: implement basic RX path (UDP)")
>> Reported-by: Paolo Abeni <pabeni@...hat.com>
>> Closes: https://lore.kernel.org/netdev/1a47ce02-fd42-4761-8697-f3f315011cc6@redhat.com
>> Signed-off-by: Antonio Quartulli <antonio@...nvpn.net>
>
> I do not think MC_LOOP is necessarily set before attaching the socket, but 1 is
> the default value, so I guess restoring to it should be fine.
>
> Reviewed-by: Larysa Zaremba <larysa.zaremba@...el.com>
>
> Another less related thing is more concerning to me: ovpn_udp_socket_attach()
> checks if rcu_dereference_sk_user_data(sock->sk) is NULL to determine if socket
> is available to configure, but a lot of callers of e.g. setup_udp_tunnel_sock(),
> including ovpn, set the user data to NULL by not providing it in the config.
>
> In such case, is checking rcu_dereference_sk_user_data() actually enough to say
> that "socket is currently unused"?
This is an "interesting" area of the code that required a lot of
attention during implementation...so having more eyes on it is
definitely appreciated.
In ovpn we have:
ovpn_socket_new()
lock_sock()
ovpn_socket_attach()
ovpn_udp_socket_attach()
rcu_assign_sk_user_data() << sk_user_data is assigned here
release_sock()
The lock takes care of preventing concurrent ovpn_socket_new()
invocations, with the same sk, to mess things up.
Upon socket detachment, a similar strategy is implemented to make sure
concurrent attachment/detachment are properly handled.
I hope this helps.
Regards,
>
>> ---
>> drivers/net/ovpn/udp.c | 14 +++++++++++---
>> 1 file changed, 11 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/net/ovpn/udp.c b/drivers/net/ovpn/udp.c
>> index aef8c0406ec9..f4d3bd070f11 100644
>> --- a/drivers/net/ovpn/udp.c
>> +++ b/drivers/net/ovpn/udp.c
>> @@ -442,8 +442,16 @@ 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 = { };
>> + struct sock *sk = ovpn_sock->sock->sk;
>>
>> - setup_udp_tunnel_sock(sock_net(ovpn_sock->sock->sk), ovpn_sock->sock,
>> - &cfg);
>> + /* Re-enable multicast loopback */
>> + inet_set_bit(MC_LOOP, sk);
>> + /* Disable CHECKSUM_UNNECESSARY to CHECKSUM_COMPLETE conversion */
>> + inet_dec_convert_csum(sk);
>> +
>> + WRITE_ONCE(udp_sk(sk)->encap_type, 0);
>> + WRITE_ONCE(udp_sk(sk)->encap_rcv, NULL);
>> + WRITE_ONCE(udp_sk(sk)->encap_destroy, NULL);
>> +
>> + rcu_assign_sk_user_data(sk, NULL);
>> }
>> --
>> 2.49.0
>>
>>
--
Antonio Quartulli
OpenVPN Inc.
Powered by blists - more mailing lists