public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net 0/12] pull-request: can 2026-03-02
@ 2026-03-02 15:16 Marc Kleine-Budde
  2026-03-02 15:16 ` [PATCH net 01/12] can: bcm: fix locking for bcm_op runtime updates Marc Kleine-Budde
                   ` (11 more replies)
  0 siblings, 12 replies; 18+ messages in thread
From: Marc Kleine-Budde @ 2026-03-02 15:16 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel

Hello netdev-team,

this is a pull request of 12 patches for net/main.

The first 2 patches are by Oliver Hartkopp. The first fixes the
locking for CAN Broadcast Manager op runtime updates, the second fixes
the packet statisctics for the CAN dummy driver.

Alban Bedel's patch fixes a potential problem in the error path of the
mcp251x's ndo_open callback.

A patch by Ziyi Guo add USB endpoint type validation to the esd_usb
driver.

The next 6 patches are by Greg Kroah-Hartman and fix URB data parsing
for the ems_usb and ucan driver, fix URB anchoring in the etas_es58x,
and in the f81604 driver fix URB data parsing, add URB error handling
and fix URB anchoring.

A patch by me targets the gs_usb driver and fixes interoperability
with the CANable-2.5 firmware by always configuring the bit rate
before starting the device.

The last patch is by Frank Li and fixes a CHECK_DTBS warning for the
nxp,sja1000 dt-binding.

regards,
Marc

---

The following changes since commit 9439a661c2e80485406ce2c90b107ca17858382d:

  amd-xgbe: fix MAC_TCR_SS register width for 2.5G and 10M speeds (2026-02-28 14:22:34 -0800)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can.git tags/linux-can-fixes-for-7.0-20260302

for you to fetch changes up to 7e1e6d6845329adb2da75110a061557e9c26d9b7:

  dt-bindings: net: can: nxp,sja1000: add reference to mc-peripheral-props.yaml (2026-03-02 11:23:40 +0100)

----------------------------------------------------------------
linux-can-fixes-for-7.0-20260302

----------------------------------------------------------------
Alban Bedel (1):
      can: mcp251x: fix deadlock in error path of mcp251x_open

Frank Li (1):
      dt-bindings: net: can: nxp,sja1000: add reference to mc-peripheral-props.yaml

Greg Kroah-Hartman (6):
      can: ems_usb: ems_usb_read_bulk_callback(): check the proper length of a message
      can: ucan: Fix infinite loop from zero-length messages
      can: usb: etas_es58x: correctly anchor the urb in the read bulk callback
      can: usb: f81604: handle short interrupt urb messages properly
      can: usb: f81604: handle bulk write errors properly
      can: usb: f81604: correctly anchor the urb in the read bulk callback

Marc Kleine-Budde (2):
      Merge patch series "can: usb: f81604: handle short interrupt urb messages properly"
      can: gs_usb: gs_can_open(): always configure bitrates before starting device

Oliver Hartkopp (2):
      can: bcm: fix locking for bcm_op runtime updates
      can: dummy_can: dummy_can_init(): fix packet statistics

Ziyi Guo (1):
      can: esd_usb: add endpoint type validation

 .../devicetree/bindings/net/can/nxp,sja1000.yaml   |  1 +
 drivers/net/can/dummy_can.c                        |  1 +
 drivers/net/can/spi/mcp251x.c                      | 15 +++++++-
 drivers/net/can/usb/ems_usb.c                      |  7 +++-
 drivers/net/can/usb/esd_usb.c                      | 30 ++++++++-------
 drivers/net/can/usb/etas_es58x/es58x_core.c        |  8 +++-
 drivers/net/can/usb/f81604.c                       | 45 +++++++++++++++++++---
 drivers/net/can/usb/gs_usb.c                       | 22 ++++++++---
 drivers/net/can/usb/ucan.c                         |  2 +-
 net/can/bcm.c                                      |  1 +
 10 files changed, 104 insertions(+), 28 deletions(-)

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH net 01/12] can: bcm: fix locking for bcm_op runtime updates
  2026-03-02 15:16 [PATCH net 0/12] pull-request: can 2026-03-02 Marc Kleine-Budde
@ 2026-03-02 15:16 ` Marc Kleine-Budde
  2026-03-05  1:00   ` patchwork-bot+netdevbpf
  2026-03-02 15:16 ` [PATCH net 02/12] can: dummy_can: dummy_can_init(): fix packet statistics Marc Kleine-Budde
                   ` (10 subsequent siblings)
  11 siblings, 1 reply; 18+ messages in thread
From: Marc Kleine-Budde @ 2026-03-02 15:16 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Oliver Hartkopp,
	syzbot+5b11eccc403dd1cea9f8, Marc Kleine-Budde

From: Oliver Hartkopp <socketcan@hartkopp.net>

Commit c2aba69d0c36 ("can: bcm: add locking for bcm_op runtime updates")
added a locking for some variables that can be modified at runtime when
updating the sending bcm_op with a new TX_SETUP command in bcm_tx_setup().

Usually the RX_SETUP only handles and filters incoming traffic with one
exception: When the RX_RTR_FRAME flag is set a predefined CAN frame is
sent when a specific RTR frame is received. Therefore the rx bcm_op uses
bcm_can_tx() which uses the bcm_tx_lock that was only initialized in
bcm_tx_setup(). Add the missing spin_lock_init() when allocating the
bcm_op in bcm_rx_setup() to handle the RTR case properly.

Fixes: c2aba69d0c36 ("can: bcm: add locking for bcm_op runtime updates")
Reported-by: syzbot+5b11eccc403dd1cea9f8@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/linux-can/699466e4.a70a0220.2c38d7.00ff.GAE@google.com/
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://patch.msgid.link/20260218-bcm_spin_lock_init-v1-1-592634c8a5b5@hartkopp.net
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 net/can/bcm.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/can/bcm.c b/net/can/bcm.c
index b7324e9c955b..fd9fa072881e 100644
--- a/net/can/bcm.c
+++ b/net/can/bcm.c
@@ -1176,6 +1176,7 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
 		if (!op)
 			return -ENOMEM;
 
+		spin_lock_init(&op->bcm_tx_lock);
 		op->can_id = msg_head->can_id;
 		op->nframes = msg_head->nframes;
 		op->cfsiz = CFSIZ(msg_head->flags);

