From: sashiko-bot@kernel.org
To: "Guangshuo Li" <lgs201920130244@gmail.com>
Cc: linux-can@vger.kernel.org, "Vincent Mailhol" <mailhol@kernel.org>,
"Marc Kleine-Budde" <mkl@pengutronix.de>,
"Oliver Hartkopp" <socketcan@hartkopp.net>,
"Oleksij Rempel" <o.rempel@pengutronix.de>
Subject: Re: [PATCH] can: usb: etas_es58x: Fix RX buffer leak on URB resubmit failure
Date: Sat, 04 Jul 2026 17:14:32 +0000 [thread overview]
Message-ID: <20260704171433.3A1881F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260704165717.248880-1-lgs201920130244@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Race condition during device disconnect leads to a Use-After-Free of the `netdev` structure in the URB completion handler.
--
commit 60846d2bc70af068d7027f0af965d52838e69d83
Author: Guangshuo Li <lgs201920130244@gmail.com>
can: usb: etas_es58x: Fix RX buffer leak on URB resubmit failure
This commit reuses the free_urb path after an RX URB resubmit failure
in es58x_read_bulk_callback(). This prevents a memory leak of the coherent
transfer buffer when usb_submit_urb() fails.
> diff --git a/drivers/net/can/usb/etas_es58x/es58x_core.c b/drivers/net/can/usb/etas_es58x/es58x_core.c
> index b259f61098083..da12a35dd2f9a 100644
> --- a/drivers/net/can/usb/etas_es58x/es58x_core.c
> +++ b/drivers/net/can/usb/etas_es58x/es58x_core.c
> @@ -1476,7 +1476,7 @@ static void es58x_read_bulk_callback(struct urb *urb)
> dev_err_ratelimited(dev,
> "Failed resubmitting read bulk urb: %pe\n",
> ERR_PTR(ret));
> - return;
> + goto free_urb;
[Severity: High]
This is a pre-existing issue, but does a race condition exist during device
disconnect that leads to a use-after-free of the netdev structure?
If a dual-channel ES58x device is abruptly disconnected, es58x_disconnect()
calls es58x_free_netdevs() to iteratively free the channels. When it
unregisters the first channel, opened_channel_cnt drops to 1, so
es58x_free_urbs() is not called yet, and URBs continue running concurrently.
Meanwhile, es58x_free_netdevs() frees the first channel's netdev:
drivers/net/can/usb/etas_es58x/es58x_core.c:es58x_free_netdevs() {
...
es58x_dev->netdev[i] = NULL;
free_candev(netdev);
...
}
If a concurrent es58x_read_bulk_callback() fails to resubmit its URB
and receives -ENODEV due to the disconnect, it iterates over all channels
just above this diff hunk:
drivers/net/can/usb/etas_es58x/es58x_core.c:es58x_read_bulk_callback() {
...
if (ret == -ENODEV) {
for (i = 0; i < es58x_dev->num_can_ch; i++)
if (es58x_dev->netdev[i])
netif_device_detach(es58x_dev->netdev[i]);
...
}
Could the callback read the netdev pointer before it is set to NULL, but
execute netif_device_detach() on it after free_candev() has already freed it?
>
> free_urb:
> usb_free_coherent(urb->dev, urb->transfer_buffer_length,
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260704165717.248880-1-lgs201920130244@gmail.com?part=1
next prev parent reply other threads:[~2026-07-04 17:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-04 16:57 [PATCH] can: usb: etas_es58x: Fix RX buffer leak on URB resubmit failure Guangshuo Li
2026-07-04 17:14 ` sashiko-bot [this message]
2026-07-05 8:38 ` Vincent Mailhol
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=20260704171433.3A1881F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=lgs201920130244@gmail.com \
--cc=linux-can@vger.kernel.org \
--cc=mailhol@kernel.org \
--cc=mkl@pengutronix.de \
--cc=o.rempel@pengutronix.de \
--cc=sashiko-reviews@lists.linux.dev \
--cc=socketcan@hartkopp.net \
/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