* [PATCH can-next] can: gs_usb: gs_usb_probe(): fix return value check of gs_make_candev()
@ 2026-12-01 8:21 Marc Kleine-Budde
2026-12-01 8:25 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Marc Kleine-Budde @ 2026-12-01 8:21 UTC (permalink / raw)
To: Vincent Mailhol, Maximilian Schneider, Wolfgang Grandegger
Cc: kernel, linux-can, kernel test robot, Dan Carpenter,
Marc Kleine-Budde
As gs_make_candev() never returns a NULL pointer, don't use
IS_ERR_OR_NULL(), but IS_ERR() to check it's return value.
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <error27@gmail.com>
Closes: https://lore.kernel.org/r/20261130164854.GxDvgW5x-lkp@intel.com/
Fixes: d08e973a77d1 ("can: gs_usb: Added support for the GS_USB CAN devices")
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/usb/gs_usb.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
index 15f28833f2de..d1a7c37a72a1 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]);
---
base-commit: d7f7fac1c3220a430559c6d43904e27917ae1eb0
base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git main
change-id: 20261201-b4-gs-usb_fix-return-value-check-1fee569e9487
Best regards,
--
Marc Kleine-Budde <mkl@pengutronix.de>
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH can-next] can: gs_usb: gs_usb_probe(): fix return value check of gs_make_candev()
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
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-01 8:25 UTC (permalink / raw)
To: Marc Kleine-Budde
Cc: linux-can, Oliver Hartkopp, Vincent Mailhol, Oleksij Rempel
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-01 8:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox