A UDP socket may retain a detachable tunnel GRO callback while it
remains visible to userspace. If userspace subsequently changes
UDP_ENCAP, replacing the encapsulation callbacks without first retiring
GRO leaves the old callback lifetime and frag-list acceptance state
active.

Validate the requested encapsulation type, then detach such a GRO
callback before installing the new encapsulation implementation.
Existing sockets are unaffected because no current user enables
detachable GRO callbacks.

UDP_ENCAP already permits userspace to change the encapsulation type of
a live socket even when driver state remains attached to it. Resolving
that pre-existing ownership issue is outside the scope of this change.
This only keeps detachable GRO state and callback lifetimes consistent
when the existing transition occurs; it does not make cross-encapsulator
ownership handoff supported.

Signed-off-by: Ralf Lici <[email protected]>
---
No changes since v1 
https://lore.kernel.org/openvpn-devel/99b9cccf9845899bc36e92165d9443499fe8a284.1794314969.git.r...@mandelbit.com/

 net/ipv4/udp.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index d62452c0f663..2d16a220c42d 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -3019,6 +3019,9 @@ int udp_lib_setsockopt(struct sock *sk, int level, int 
optname,
                case 0:
 #ifdef CONFIG_XFRM
                case UDP_ENCAP_ESPINUDP:
+                       if (udp_test_bit(GRO_RCV_DETACHABLE, sk))
+                               udp_tunnel_detach_gro(sk);
+
                        set_xfrm_gro_udp_encap_rcv(val, sk->sk_family, sk);
 #if IS_ENABLED(CONFIG_IPV6)
                        if (sk->sk_family == AF_INET6)
@@ -3031,6 +3034,9 @@ int udp_lib_setsockopt(struct sock *sk, int level, int 
optname,
 #endif
                        fallthrough;
                case UDP_ENCAP_L2TPINUDP:
+                       if (udp_test_bit(GRO_RCV_DETACHABLE, sk))
+                               udp_tunnel_detach_gro(sk);
+
                        WRITE_ONCE(up->encap_type, val);
                        udp_tunnel_encap_enable(sk);
                        break;
-- 
2.56.0



_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to