base-commit: 9439a661c2e80485406ce2c90b107ca17858382d
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH net 02/12] can: dummy_can: dummy_can_init(): fix packet statistics
  2026-03-02 15:16 [PATCH net 0/12] pull-request: can 2026-03-02 Marc Kleine-Budde
  2026-03-02 15:16 ` [PATCH net 01/12] can: bcm: fix locking for bcm_op runtime updates Marc Kleine-Budde
@ 2026-03-02 15:16 ` Marc Kleine-Budde
  2026-03-02 15:16 ` [PATCH net 03/12] can: mcp251x: fix deadlock in error path of mcp251x_open Marc Kleine-Budde
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 18+ messages in thread
From: Marc Kleine-Budde @ 2026-03-02 15:16 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Oliver Hartkopp, Vincent Mailhol,
	Marc Kleine-Budde

From: Oliver Hartkopp <socketcan@hartkopp.net>

The former implementation was only counting the tx_packets value but not
the tx_bytes as the skb was dropped on driver layer.

Enable CAN echo support (IFF_ECHO) in dummy_can_init(), which activates the
code for setting and retrieving the echo SKB and counts the tx_bytes
correctly.

Fixes: 816cf430e84b ("can: add dummy_can driver")
Cc: Vincent Mailhol <mailhol@kernel.org>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Reviewed-by: Vincent Mailhol <mailhol@kernel.org>
Link: https://patch.msgid.link/20260126104540.21024-1-socketcan@hartkopp.net
[mkl: make commit message imperative]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/dummy_can.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/can/dummy_can.c b/drivers/net/can/dummy_can.c
index 41953655e3d3..cd23de488edc 100644
--- a/drivers/net/can/dummy_can.c
+++ b/drivers/net/can/dummy_can.c
@@ -241,6 +241,7 @@ static int __init dummy_can_init(void)
 
 	dev->netdev_ops = &dummy_can_netdev_ops;
 	dev->ethtool_ops = &dummy_can_ethtool_ops;
+	dev->flags |= IFF_ECHO; /* enable echo handling */
 	priv = netdev_priv(dev);
 	priv->can.bittiming_const = &dummy_can_bittiming_const;
 	priv->can.bitrate_max = 20 * MEGA /* BPS */;
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH net 03/12] can: mcp251x: fix deadlock in error path of mcp251x_open
  2026-03-02 15:16 [PATCH net 0/12] pull-request: can 2026-03-02 Marc Kleine-Budde
  2026-03-02 15:16 ` [PATCH net 01/12] can: bcm: fix locking for bcm_op runtime updates Marc Kleine-Budde
  2026-03-02 15:16 ` [PATCH net 02/12] can: dummy_can: dummy_can_init(): fix packet statistics Marc Kleine-Budde
@ 2026-03-02 15:16 ` Marc Kleine-Budde
  2026-03-02 15:16 ` [PATCH net 04/12] can: esd_usb: add endpoint type validation Marc Kleine-Budde
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 18+ messages in thread
From: Marc Kleine-Budde @ 2026-03-02 15:16 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel, Alban Bedel, Marc Kleine-Budde

From: Alban Bedel <alban.bedel@lht.dlh.de>

The mcp251x_open() function call free_irq() in its error path with the
mpc_lock mutex held. But if an interrupt already occurred the
interrupt handler will be waiting for the mpc_lock and free_irq() will
deadlock waiting for the handler to finish.

This issue is similar to the one fixed in commit 7dd9c26bd6cf ("can:
mcp251x: fix deadlock if an interrupt occurs during mcp251x_open") but
for the error path.

To solve this issue move the call to free_irq() after the lock is
released. Setting `priv->force_quit = 1` beforehand ensure that the IRQ
handler will exit right away once it acquired the lock.

Signed-off-by: Alban Bedel <alban.bedel@lht.dlh.de>
Link: https://patch.msgid.link/20260209144706.2261954-1-alban.bedel@lht.dlh.de
Fixes: bf66f3736a94 ("can: mcp251x: Move to threaded interrupts instead of workqueues.")
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/spi/mcp251x.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/spi/mcp251x.c b/drivers/net/can/spi/mcp251x.c
index fa97adf25b73..bb7782582f40 100644
--- a/drivers/net/can/spi/mcp251x.c
+++ b/drivers/net/can/spi/mcp251x.c
@@ -1214,6 +1214,7 @@ static int mcp251x_open(struct net_device *net)
 {
 	struct mcp251x_priv *priv = netdev_priv(net);
 	struct spi_device *spi = priv->spi;
+	bool release_irq = false;
 	unsigned long flags = 0;
 	int ret;
 
@@ -1257,12 +1258,24 @@ static int mcp251x_open(struct net_device *net)
 	return 0;
 
 out_free_irq:
-	free_irq(spi->irq, priv);
+	/* The IRQ handler might be running, and if so it will be waiting
+	 * for the lock. But free_irq() must wait for the handler to finish
+	 * so calling it here would deadlock.
+	 *
+	 * Setting priv->force_quit will let the handler exit right away
+	 * without any access to the hardware. This make it safe to call
+	 * free_irq() after the lock is released.
+	 */
+	priv->force_quit = 1;
+	release_irq = true;
+
 	mcp251x_hw_sleep(spi);
 out_close:
 	mcp251x_power_enable(priv->transceiver, 0);
 	close_candev(net);
 	mutex_unlock(&priv->mcp_lock);
+	if (release_irq)
+		free_irq(spi->irq, priv);
 	return ret;
 }
 
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH net 04/12] can: esd_usb: add endpoint type validation
  2026-03-02 15:16 [PATCH net 0/12] pull-request: can 2026-03-02 Marc Kleine-Budde
                   ` (2 preceding siblings ...)
  2026-03-02 15:16 ` [PATCH net 03/12] can: mcp251x: fix deadlock in error path of mcp251x_open Marc Kleine-Budde
@ 2026-03-02 15:16 ` Marc Kleine-Budde
  2026-03-02 15:16 ` [PATCH net 05/12] can: ems_usb: ems_usb_read_bulk_callback(): check the proper length of a message Marc Kleine-Budde
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 18+ messages in thread
From: Marc Kleine-Budde @ 2026-03-02 15:16 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Ziyi Guo, Vincent Mailhol,
	Marc Kleine-Budde

From: Ziyi Guo <n7l8m4@u.northwestern.edu>

esd_usb_probe() constructs bulk pipes for two endpoints without
verifying their transfer types:

  - usb_rcvbulkpipe(dev->udev, 1) for RX (version reply, async RX data)
  - usb_sndbulkpipe(dev->udev, 2) for TX (version query, CAN frames)

A malformed USB device can present these endpoints with transfer types
that differ from what the driver assumes, triggering the WARNING in
usb_submit_urb().

Use usb_find_common_endpoints() to discover and validate the first
bulk IN and bulk OUT endpoints at probe time, before any allocation.
Found pipes are saved to struct esd_usb and code uses them directly
instead of making pipes in place.

Similar to
- commit 136bed0bfd3b ("can: mcba_usb: properly check endpoint type")
  which established the usb_find_common_endpoints() + stored pipes
  pattern for CAN USB drivers.

Fixes: 96d8e90382dc ("can: Add driver for esd CAN-USB/2 device")
Suggested-by: Vincent Mailhol <mailhol@kernel.org>
Signed-off-by: Ziyi Guo <n7l8m4@u.northwestern.edu>
Reviewed-by: Vincent Mailhol <mailhol@kernel.org>
Link: https://patch.msgid.link/20260213203927.599163-1-n7l8m4@u.northwestern.edu
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/esd_usb.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/drivers/net/can/usb/esd_usb.c b/drivers/net/can/usb/esd_usb.c
index 2892a68f510a..d257440fa01f 100644
--- a/drivers/net/can/usb/esd_usb.c
+++ b/drivers/net/can/usb/esd_usb.c
@@ -272,6 +272,9 @@ struct esd_usb {
 
 	struct usb_anchor rx_submitted;
 
+	unsigned int rx_pipe;
+	unsigned int tx_pipe;
+
 	int net_count;
 	u32 version;
 	int rxinitdone;
@@ -537,7 +540,7 @@ static void esd_usb_read_bulk_callback(struct urb *urb)
 	}
 
 resubmit_urb:
-	usb_fill_bulk_urb(urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
+	usb_fill_bulk_urb(urb, dev->udev, dev->rx_pipe,
 			  urb->transfer_buffer, ESD_USB_RX_BUFFER_SIZE,
 			  esd_usb_read_bulk_callback, dev);
 
@@ -626,9 +629,7 @@ static int esd_usb_send_msg(struct esd_usb *dev, union esd_usb_msg *msg)
 {
 	int actual_length;
 
-	return usb_bulk_msg(dev->udev,
-			    usb_sndbulkpipe(dev->udev, 2),
-			    msg,
+	return usb_bulk_msg(dev->udev, dev->tx_pipe, msg,
 			    msg->hdr.len * sizeof(u32), /* convert to # of bytes */
 			    &actual_length,
 			    1000);
@@ -639,12 +640,8 @@ static int esd_usb_wait_msg(struct esd_usb *dev,
 {
 	int actual_length;
 
-	return usb_bulk_msg(dev->udev,
-			    usb_rcvbulkpipe(dev->udev, 1),
-			    msg,
-			    sizeof(*msg),
-			    &actual_length,
-			    1000);
+	return usb_bulk_msg(dev->udev, dev->rx_pipe, msg,
+			    sizeof(*msg), &actual_length, 1000);
 }
 
 static int esd_usb_setup_rx_urbs(struct esd_usb *dev)
@@ -677,8 +674,7 @@ static int esd_usb_setup_rx_urbs(struct esd_usb *dev)
 
 		urb->transfer_dma = buf_dma;
 
-		usb_fill_bulk_urb(urb, dev->udev,
-				  usb_rcvbulkpipe(dev->udev, 1),
+		usb_fill_bulk_urb(urb, dev->udev, dev->rx_pipe,
 				  buf, ESD_USB_RX_BUFFER_SIZE,
 				  esd_usb_read_bulk_callback, dev);
 		urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
@@ -903,7 +899,7 @@ static netdev_tx_t esd_usb_start_xmit(struct sk_buff *skb,
 	/* hnd must not be 0 - MSB is stripped in txdone handling */
 	msg->tx.hnd = BIT(31) | i; /* returned in TX done message */
 
-	usb_fill_bulk_urb(urb, dev->udev, usb_sndbulkpipe(dev->udev, 2), buf,
+	usb_fill_bulk_urb(urb, dev->udev, dev->tx_pipe, buf,
 			  msg->hdr.len * sizeof(u32), /* convert to # of bytes */
 			  esd_usb_write_bulk_callback, context);
 
@@ -1298,10 +1294,16 @@ static int esd_usb_probe_one_net(struct usb_interface *intf, int index)
 static int esd_usb_probe(struct usb_interface *intf,
 			 const struct usb_device_id *id)
 {
+	struct usb_endpoint_descriptor *ep_in, *ep_out;
 	struct esd_usb *dev;
 	union esd_usb_msg *msg;
 	int i, err;
 
+	err = usb_find_common_endpoints(intf->cur_altsetting, &ep_in, &ep_out,
+					NULL, NULL);
+	if (err)
+		return err;
+
 	dev = kzalloc_obj(*dev);
 	if (!dev) {
 		err = -ENOMEM;
@@ -1309,6 +1311,8 @@ static int esd_usb_probe(struct usb_interface *intf,
 	}
 
 	dev->udev = interface_to_usbdev(intf);
+	dev->rx_pipe = usb_rcvbulkpipe(dev->udev, ep_in->bEndpointAddress);
+	dev->tx_pipe = usb_sndbulkpipe(dev->udev, ep_out->bEndpointAddress);
 
 	init_usb_anchor(&dev->rx_submitted);
 
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH net 05/12] can: ems_usb: ems_usb_read_bulk_callback(): check the proper length of a message
  2026-03-02 15:16 [PATCH net 0/12] pull-request: can 2026-03-02 Marc Kleine-Budde
                   ` (3 preceding siblings ...)
  2026-03-02 15:16 ` [PATCH net 04/12] can: esd_usb: add endpoint type validation Marc Kleine-Budde
@ 2026-03-02 15:16 ` Marc Kleine-Budde
  2026-03-03 14:20   ` Paolo Abeni
  2026-03-02 15:16 ` [PATCH net 06/12] can: ucan: Fix infinite loop from zero-length messages Marc Kleine-Budde
                   ` (6 subsequent siblings)
  11 siblings, 1 reply; 18+ messages in thread
From: Marc Kleine-Budde @ 2026-03-02 15:16 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Greg Kroah-Hartman,
	Vincent Mailhol, Marc Kleine-Budde, stable

From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

When looking at the data in a USB urb, the actual_length is the size of
the buffer passed to the driver, not the transfer_buffer_length which is
set by the driver as the max size of the buffer.

When parsing the messages in ems_usb_read_bulk_callback() properly check
the size both at the beginning of parsing the message to make sure it is
big enough for the expected structure, and at the end of the message to
make sure we don't overflow past the end of the buffer for the next
message.

Cc: Vincent Mailhol <mailhol@kernel.org>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: stable@kernel.org
Assisted-by: gkh_clanker_2000
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://patch.msgid.link/2026022316-answering-strainer-a5db@gregkh
Fixes: 702171adeed3 ("ems_usb: Added support for EMS CPC-USB/ARM7 CAN/USB interface")
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/ems_usb.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c
index 4c219a5b139b..9b25dda7c183 100644
--- a/drivers/net/can/usb/ems_usb.c
+++ b/drivers/net/can/usb/ems_usb.c
@@ -445,6 +445,11 @@ static void ems_usb_read_bulk_callback(struct urb *urb)
 		start = CPC_HEADER_SIZE;
 
 		while (msg_count) {
+			if (start + CPC_MSG_HEADER_LEN > urb->actual_length) {
+				netdev_err(netdev, "format error\n");
+				break;
+			}
+
 			msg = (struct ems_cpc_msg *)&ibuf[start];
 
 			switch (msg->type) {
@@ -474,7 +479,7 @@ static void ems_usb_read_bulk_callback(struct urb *urb)
 			start += CPC_MSG_HEADER_LEN + msg->length;
 			msg_count--;
 
-			if (start > urb->transfer_buffer_length) {
+			if (start > urb->actual_length) {
 				netdev_err(netdev, "format error\n");
 				break;
 			}
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH net 06/12] can: ucan: Fix infinite loop from zero-length messages
  2026-03-02 15:16 [PATCH net 0/12] pull-request: can 2026-03-02 Marc Kleine-Budde
                   ` (4 preceding siblings ...)
  2026-03-02 15:16 ` [PATCH net 05/12] can: ems_usb: ems_usb_read_bulk_callback(): check the proper length of a message Marc Kleine-Budde
@ 2026-03-02 15:16 ` Marc Kleine-Budde
  2026-03-02 15:16 ` [PATCH net 07/12] can: usb: etas_es58x: correctly anchor the urb in the read bulk callback Marc Kleine-Budde
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 18+ messages in thread
From: Marc Kleine-Budde @ 2026-03-02 15:16 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Greg Kroah-Hartman,
	Marc Kleine-Budde, Vincent Mailhol, stable

From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

If a broken ucan device gets a message with the message length field set
to 0, then the driver will loop for forever in
ucan_read_bulk_callback(), hanging the system.  If the length is 0, just
skip the message and go on to the next one.

This has been fixed in the kvaser_usb driver in the past in commit
0c73772cd2b8 ("can: kvaser_usb: leaf: Fix potential infinite loop in
command parsers"), so there must be some broken devices out there like
this somewhere.

Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: Vincent Mailhol <mailhol@kernel.org>
Cc: stable@kernel.org
Assisted-by: gkh_clanker_2000
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://patch.msgid.link/2026022319-huff-absurd-6a18@gregkh
Fixes: 9f2d3eae88d2 ("can: ucan: add driver for Theobroma Systems UCAN devices")
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/ucan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/can/usb/ucan.c b/drivers/net/can/usb/ucan.c
index c79508b1c43e..0ea0ac75e42f 100644
--- a/drivers/net/can/usb/ucan.c
+++ b/drivers/net/can/usb/ucan.c
@@ -748,7 +748,7 @@ static void ucan_read_bulk_callback(struct urb *urb)
 		len = le16_to_cpu(m->len);
 
 		/* check sanity (length of content) */
-		if (urb->actual_length - pos < len) {
+		if ((len == 0) || (urb->actual_length - pos < len)) {
 			netdev_warn(up->netdev,
 				    "invalid message (short; no data; l:%d)\n",
 				    urb->actual_length);
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH net 07/12] can: usb: etas_es58x: correctly anchor the urb in the read bulk callback
  2026-03-02 15:16 [PATCH net 0/12] pull-request: can 2026-03-02 Marc Kleine-Budde
                   ` (5 preceding siblings ...)
  2026-03-02 15:16 ` [PATCH net 06/12] can: ucan: Fix infinite loop from zero-length messages Marc Kleine-Budde
@ 2026-03-02 15:16 ` Marc Kleine-Budde
  2026-03-02 15:16 ` [PATCH net 08/12] can: usb: f81604: handle short interrupt urb messages properly Marc Kleine-Budde
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 18+ messages in thread
From: Marc Kleine-Budde @ 2026-03-02 15:16 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Greg Kroah-Hartman,
	Vincent Mailhol, Marc Kleine-Budde, stable

From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

When submitting an urb, that is using the anchor pattern, it needs to be
anchored before submitting it otherwise it could be leaked if
usb_kill_anchored_urbs() is called.  This logic is correctly done
elsewhere in the driver, except in the read bulk callback so do that
here also.

Cc: Vincent Mailhol <mailhol@kernel.org>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: stable@kernel.org
Assisted-by: gkh_clanker_2000
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Vincent Mailhol <mailhol@kernel.org>
Tested-by: Vincent Mailhol <mailhol@kernel.org>
Link: https://patch.msgid.link/2026022320-poser-stiffly-9d84@gregkh
Fixes: 8537257874e9 ("can: etas_es58x: add core support for ETAS ES58X CAN USB interfaces")
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/etas_es58x/es58x_core.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/usb/etas_es58x/es58x_core.c b/drivers/net/can/usb/etas_es58x/es58x_core.c
index 2d248deb69dc..b259f6109808 100644
--- a/drivers/net/can/usb/etas_es58x/es58x_core.c
+++ b/drivers/net/can/usb/etas_es58x/es58x_core.c
@@ -1461,12 +1461,18 @@ static void es58x_read_bulk_callback(struct urb *urb)
 	}
 
  resubmit_urb:
+	usb_anchor_urb(urb, &es58x_dev->rx_urbs);
 	ret = usb_submit_urb(urb, GFP_ATOMIC);
+	if (!ret)
+		return;
+
+	usb_unanchor_urb(urb);
+
 	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]);
-	} else if (ret)
+	} else
 		dev_err_ratelimited(dev,
 				    "Failed resubmitting read bulk urb: %pe\n",
 				    ERR_PTR(ret));
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH net 08/12] can: usb: f81604: handle short interrupt urb messages properly
  2026-03-02 15:16 [PATCH net 0/12] pull-request: can 2026-03-02 Marc Kleine-Budde
                   ` (6 preceding siblings ...)
  2026-03-02 15:16 ` [PATCH net 07/12] can: usb: etas_es58x: correctly anchor the urb in the read bulk callback Marc Kleine-Budde
@ 2026-03-02 15:16 ` Marc Kleine-Budde
  2026-03-03 14:23   ` Paolo Abeni
  2026-03-02 15:16 ` [PATCH net 09/12] can: usb: f81604: handle bulk write errors properly Marc Kleine-Budde
                   ` (3 subsequent siblings)
  11 siblings, 1 reply; 18+ messages in thread
From: Marc Kleine-Budde @ 2026-03-02 15:16 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Greg Kroah-Hartman,
	Ji-Ze Hong (Peter Hong), Marc Kleine-Budde, Vincent Mailhol,
	stable

From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

If an interrupt urb is received that is not the correct length, properly
detect it and don't attempt to treat the data as valid.

Cc: Ji-Ze Hong (Peter Hong) <peter_hong@fintek.com.tw>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: Vincent Mailhol <mailhol@kernel.org>
Cc: stable@kernel.org
Assisted-by: gkh_clanker_2000
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://patch.msgid.link/2026022331-opal-evaluator-a928@gregkh
Fixes: 88da17436973 ("can: usb: f81604: add Fintek F81604 support")
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/f81604.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/can/usb/f81604.c b/drivers/net/can/usb/f81604.c
index 76578063ac82..c61bd30d1765 100644
--- a/drivers/net/can/usb/f81604.c
+++ b/drivers/net/can/usb/f81604.c
@@ -620,6 +620,12 @@ static void f81604_read_int_callback(struct urb *urb)
 		netdev_info(netdev, "%s: Int URB aborted: %pe\n", __func__,
 			    ERR_PTR(urb->status));
 
+	if (urb->actual_length < sizeof(*data)) {
+		netdev_warn(netdev, "%s: short int URB: %u < %zu\n",
+			    __func__, urb->actual_length, sizeof(*data));
+		goto resubmit_urb;
+	}
+
 	switch (urb->status) {
 	case 0: /* success */
 		break;
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH net 09/12] can: usb: f81604: handle bulk write errors properly
  2026-03-02 15:16 [PATCH net 0/12] pull-request: can 2026-03-02 Marc Kleine-Budde
                   ` (7 preceding siblings ...)
  2026-03-02 15:16 ` [PATCH net 08/12] can: usb: f81604: handle short interrupt urb messages properly Marc Kleine-Budde
@ 2026-03-02 15:16 ` Marc Kleine-Budde
  2026-03-02 15:16 ` [PATCH net 10/12] can: usb: f81604: correctly anchor the urb in the read bulk callback Marc Kleine-Budde
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 18+ messages in thread
From: Marc Kleine-Budde @ 2026-03-02 15:16 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Greg Kroah-Hartman,
	Ji-Ze Hong (Peter Hong), Marc Kleine-Budde, Vincent Mailhol,
	stable

From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

If a write urb fails then more needs to be done other than just logging
the message, otherwise the transmission could be stalled.  Properly
increment the error counters and wake up the queues so that data will
continue to flow.

Cc: Ji-Ze Hong (Peter Hong) <peter_hong@fintek.com.tw>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: Vincent Mailhol <mailhol@kernel.org>
Cc: stable@kernel.org
Assisted-by: gkh_clanker_2000
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://patch.msgid.link/2026022334-slackness-dynamic-9195@gregkh
Fixes: 88da17436973 ("can: usb: f81604: add Fintek F81604 support")
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/f81604.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/net/can/usb/f81604.c b/drivers/net/can/usb/f81604.c
index c61bd30d1765..1cc927d79b6a 100644
--- a/drivers/net/can/usb/f81604.c
+++ b/drivers/net/can/usb/f81604.c
@@ -880,9 +880,27 @@ static void f81604_write_bulk_callback(struct urb *urb)
 	if (!netif_device_present(netdev))
 		return;
 
-	if (urb->status)
-		netdev_info(netdev, "%s: Tx URB error: %pe\n", __func__,
-			    ERR_PTR(urb->status));
+	if (!urb->status)
+		return;
+
+	switch (urb->status) {
+	case -ENOENT:
+	case -ECONNRESET:
+	case -ESHUTDOWN:
+		return;
+	default:
+		break;
+	}
+
+	if (net_ratelimit())
+		netdev_err(netdev, "%s: Tx URB error: %pe\n", __func__,
+			   ERR_PTR(urb->status));
+
+	can_free_echo_skb(netdev, 0, NULL);
+	netdev->stats.tx_dropped++;
+	netdev->stats.tx_errors++;
+
+	netif_wake_queue(netdev);
 }
 
 static void f81604_clear_reg_work(struct work_struct *work)
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH net 10/12] can: usb: f81604: correctly anchor the urb in the read bulk callback
  2026-03-02 15:16 [PATCH net 0/12] pull-request: can 2026-03-02 Marc Kleine-Budde
                   ` (8 preceding siblings ...)
  2026-03-02 15:16 ` [PATCH net 09/12] can: usb: f81604: handle bulk write errors properly Marc Kleine-Budde
@ 2026-03-02 15:16 ` Marc Kleine-Budde
  2026-03-02 15:16 ` [PATCH net 11/12] can: gs_usb: gs_can_open(): always configure bitrates before starting device Marc Kleine-Budde
  2026-03-02 15:16 ` [PATCH net 12/12] dt-bindings: net: can: nxp,sja1000: add reference to mc-peripheral-props.yaml Marc Kleine-Budde
  11 siblings, 0 replies; 18+ messages in thread
