[PATCH 0/2] Fix some redundant and incorrect initialisation of UDP sockets
This fixes bug 79 and makes another clean up in the same area. Link: https://bugs.passt.top/show_bug.cgi?id=79 David Gibson (2): udp: Don't prematurely (and incorrectly) set up automatic inbound forwards udp: udp_sock_init_ns() partially duplicats udp_port_rebind_outbound() udp.c | 90 +++++++++++++++++------------------------------------------ 1 file changed, 25 insertions(+), 65 deletions(-) -- 2.43.0
For automated inbound port forwarding in pasta mode we scan bound ports
within the guest namespace via /proc and bind matching ports on the host to
listen for packets. For UDP this is usually handled by udp_timer() which
calls port_fwd_scan_udp() followed by udp_port_rebind(). However there's
one initial scan before the the UDP timer is started: we call
port_fwd_scan_udp() from port_fwd_init(), and actually bind the resulting
ports in udp_sock_init_init() called from udp_init().
Unfortunately, the version in udp_sock_init_init() isn't correct. It
unconditionally opens a new socket for every forwarded port, even if a
socket has already been explicit created with the -u option. If the
explicitly forwarded ports have particular configuration (such as a
specific bound address address, or one implied by the -o option) those will
not be replicated in the new socket. We essentially leak the original
correctly configured socket, replacing it with one which might not be
right.
We could make udp_sock_init_init() use udp_port_rebind() to get that right,
but there's actually no point doing so:
* The initial bind was introduced by ccf6d2a7b48d ("udp: Actually bind
detected namespace ports in init namespace") at which time we didn't
periodically scan for bound UDP ports. Periodic scanning was introduced
in 457ff122e ("udp,pasta: Periodically scan for ports to automatically
forward") making the bind from udp_init() redundant.
* At the time of udp_init(), programs in the guest namespace are likely
not to have started yet (unless attaching a pre-existing namespace) so
there's likely not anything to scan for anyway.
So, simply remove the initial, broken socket create/bind, allowing
automatic port forwards to be created the first time udp_timer() runs.
Reported-by: Laurent Jacquot
Usually automatically forwarded UDP outbound ports are set up by
udp_port_rebind_outbound() called from udp_timer(). However, the very
first time they're created and bound is by udp_sock_init_ns() called from
udp_init(). udp_sock_init_ns() is essentially an unnecessary cut down
version of udp_port_rebind_outbound(), so we can jusat remove it.
Doing so does require moving udp_init() below udp_port_rebind_outbound()'s
definition.
Signed-off-by: David Gibson
On Mon, 12 Feb 2024 17:06:56 +1100
David Gibson
This fixes bug 79 and makes another clean up in the same area.
Link: https://bugs.passt.top/show_bug.cgi?id=79
David Gibson (2): udp: Don't prematurely (and incorrectly) set up automatic inbound forwards udp: udp_sock_init_ns() partially duplicats udp_port_rebind_outbound()
udp.c | 90 +++++++++++++++++------------------------------------------ 1 file changed, 25 insertions(+), 65 deletions(-)
Applied. -- Stefano
participants (2)
-
David Gibson
-
Stefano Brivio