From: Shuah Khan <skhan@linuxfoundation.org>
To: longlong yan <yanlonglong@kylinos.cn>,
valentina.manea.m@gmail.com, shuah@kernel.org,
gregkh@linuxfoundation.org
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH] usbip: add NULL check for calloc in do_standalone_mode
Date: Tue, 22 Sep 2026 04:07:28 -0600 [thread overview]
Message-ID: <2f14b623-7490-48e5-a509-d605a04930d1@linuxfoundation.org> (raw)
In-Reply-To: <20260817061514.765-1-yanlonglong@kylinos.cn>
On 8/17/26 00:15, longlong yan wrote:
> Add a NULL check for the return value of calloc() in
> do_standalone_mode(). If calloc() fails and returns NULL, the
> subsequent access to fds[i].fd would cause a NULL pointer
> dereference.
>
> Signed-off-by: longlong yan <yanlonglong@kylinos.cn>
> ---
> tools/usb/usbip/src/usbipd.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/tools/usb/usbip/src/usbipd.c b/tools/usb/usbip/src/usbipd.c
> index 3e22b651c754..dbc2b48363b2 100644
> --- a/tools/usb/usbip/src/usbipd.c
> +++ b/tools/usb/usbip/src/usbipd.c
> @@ -544,6 +544,11 @@ static int do_standalone_mode(int daemonize, int ipv4, int ipv6)
> dbg("listening on %d address%s", nsockfd, (nsockfd == 1) ? "" : "es");
>
> fds = calloc(nsockfd, sizeof(struct pollfd));
> + if (!fds) {
> + err("calloc for pollfd");
> + usbip_driver_close(driver);
> + return -1;
> + }
> for (i = 0; i < nsockfd; i++) {
> fds[i].fd = sockfdlist[i];
> fds[i].events = POLLIN;
It is theoretically possible for calloc() to fail, however how often
does it fail and were you able to make this allocation to fail?
If not, how did you test this patch? In any case, I am not going to
take this patch and all the other patches you sent adding checks to
calloc() calls in other places in usbip tool.
thanks,
-- Shuah
prev parent reply other threads:[~2026-09-22 10:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-17 6:15 longlong yan
2026-09-22 10:07 ` 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=2f14b623-7490-48e5-a509-d605a04930d1@linuxfoundation.org \
--to=skhan@linuxfoundation.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=valentina.manea.m@gmail.com \
--cc=yanlonglong@kylinos.cn \
/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®