From: Marc Kleine-Budde @ 2026-03-02 15:16 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Greg Kroah-Hartman,
	Ji-Ze Hong (Peter Hong), Marc Kleine-Budde, Vincent Mailhol,
	stable

From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

When submitting an urb, that is using the anchor pattern, it needs to be
anchored before submitting it otherwise it could be leaked if
usb_kill_anchored_urbs() is called.  This logic is correctly done
elsewhere in the driver, except in the read bulk callback so do that
here also.

Cc: Ji-Ze Hong (Peter Hong) <peter_hong@fintek.com.tw>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: Vincent Mailhol <mailhol@kernel.org>
Cc: stable@kernel.org
Assisted-by: gkh_clanker_2000
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://patch.msgid.link/2026022334-starlight-scaling-2cea@gregkh
Fixes: 88da17436973 ("can: usb: f81604: add Fintek F81604 support")
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/f81604.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/usb/f81604.c b/drivers/net/can/usb/f81604.c
index 1cc927d79b6a..f12318268e46 100644
--- a/drivers/net/can/usb/f81604.c
+++ b/drivers/net/can/usb/f81604.c
@@ -413,6 +413,7 @@ static void f81604_read_bulk_callback(struct urb *urb)
 {
 	struct f81604_can_frame *frame = urb->transfer_buffer;
 	struct net_device *netdev = urb->context;
+	struct f81604_port_priv *priv = netdev_priv(netdev);
 	int ret;
 
 	if (!netif_device_present(netdev))
@@ -445,10 +446,15 @@ static void f81604_read_bulk_callback(struct urb *urb)
 	f81604_process_rx_packet(netdev, frame);
 
 resubmit_urb:
+	usb_anchor_urb(urb, &priv->urbs_anchor);
 	ret = usb_submit_urb(urb, GFP_ATOMIC);
+	if (!ret)
+		return;
+	usb_unanchor_urb(urb);
+
 	if (ret == -ENODEV)
 		netif_device_detach(netdev);
-	else if (ret)
+	else
 		netdev_err(netdev,
 			   "%s: failed to resubmit read bulk urb: %pe\n",
 			   __func__, ERR_PTR(ret));
@@ -652,10 +658,15 @@ static void f81604_read_int_callback(struct urb *urb)
 		f81604_handle_tx(priv, data);
 
 resubmit_urb:
+	usb_anchor_urb(urb, &priv->urbs_anchor);
 	ret = usb_submit_urb(urb, GFP_ATOMIC);
+	if (!ret)
+		return;
+	usb_unanchor_urb(urb);
+
 	if (ret == -ENODEV)
 		netif_device_detach(netdev);
-	else if (ret)
+	else
 		netdev_err(netdev, "%s: failed to resubmit int urb: %pe\n",
 			   __func__, ERR_PTR(ret));
 }
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH net 11/12] can: gs_usb: gs_can_open(): always configure bitrates before starting device
  2026-03-02 15:16 [PATCH net 0/12] pull-request: can 2026-03-02 Marc Kleine-Budde
                   ` (9 preceding siblings ...)
  2026-03-02 15:16 ` [PATCH net 10/12] can: usb: f81604: correctly anchor the urb in the read bulk callback Marc Kleine-Budde
