From: Shuah Khan <skhan@linuxfoundation.org>
To: raoxu <raoxu@uniontech.com>, valentina.manea.m@gmail.com
Cc: shuah@kernel.org, i@zenithal.me, luiz.von.dentz@intel.com,
pengpeng@iscas.ac.cn, brgl@kernel.org, pmenzel@molgen.mpg.de,
gregkh@linuxfoundation.org, ihadzic@research.bell-labs.com,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH] usbip: Close all listening sockets in request workers
Date: Thu, 12 Nov 2026 09:12:01 -0700 [thread overview]
Message-ID: <67b2c06e-0caa-4ba1-89ee-17cb814d173c@linuxfoundation.org> (raw)
In-Reply-To: <E063498E65C71B8D+20261112121648.1458957-1-raoxu@uniontech.com>
On 11/12/26 05:16, raoxu wrote:
> From: Xu Rao <raoxu@uniontech.com>
>
> process_request() forks a worker after accepting a connection, but the
> child only closes the listener used for that connection. All other
> listening sockets are inherited and remain open until the worker exits.
> This occurs when usbipd listens on multiple addresses, including the
> default IPv4 and IPv6 setup.
>
> A worker waiting for a client request can therefore keep an unrelated
> listener alive after the main daemon exits. Restarting usbipd then fails
> to bind that address with EADDRINUSE, or starts with only the addresses
> that are still available. A single-listener configuration is unaffected.
>
> Pass the complete listening socket array and its count to
> process_request(), and close every listener in the child before handling
> the request. The accepted connection remains open, and the parent's
> descriptors are unaffected. Make process_request() static as its only
> caller is in the same file.
Looks reasonable to me. How did you find the problem? Can you share
how to reproduce this problem?
>
> Fixes: 328f7f8a0a1c ("staging: usbip: userspace: eliminate glib dependency")
> Cc: stable@vger.kernel.org
> Signed-off-by: Xu Rao <raoxu@uniontech.com>
> ---
> tools/usb/usbip/src/usbipd.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/tools/usb/usbip/src/usbipd.c b/tools/usb/usbip/src/usbipd.c
> index 3e22b651c754..5ff5b46674a2 100644
> --- a/tools/usb/usbip/src/usbipd.c
> +++ b/tools/usb/usbip/src/usbipd.c
> @@ -339,17 +339,20 @@ static int do_accept(int listenfd)
> return connfd;
> }
>
> -int process_request(int listenfd)
> +static int process_request(int listenfd, const int *listenfds, int nlistenfds)
> {
> pid_t childpid;
> int connfd;
> + int i;
>
> connfd = do_accept(listenfd);
> if (connfd < 0)
> return -1;
> childpid = fork();
> if (childpid == 0) {
> - close(listenfd);
> + /* Do not keep unrelated listening sockets alive in workers. */
> + for (i = 0; i < nlistenfds; i++)
> + close(listenfds[i]);
> recv_pdu(connfd);
> exit(0);
> }
> @@ -568,7 +571,8 @@ static int do_standalone_mode(int daemonize, int ipv4, int ipv6)
> if (fds[i].revents & POLLIN) {
> dbg("read event on fd[%d]=%d",
> i, sockfdlist[i]);
> - process_request(sockfdlist[i]);
> + process_request(sockfdlist[i], sockfdlist,
> + nsockfd);
> }
> }
> } else {
> --
> 2.50.1
>
thanks,
-- Shuah
prev parent reply other threads:[~2026-11-12 16:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 12:16 raoxu
2026-11-12 16:12 ` Shuah Khan [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=67b2c06e-0caa-4ba1-89ee-17cb814d173c@linuxfoundation.org \
--to=skhan@linuxfoundation.org \
--cc=brgl@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=i@zenithal.me \
--cc=ihadzic@research.bell-labs.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=luiz.von.dentz@intel.com \
--cc=pengpeng@iscas.ac.cn \
--cc=pmenzel@molgen.mpg.de \
--cc=raoxu@uniontech.com \
--cc=shuah@kernel.org \
--cc=stable@vger.kernel.org \
--cc=valentina.manea.m@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®