Re: [PATCH] usbip: Close all listening sockets in request workers

From: raoxu

Date: Fri Nov 13 2026 - 01:09:56 EST


Hi Shuah,

Thanks for the review.

I found this while reviewing the listening socket handling across fork() in
usbipd.c, and then reproduced the issue with the unmodified usbipd binary on
two UOS test machines.

Both machines have usbip 2.0+6.5.10-2 installed, with usbipd located at
/usr/sbin/usbipd. This package contains the original listener handling.

I used separate test ports to avoid interfering with the default USB/IP
service.

On 10.20.12.188, the reproduction steps were:

1. Start usbipd as root with both IPv4 and IPv6 listeners:

sudo /usr/sbin/usbipd -d -4 -6 -t 43241

2. From a client machine, establish an IPv4 TCP connection and keep it open
without sending a USB/IP request:

python3 -c 'import socket,time; s=socket.create_connection(("10.20.12.188",43241)); time.sleep(300)'

3. Terminate only the main usbipd process with SIGTERM, leaving the worker
running.

4. Inspect the listening sockets:

ss -lntp 'sport = :43241'

5. Restart usbipd on the same port.

Before the connection, usbipd had two listeners:

0.0.0.0:43241 -> parent PID 62216, fd 3
[::]:43241 -> parent PID 62216, fd 4

After accepting the IPv4 connection, the forked worker inherited the IPv6
listener:

[::]:43241 -> parent PID 62216, fd 4
worker PID 62223, fd 4

After terminating the parent, the worker continued holding that listener:

[::]:43241 -> worker PID 62223, fd 4

Restarting usbipd then produced:

usbipd: info: listening on 0.0.0.0:43241
usbipd: error: bind: :::43241: 98 (Address already in use)
usbipd: debug: listening on 1 address

The restarted daemon therefore had only the IPv4 listener available.

I reproduced the same behavior independently on 10.20.12.199 using port
43242:

usbipd: info: listening on 0.0.0.0:43242
usbipd: error: bind: :::43242: 98 (Address already in use)
usbipd: debug: listening on 1 address

This confirms that the worker inherits the unrelated IPv6 listening socket
and keeps it alive after the parent daemon exits.

I also used a separate TCP socket/fork reproducer to compare the original and
patched process_request() logic. The original implementation left the
unrelated listening socket open in the worker, causing the rebind to fail
with EADDRINUSE. With the patched logic, the listener could be rebound while
the worker was still alive. The accepted connection remained usable and the
parent's descriptors were unchanged.

The affected usbipd source also builds successfully with:

make -C tools/usb/usbip/src usbipd

These tests confirm the inherited listening socket issue and support closing
all listening sockets in the child after fork().

Thanks,
Xu