@ 2026-03-02 15:16 ` Marc Kleine-Budde
  2026-03-02 15:16 ` [PATCH net 12/12] dt-bindings: net: can: nxp,sja1000: add reference to mc-peripheral-props.yaml Marc Kleine-Budde
  11 siblings, 0 replies; 18+ messages in thread
From: Marc Kleine-Budde @ 2026-03-02 15:16 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel, Marc Kleine-Budde, stable

So far the driver populated the struct can_priv::do_set_bittiming() and
struct can_priv::fd::do_set_data_bittiming() callbacks.

Before bringing up the interface, user space has to configure the bitrates.
With these callbacks the configuration is directly forwarded into the CAN
hardware. Then the interface can be brought up.

An ifdown-ifup cycle (without changing the bit rates) doesn't re-configure
the bitrates in the CAN hardware. This leads to a problem with the
CANable-2.5 [1] firmware, which resets the configured bit rates during
ifdown.

To fix the problem remove both bit timing callbacks and always configure
the bitrates in the struct net_device_ops::ndo_open() callback.

[1] https://github.com/Elmue/CANable-2.5-firmware-Slcan-and-Candlelight

Cc: stable@vger.kernel.org
Fixes: d08e973a77d1 ("can: gs_usb: Added support for the GS_USB CAN devices")
Link: https://patch.msgid.link/20260219-gs_usb-always-configure-bitrates-v2-1-671f8ba5b0a5@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/gs_usb.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
index 9d27d6f0c0b5..ec9a7cbbbc69 100644
--- a/drivers/net/can/usb/gs_usb.c
+++ b/drivers/net/can/usb/gs_usb.c
@@ -772,9 +772,8 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
 	}
 }
 
