From: sashiko-bot@kernel.org
To: "Marc Kleine-Budde" <mkl@pengutronix.de>
Cc: linux-can@vger.kernel.org,
"Oliver Hartkopp" <socketcan@hartkopp.net>,
"Vincent Mailhol" <mailhol@kernel.org>,
"Oleksij Rempel" <o.rempel@pengutronix.de>
Subject: Re: [PATCH can-next] can: gs_usb: gs_usb_probe(): fix return value check of gs_make_candev()
Date: Tue, 01 Dec 2026 08:25:43 +0000 [thread overview]
Message-ID: <sashiko-outbox-242836@kernel.org> (raw)
In-Reply-To: <20261201-b4-gs-usb_fix-return-value-check-v1-1-693511dd12b0@pengutronix.de>
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] can: gs_usb: null pointer dereference in gs_can_open() [1]
--
commit 38a9a7eebd4d3c343441a0677697277ff22f57cd
Author: Marc Kleine-Budde <mkl@pengutronix.de>
can: gs_usb: gs_usb_probe(): fix return value check of gs_make_candev()
This commit changes gs_usb_probe() to use IS_ERR() instead of
IS_ERR_OR_NULL() when checking the return value of gs_make_candev().
> diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
> index 15f28833f2deb..d1a7c37a72a19 100644
> --- a/drivers/net/can/usb/gs_usb.c
> +++ b/drivers/net/can/usb/gs_usb.c
> @@ -1589,7 +1589,7 @@ static int gs_usb_probe(struct usb_interface *intf,
> unsigned int hf_size_rx = 0;
>
> parent->canch[i] = gs_make_candev(i, intf, &dconf);
> - if (IS_ERR_OR_NULL(parent->canch[i])) {
> + if (IS_ERR(parent->canch[i])) {
> /* save error code to return later */
> rc = PTR_ERR(parent->canch[i]);
>
[Severity: Critical]
This problem wasn't introduced by this patch, but can gs_can_open() race
with gs_usb_probe() and dereference a NULL dev->parent [1]?
gs_make_candev() calls register_candev(), which exposes the network
interface to userspace before gs_usb_probe() finishes initializing
parent->canch[i]->parent and parent->hf_size_rx:
drivers/net/can/usb/gs_usb.c:gs_usb_probe() {
...
for (i = 0; i < icount; i++) {
unsigned int hf_size_rx = 0;
parent->canch[i] = gs_make_candev(i, intf, &dconf);
if (IS_ERR(parent->canch[i])) {
...
}
parent->canch[i]->parent = parent;
...
parent->hf_size_rx = max(parent->hf_size_rx, hf_size_rx);
}
}
If userspace brings the interface up as soon as register_candev() returns,
gs_can_open() runs before those fields are populated:
CPU0 CPU1
gs_usb_probe()
gs_make_candev()
register_candev()
gs_can_open()
parent = dev->parent;
if (!parent->active_channels)
<-- NULL pointer dereference
parent->canch[i]->parent = parent;
parent->hf_size_rx = ...
If gs_can_open() instead runs after dev->parent is assigned but before
parent->hf_size_rx is computed, kmalloc(dev->parent->hf_size_rx, GFP_KERNEL)
returns ZERO_SIZE_PTR and passes it to usb_fill_bulk_urb() as the RX DMA
buffer.
[1] https://sashiko.dev/#/bug/linux-be54de7d-0b75-408c-b3ee-dd90c9756857
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-b4-gs-usb_fix-return-value-check-v1-1-693511dd12b0@pengutronix.de?part=1
prev parent reply other threads:[~2026-12-01 8:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 8:21 [PATCH can-next] can: gs_usb: gs_usb_probe(): fix return value check of gs_make_candev() Marc Kleine-Budde
2026-12-01 8:25 ` sashiko-bot [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=sashiko-outbox-242836@kernel.org \
--to=sashiko-bot@kernel.org \
--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