-static int gs_usb_set_bittiming(struct net_device *netdev)
+static int gs_usb_set_bittiming(struct gs_can *dev)
 {
-	struct gs_can *dev = netdev_priv(netdev);
 	struct can_bittiming *bt = &dev->can.bittiming;
 	struct gs_device_bittiming dbt = {
 		.prop_seg = cpu_to_le32(bt->prop_seg),
@@ -791,9 +790,8 @@ static int gs_usb_set_bittiming(struct net_device *netdev)
 				    GFP_KERNEL);
 }
 
-static int gs_usb_set_data_bittiming(struct net_device *netdev)
+static int gs_usb_set_data_bittiming(struct gs_can *dev)
 {
-	struct gs_can *dev = netdev_priv(netdev);
 	struct can_bittiming *bt = &dev->can.fd.data_bittiming;
 	struct gs_device_bittiming dbt = {
 		.prop_seg = cpu_to_le32(bt->prop_seg),
@@ -1057,6 +1055,20 @@ static int gs_can_open(struct net_device *netdev)
 	if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
 		flags |= GS_CAN_MODE_HW_TIMESTAMP;
 
+	rc = gs_usb_set_bittiming(dev);
+	if (rc) {
+		netdev_err(netdev, "failed to set bittiming: %pe\n", ERR_PTR(rc));
+		goto out_usb_kill_anchored_urbs;
+	}
+
+	if (ctrlmode & CAN_CTRLMODE_FD) {
+		rc = gs_usb_set_data_bittiming(dev);
+		if (rc) {
+			netdev_err(netdev, "failed to set data bittiming: %pe\n", ERR_PTR(rc));
+			goto out_usb_kill_anchored_urbs;
+		}
+	}
+
 	/* finally start device */
 	dev->can.state = CAN_STATE_ERROR_ACTIVE;
 	dm.flags = cpu_to_le32(flags);
@@ -1370,7 +1382,6 @@ static struct gs_can *gs_make_candev(unsigned int channel,
 	dev->can.state = CAN_STATE_STOPPED;
 	dev->can.clock.freq = le32_to_cpu(bt_const.fclk_can);
 	dev->can.bittiming_const = &dev->bt_const;
-	dev->can.do_set_bittiming = gs_usb_set_bittiming;
 
 	dev->can.ctrlmode_supported = CAN_CTRLMODE_CC_LEN8_DLC;
 
@@ -1394,7 +1405,6 @@ static struct gs_can *gs_make_candev(unsigned int channel,
 		 * GS_CAN_FEATURE_BT_CONST_EXT is set.
 		 */
 		dev->can.fd.data_bittiming_const = &dev->bt_const;
-		dev->can.fd.do_set_data_bittiming = gs_usb_set_data_bittiming;
 	}
 
 	if (feature & GS_CAN_FEATURE_TERMINATION) {
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH net 12/12] dt-bindings: net: can: nxp,sja1000: add reference to mc-peripheral-props.yaml
  2026-03-02 15:16 [PATCH net 0/12] pull-request: can 2026-03-02 Marc Kleine-Budde
                   ` (10 preceding siblings ...)
  2026-03-02 15:16 ` [PATCH net 11/12] can: gs_usb: gs_can_open(): always configure bitrates before starting device Marc Kleine-Budde
@ 2026-03-02 15:16 ` Marc Kleine-Budde
  11 siblings, 0 replies; 18+ messages in thread
From: Marc Kleine-Budde @ 2026-03-02 15:16 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Frank Li, Krzysztof Kozlowski,
	Marc Kleine-Budde

From: Frank Li <Frank.Li@nxp.com>

Add a reference to mc-peripheral-props.yaml to allow vendor-specific
properties for memory access timings.

Fix below CHECK_DTBS warings:
arch/arm/boot/dts/nxp/imx/imx27-phytec-phycore-rdk.dtb: can@4,0 (nxp,sja1000): Unevaluated properties are not allowed ('fsl,weim-cs-timing' was unexpected)
        from schema $id: http://devicetree.org/schemas/net/can/nxp,sja1000.yaml

Signed-off-by: Frank Li <Frank.Li@nxp.com>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Link: https://patch.msgid.link/20260212163000.1195586-1-Frank.Li@nxp.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 Documentation/devicetree/bindings/net/can/nxp,sja1000.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/net/can/nxp,sja1000.yaml b/Documentation/devicetree/bindings/net/can/nxp,sja1000.yaml
index ec0c2168e4b9..6bcfff970117 100644
--- a/Documentation/devicetree/bindings/net/can/nxp,sja1000.yaml
+++ b/Documentation/devicetree/bindings/net/can/nxp,sja1000.yaml
@@ -87,6 +87,7 @@ required:
 
 allOf:
   - $ref: can-controller.yaml#
+  - $ref: /schemas/memory-controllers/mc-peripheral-props.yaml
   - if:
       properties:
         compatible:
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH net 05/12] can: ems_usb: ems_usb_read_bulk_callback(): check the proper length of a message
  2026-03-02 15:16 ` [PATCH net 05/12] can: ems_usb: ems_usb_read_bulk_callback(): check the proper length of a message Marc Kleine-Budde
@ 2026-03-03 14:20   ` Paolo Abeni
  2026-03-03 14:33     ` Marc Kleine-Budde
  0 siblings, 1 reply; 18+ messages in thread
From: Paolo Abeni @ 2026-03-03 14:20 UTC (permalink / raw)
  To: Marc Kleine-Budde, netdev
  Cc: davem, kuba, linux-can, kernel, Greg Kroah-Hartman,
	Vincent Mailhol, stable

On 3/2/26 4:16 PM, Marc Kleine-Budde wrote:
> From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> 
> When looking at the data in a USB urb, the actual_length is the size of
> the buffer passed to the driver, not the transfer_buffer_length which is
> set by the driver as the max size of the buffer.
> 
> When parsing the messages in ems_usb_read_bulk_callback() properly check
> the size both at the beginning of parsing the message to make sure it is
> big enough for the expected structure, and at the end of the message to
> make sure we don't overflow past the end of the buffer for the next
> message.
> 
> Cc: Vincent Mailhol <mailhol@kernel.org>
> Cc: Marc Kleine-Budde <mkl@pengutronix.de>
> Cc: stable@kernel.org
> Assisted-by: gkh_clanker_2000
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Link: https://patch.msgid.link/2026022316-answering-strainer-a5db@gregkh
> Fixes: 702171adeed3 ("ems_usb: Added support for EMS CPC-USB/ARM7 CAN/USB interface")
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> ---
>  drivers/net/can/usb/ems_usb.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c
> index 4c219a5b139b..9b25dda7c183 100644
> --- a/drivers/net/can/usb/ems_usb.c
> +++ b/drivers/net/can/usb/ems_usb.c
> @@ -445,6 +445,11 @@ static void ems_usb_read_bulk_callback(struct urb *urb)
>  		start = CPC_HEADER_SIZE;
>  
>  		while (msg_count) {
> +			if (start + CPC_MSG_HEADER_LEN > urb->actual_length) {
> +				netdev_err(netdev, "format error\n");
> +				break;
> +			}
> +
>  			msg = (struct ems_cpc_msg *)&ibuf[start];
>  
>  			switch (msg->type) {
> @@ -474,7 +479,7 @@ static void ems_usb_read_bulk_callback(struct urb *urb)
>  			start += CPC_MSG_HEADER_LEN + msg->length;
>  			msg_count--;
>  
> -			if (start > urb->transfer_buffer_length) {
> +			if (start > urb->actual_length) {
>  				netdev_err(netdev, "format error\n");
>  				break;
>  			}

AI noticed the following:
---
Does the check validate enough of the message? The code checks that the
11-byte header (CPC_MSG_HEADER_LEN) fits in the buffer, but
ems_usb_rx_can_msg() and ems_usb_rx_err() both access fields in the
msg->msg union payload starting at offset 11.

For example, ems_usb_rx_can_msg() reads:
- msg->msg.can_msg.id (4 bytes at offset 11)
- msg->msg.can_msg.length (1 byte at offset 15)
- msg->msg.can_msg.msg[i] (up to 8 bytes at offset 16)

Similarly, ems_usb_rx_err() reads:
- msg->msg.can_state (1 byte at offset 11)
- msg->msg.error.cc.regs.sja1000.{ecc,txerr,rxerr} (3 bytes at offset 11+)

A malicious USB device could send a packet where actual_length equals
CPC_HEADER_SIZE + CPC_MSG_HEADER_LEN (15 bytes total), which would pass
this check but provide zero payload bytes. The callees would then read
beyond the received buffer before reaching the second check at the end
of the loop.

Should the validation check that both the header and payload
(msg->length bytes) fit within actual_length before calling the
processing functions?
---
I guess this patch could need a follow-up? Not blocking the PR, as
AFAICS worst case this patch still improves the current situation.

/P


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH net 08/12] can: usb: f81604: handle short interrupt urb messages properly
  2026-03-02 15:16 ` [PATCH net 08/12] can: usb: f81604: handle short interrupt urb messages properly Marc Kleine-Budde
@ 2026-03-03 14:23   ` Paolo Abeni
  2026-03-04  9:07     ` Greg Kroah-Hartman
  0 siblings, 1 reply; 18+ messages in thread
From: Paolo Abeni @ 2026-03-03 14:23 UTC (permalink / raw)
  To: Marc Kleine-Budde, netdev
  Cc: davem, kuba, linux-can, kernel, Greg Kroah-Hartman,
	Ji-Ze Hong (Peter Hong), Vincent Mailhol, stable

On 3/2/26 4:16 PM, Marc Kleine-Budde wrote:
> From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> 
> If an interrupt urb is received that is not the correct length, properly
> detect it and don't attempt to treat the data as valid.
> 
> Cc: Ji-Ze Hong (Peter Hong) <peter_hong@fintek.com.tw>
> Cc: Marc Kleine-Budde <mkl@pengutronix.de>
> Cc: Vincent Mailhol <mailhol@kernel.org>
> Cc: stable@kernel.org
> Assisted-by: gkh_clanker_2000
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Link: https://patch.msgid.link/2026022331-opal-evaluator-a928@gregkh
> Fixes: 88da17436973 ("can: usb: f81604: add Fintek F81604 support")
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> ---
>  drivers/net/can/usb/f81604.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/net/can/usb/f81604.c b/drivers/net/can/usb/f81604.c
> index 76578063ac82..c61bd30d1765 100644
> --- a/drivers/net/can/usb/f81604.c
> +++ b/drivers/net/can/usb/f81604.c
> @@ -620,6 +620,12 @@ static void f81604_read_int_callback(struct urb *urb)
>  		netdev_info(netdev, "%s: Int URB aborted: %pe\n", __func__,
>  			    ERR_PTR(urb->status));
>  
> +	if (urb->actual_length < sizeof(*data)) {
> +		netdev_warn(netdev, "%s: short int URB: %u < %zu\n",
> +			    __func__, urb->actual_length, sizeof(*data));
> +		goto resubmit_urb;
> +	}
> +
>  	switch (urb->status) {
>  	case 0: /* success */
>  		break;

AI says:

---
Should the length check happen after the status check instead of before it?
With the current ordering, if a URB completes with both a terminal error
status (like -ESHUTDOWN, -ENOENT, -EPIPE, or -EPROTO) and insufficient
data length, the code will jump to resubmit_urb instead of returning
immediately.

Looking at the switch statement that follows:

>  	switch (urb->status) {
>  	case 0: /* success */
>  		break;
>
> 	case -ENOENT:
> 	case -EPIPE:
> 	case -EPROTO:
> 	case -ESHUTDOWN:
> 		return;

Terminal error codes should cause immediate return without resubmission,
but the length check bypasses this. This could lead to inappropriate URB
resubmissions when the device is shutting down or has been disconnected.
---

IDK if 'status' is valid in case of short URB, possibly the patch code
is fine, but please have a look. Again, not blocking the PR.

/P


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH net 05/12] can: ems_usb: ems_usb_read_bulk_callback(): check the proper length of a message
  2026-03-03 14:20   ` Paolo Abeni
@ 2026-03-03 14:33     ` Marc Kleine-Budde
  0 siblings, 0 replies; 18+ messages in thread
From: Marc Kleine-Budde @ 2026-03-03 14:33 UTC (permalink / raw)
  To: Paolo Abeni
  Cc: netdev, davem, kuba, linux-can, kernel, Greg Kroah-Hartman,
	Vincent Mailhol, stable

[-- Attachment #1: Type: text/plain, Size: 1713 bytes --]

On 03.03.2026 15:20:01, Paolo Abeni wrote:
> AI noticed the following:
> ---
> Does the check validate enough of the message? The code checks that the
> 11-byte header (CPC_MSG_HEADER_LEN) fits in the buffer, but
> ems_usb_rx_can_msg() and ems_usb_rx_err() both access fields in the
> msg->msg union payload starting at offset 11.
>
> For example, ems_usb_rx_can_msg() reads:
> - msg->msg.can_msg.id (4 bytes at offset 11)
> - msg->msg.can_msg.length (1 byte at offset 15)
> - msg->msg.can_msg.msg[i] (up to 8 bytes at offset 16)
>
> Similarly, ems_usb_rx_err() reads:
> - msg->msg.can_state (1 byte at offset 11)
> - msg->msg.error.cc.regs.sja1000.{ecc,txerr,rxerr} (3 bytes at offset 11+)
>
> A malicious USB device could send a packet where actual_length equals
> CPC_HEADER_SIZE + CPC_MSG_HEADER_LEN (15 bytes total), which would pass
> this check but provide zero payload bytes. The callees would then read
> beyond the received buffer before reaching the second check at the end
> of the loop.
>
> Should the validation check that both the header and payload
> (msg->length bytes) fit within actual_length before calling the
> processing functions?
> ---
> I guess this patch could need a follow-up? Not blocking the PR, as
> AFAICS worst case this patch still improves the current situation.

Yes, Greg said he'll look into this

| https://lore.kernel.org/all/2026030253-lather-pulse-3bb5@gregkh/

Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH net 08/12] can: usb: f81604: handle short interrupt urb messages properly
  2026-03-03 14:23   ` Paolo Abeni
@ 2026-03-04  9:07     ` Greg Kroah-Hartman
  0 siblings, 0 replies; 18+ messages in thread
From: Greg Kroah-Hartman @ 2026-03-04  9:07 UTC (permalink / raw)
  To: Paolo Abeni
  Cc: Marc Kleine-Budde, netdev, davem, kuba, linux-can, kernel,
	Ji-Ze Hong (Peter Hong), Vincent Mailhol, stable

On Tue, Mar 03, 2026 at 03:23:19PM +0100, Paolo Abeni wrote:
> On 3/2/26 4:16 PM, Marc Kleine-Budde wrote:
> > From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > 
> > If an interrupt urb is received that is not the correct length, properly
> > detect it and don't attempt to treat the data as valid.
> > 
> > Cc: Ji-Ze Hong (Peter Hong) <peter_hong@fintek.com.tw>
> > Cc: Marc Kleine-Budde <mkl@pengutronix.de>
> > Cc: Vincent Mailhol <mailhol@kernel.org>
> > Cc: stable@kernel.org
> > Assisted-by: gkh_clanker_2000
> > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Link: https://patch.msgid.link/2026022331-opal-evaluator-a928@gregkh
> > Fixes: 88da17436973 ("can: usb: f81604: add Fintek F81604 support")
> > Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> > ---
> >  drivers/net/can/usb/f81604.c | 6 ++++++
> >  1 file changed, 6 insertions(+)
> > 
> > diff --git a/drivers/net/can/usb/f81604.c b/drivers/net/can/usb/f81604.c
> > index 76578063ac82..c61bd30d1765 100644
> > --- a/drivers/net/can/usb/f81604.c
> > +++ b/drivers/net/can/usb/f81604.c
> > @@ -620,6 +620,12 @@ static void f81604_read_int_callback(struct urb *urb)
> >  		netdev_info(netdev, "%s: Int URB aborted: %pe\n", __func__,
> >  			    ERR_PTR(urb->status));
> >  
> > +	if (urb->actual_length < sizeof(*data)) {
> > +		netdev_warn(netdev, "%s: short int URB: %u < %zu\n",
> > +			    __func__, urb->actual_length, sizeof(*data));
> > +		goto resubmit_urb;
> > +	}
> > +
> >  	switch (urb->status) {
> >  	case 0: /* success */
> >  		break;
> 
> AI says:
> 
> ---
> Should the length check happen after the status check instead of before it?
> With the current ordering, if a URB completes with both a terminal error
> status (like -ESHUTDOWN, -ENOENT, -EPIPE, or -EPROTO) and insufficient
> data length, the code will jump to resubmit_urb instead of returning
> immediately.
> 
> Looking at the switch statement that follows:
> 
> >  	switch (urb->status) {
> >  	case 0: /* success */
> >  		break;
> >
> > 	case -ENOENT:
> > 	case -EPIPE:
> > 	case -EPROTO:
> > 	case -ESHUTDOWN:
> > 		return;
> 
> Terminal error codes should cause immediate return without resubmission,
> but the length check bypasses this. This could lead to inappropriate URB
> resubmissions when the device is shutting down or has been disconnected.
> ---
> 
> IDK if 'status' is valid in case of short URB, possibly the patch code
> is fine, but please have a look. Again, not blocking the PR.

status will be valid in case of a short URB, so all should be fine.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH net 01/12] can: bcm: fix locking for bcm_op runtime updates
  2026-03-02 15:16 ` [PATCH net 01/12] can: bcm: fix locking for bcm_op runtime updates Marc Kleine-Budde
@ 2026-03-05  1:00   ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 18+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-03-05  1:00 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: netdev, davem, kuba, linux-can, kernel, socketcan,
	syzbot+5b11eccc403dd1cea9f8

Hello:

This series was applied to netdev/net.git (main)
by Marc Kleine-Budde <mkl@pengutronix.de>:

On Mon,  2 Mar 2026 16:16:07 +0100 you wrote:
> From: Oliver Hartkopp <socketcan@hartkopp.net>
> 
> Commit c2aba69d0c36 ("can: bcm: add locking for bcm_op runtime updates")
> added a locking for some variables that can be modified at runtime when
> updating the sending bcm_op with a new TX_SETUP command in bcm_tx_setup().
> 
> Usually the RX_SETUP only handles and filters incoming traffic with one
> exception: When the RX_RTR_FRAME flag is set a predefined CAN frame is
> sent when a specific RTR frame is received. Therefore the rx bcm_op uses
> bcm_can_tx() which uses the bcm_tx_lock that was only initialized in
> bcm_tx_setup(). Add the missing spin_lock_init() when allocating the
> bcm_op in bcm_rx_setup() to handle the RTR case properly.
> 
> [...]

Here is the summary with links:
  - [net,01/12] can: bcm: fix locking for bcm_op runtime updates
    https://git.kernel.org/netdev/net/c/c35636e91e39
  - [net,02/12] can: dummy_can: dummy_can_init(): fix packet statistics
    https://git.kernel.org/netdev/net/c/c77bfbdd6aac
  - [net,03/12] can: mcp251x: fix deadlock in error path of mcp251x_open
    https://git.kernel.org/netdev/net/c/ab3f894de216
  - [net,04/12] can: esd_usb: add endpoint type validation
    https://git.kernel.org/netdev/net/c/968b098220e3
  - [net,05/12] can: ems_usb: ems_usb_read_bulk_callback(): check the proper length of a message
    https://git.kernel.org/netdev/net/c/38a01c9700b0
  - [net,06/12] can: ucan: Fix infinite loop from zero-length messages
    https://git.kernel.org/netdev/net/c/1e446fd0582a
  - [net,07/12] can: usb: etas_es58x: correctly anchor the urb in the read bulk callback
    https://git.kernel.org/netdev/net/c/5eaad4f76826
  - [net,08/12] can: usb: f81604: handle short interrupt urb messages properly
    https://git.kernel.org/netdev/net/c/7299b1b39a25
  - [net,09/12] can: usb: f81604: handle bulk write errors properly
    https://git.kernel.org/netdev/net/c/51f94780720f
  - [net,10/12] can: usb: f81604: correctly anchor the urb in the read bulk callback
    https://git.kernel.org/netdev/net/c/952caa5da10b
  - [net,11/12] can: gs_usb: gs_can_open(): always configure bitrates before starting device
    https://git.kernel.org/netdev/net/c/2df6162785f3
  - [net,12/12] dt-bindings: net: can: nxp,sja1000: add reference to mc-peripheral-props.yaml
    https://git.kernel.org/netdev/net/c/7e1e6d684532

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2026-03-05  1:00 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-02 15:16 [PATCH net 0/12] pull-request: can 2026-03-02 Marc Kleine-Budde
2026-03-02 15:16 ` [PATCH net 01/12] can: bcm: fix locking for bcm_op runtime updates Marc Kleine-Budde
2026-03-05  1:00   ` patchwork-bot+netdevbpf
2026-03-02 15:16 ` [PATCH net 02/12] can: dummy_can: dummy_can_init(): fix packet statistics Marc Kleine-Budde
2026-03-02 15:16 ` [PATCH net 03/12] can: mcp251x: fix deadlock in error path of mcp251x_open Marc Kleine-Budde
2026-03-02 15:16 ` [PATCH net 04/12] can: esd_usb: add endpoint type validation Marc Kleine-Budde
2026-03-02 15:16 ` [PATCH net 05/12] can: ems_usb: ems_usb_read_bulk_callback(): check the proper length of a message Marc Kleine-Budde
2026-03-03 14:20   ` Paolo Abeni
2026-03-03 14:33     ` Marc Kleine-Budde
2026-03-02 15:16 ` [PATCH net 06/12] can: ucan: Fix infinite loop from zero-length messages Marc Kleine-Budde
2026-03-02 15:16 ` [PATCH net 07/12] can: usb: etas_es58x: correctly anchor the urb in the read bulk callback Marc Kleine-Budde
2026-03-02 15:16 ` [PATCH net 08/12] can: usb: f81604: handle short interrupt urb messages properly Marc Kleine-Budde
2026-03-03 14:23   ` Paolo Abeni
2026-03-04  9:07     ` Greg Kroah-Hartman
2026-03-02 15:16 ` [PATCH net 09/12] can: usb: f81604: handle bulk write errors properly Marc Kleine-Budde
2026-03-02 15:16 ` [PATCH net 10/12] can: usb: f81604: correctly anchor the urb in the read bulk callback Marc Kleine-Budde
2026-03-02 15:16 ` [PATCH net 11/12] can: gs_usb: gs_can_open(): always configure bitrates before starting device Marc Kleine-Budde
2026-03-02 15:16 ` [PATCH net 12/12] dt-bindings: net: can: nxp,sja1000: add reference to mc-peripheral-props.yaml Marc Kleine-Budde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox