Skip to contentSkip to conversation

pull-request: can 2025-02-08

PATCH Applied Marc Kleine-Budde 2 participants 8 messages Feb 8, 2025 – Feb 11, 2025

Subsystems (11)
lore
Share & tools
lore

Marc Kleine-Budde

author maintainer
#0 lore raw

cover pull-request: can 2025-02-08

Hello netdev-team,

this is a pull request of 6 patches for net/master.

The first patch is by Reyders Morales and fixes a code example in the CAN ISO15765-2 documentation.

The next patch is contributed by Alexander Hölzl and fixes sending of J1939 messages with zero data length.

Fedor Pchelkin's patch for the ctucanfd driver adds a missing handling for an skb allocation error.

Krzysztof Kozlowski contributes a patch for the c_can driver to fix unbalanced runtime PM disable in error path.

The next patch is by Vincent Mailhol and fixes a NULL pointer dereference on udev->serial in the etas_es58x driver.

The patch is by Robin van der Gracht and fixes the handling for an skb allocation error.

regards,
Marc

---

The following changes since commit 1438f5d07b9a7afb15e1d0e26df04a6fd4e56a3c:

rtnetlink: fix netns leak with rtnl_setlink() (2025-02-06 17:17:44 -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-6.14-20250208

for you to fetch changes up to f7f0adfe64de08803990dc4cbecd2849c04e314a:

can: rockchip: rkcanfd_handle_rx_fifo_overflow_int(): bail out if skb cannot be allocated (2025-02-08 12:42:56 +0100)

----------------------------------------------------------------
linux-can-fixes-for-6.14-20250208

----------------------------------------------------------------
Alexander Hölzl (1):
can: j1939: j1939_sk_send_loop(): fix unable to send messages with data length zero

Fedor Pchelkin (1):
can: ctucanfd: handle skb allocation failure

Krzysztof Kozlowski (1):
can: c_can: fix unbalanced runtime PM disable in error path

Reyders Morales (1):
Documentation/networking: fix basic node example document ISO 15765-2

Robin van der Gracht (1):
can: rockchip: rkcanfd_handle_rx_fifo_overflow_int(): bail out if skb cannot be allocated

Vincent Mailhol (1):

      can: etas_es58x: fix potential NULL pointer dereference on udev->serial
 Documentation/networking/iso15765-2.rst        |  4 ++--
 drivers/net/can/c_can/c_can_platform.c         |  5 +++--
 drivers/net/can/ctucanfd/ctucanfd_base.c       | 10 ++++++----
 drivers/net/can/rockchip/rockchip_canfd-core.c |  2 +-
 drivers/net/can/usb/etas_es58x/es58x_devlink.c |  6 +++++-
 net/can/j1939/socket.c                         |  4 ++--
 net/can/j1939/transport.c                      |  5 +++--
 7 files changed, 22 insertions(+), 14 deletions(-)
author maintainer
#1 lore raw

PATCH 1/6 Documentation/networking: fix basic node example document ISO 15765-2

From: Reyders Morales <[email protected]>

In the current struct sockaddr_can tp is member of can_addr. tp is not member of struct sockaddr_can.

---
 Documentation/networking/iso15765-2.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/networking/iso15765-2.rst +2 -2
index 0e9d96074178..37ebb2c417cb 100644
@@ -369,8 +369,8 @@ to their default.
 
   addr.can_family = AF_CAN;
   addr.can_ifindex = if_nametoindex("can0");
-  addr.tp.tx_id = 0x18DA42F1 | CAN_EFF_FLAG;
-  addr.tp.rx_id = 0x18DAF142 | CAN_EFF_FLAG;
+  addr.can_addr.tp.tx_id = 0x18DA42F1 | CAN_EFF_FLAG;
+  addr.can_addr.tp.rx_id = 0x18DAF142 | CAN_EFF_FLAG;
 
   ret = bind(s, (struct sockaddr *)&addr, sizeof(addr));
   if (ret < 0)

base-commit: 1438f5d07b9a7afb15e1d0e26df04a6fd4e56a3c

Signature · 1 line
2.47.2
#2 lore raw

Re: [PATCH net 1/6] Documentation/networking: fix basic node example document ISO 15765-2

This series was applied to netdev/net.git (main) by Marc Kleine-Budde <[email protected]>:

Hello:

This series was applied to netdev/net.git (main)
by Marc Kleine-Budde <[email protected]>:

Quoted 5 lines · On Sat, 8 Feb 2025 12:45:14 +0100 you wrote:

From: Reyders Morales <[email protected]>

In the current struct sockaddr_can tp is member of can_addr. tp is not member of struct sockaddr_can.

Quoted 8 lines

[...]

Here is the summary with links:
- [net,1/6] Documentation/networking: fix basic node example document ISO 15765-2

    https://git.kernel.org/netdev/net/c/d0b197b6505f
  - [net,2/6] can: j1939: j1939_sk_send_loop(): fix unable to send messages with data length zero
    https://git.kernel.org/netdev/net/c/44de577e61ed
  - [net,3/6] can: ctucanfd: handle skb allocation failure
    https://git.kernel.org/netdev/net/c/9bd24927e3ee
  - [net,4/6] can: c_can: fix unbalanced runtime PM disable in error path
    https://git.kernel.org/netdev/net/c/257a2cd3eb57
  - [net,5/6] can: etas_es58x: fix potential NULL pointer dereference on udev->serial
    https://git.kernel.org/netdev/net/c/a1ad2109ce41
  - [net,6/6] can: rockchip: rkcanfd_handle_rx_fifo_overflow_int(): bail out if skb cannot be allocated
    https://git.kernel.org/netdev/net/c/f7f0adfe64de

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
author maintainer
#3 lore raw

PATCH 2/6 can: j1939: j1939_sk_send_loop(): fix unable to send messages with data length zero

In reply to Marc Kleine-Budde

From: Alexander Hölzl <[email protected]>

The J1939 standard requires the transmission of messages of length 0.

For example proprietary messages are specified with a data length of 0 to 1785. The transmission of such messages is not possible. Sending results in no error being returned but no corresponding can frame being generated.

Enable the transmission of zero length J1939 messages. In order to facilitate this two changes are necessary:

1) If the transmission of a new message is requested from user space the message is segmented in j1939_sk_send_loop(). Let the segmentation take into account zero length messages, do not terminate immediately, queue the corresponding skb.

2) j1939_session_skb_get_by_offset() selects the next skb to transmit for a session. Take into account that there might be zero length skbs in the queue.

Fixes 9d71dd0c7009 ("can: add support of SAE J1939 protocol")
[mkl: commit message rephrased]
---
 net/can/j1939/socket.c    | 4 ++--
 net/can/j1939/transport.c | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)
net/can/j1939/socket.c +2 -2
index 305dd72c844c..17226b2341d0 100644
@@ -1132,7 +1132,7 @@ static int j1939_sk_send_loop(struct j1939_priv *priv,  struct sock *sk,
 
 	todo_size = size;
 
-	while (todo_size) {
+	do {
 		struct j1939_sk_buff_cb *skcb;
 
 		segment_size = min_t(size_t, J1939_MAX_TP_PACKET_SIZE,
@@ -1177,7 +1177,7 @@ static int j1939_sk_send_loop(struct j1939_priv *priv,  struct sock *sk,
 
 		todo_size -= segment_size;
 		session->total_queued_size += segment_size;
-	}
+	} while (todo_size);
 
 	switch (ret) {
 	case 0: /* OK */
net/can/j1939/transport.c +3 -2
index 95f7a7e65a73..9b72d118d756 100644
@@ -382,8 +382,9 @@ sk_buff *j1939_session_skb_get_by_offset(struct j1939_session *session,
 	skb_queue_walk(&session->skb_queue, do_skb) {
 		do_skcb = j1939_skb_to_cb(do_skb);
 
-		if (offset_start >= do_skcb->offset &&
-		    offset_start < (do_skcb->offset + do_skb->len)) {
+		if ((offset_start >= do_skcb->offset &&
+		     offset_start < (do_skcb->offset + do_skb->len)) ||
+		     (offset_start == 0 && do_skcb->offset == 0 && do_skb->len == 0)) {
 			skb = do_skb;
 		}
 	}
Signature · 1 line
2.47.2
author maintainer
#4 lore raw

PATCH 3/6 can: ctucanfd: handle skb allocation failure

In reply to Marc Kleine-Budde

From: Fedor Pchelkin <[email protected]>

If skb allocation fails, the pointer to struct can_frame is NULL. This is actually handled everywhere inside ctucan_err_interrupt() except for the only place.

Add the missed NULL check.

Found by Linux Verification Center (linuxtesting.org) with SVACE static analysis tool.

Fixes 2dcb8e8782d8 ("can: ctucanfd: add support for CTU CAN FD open-source IP core - bus independent part.")
---
 drivers/net/can/ctucanfd/ctucanfd_base.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/net/can/ctucanfd/ctucanfd_base.c +6 -4
index 64c349fd4600..f65c1a1e05cc 100644
@@ -867,10 +867,12 @@ static void ctucan_err_interrupt(struct net_device *ndev, u32 isr)
 			}
 			break;
 		case CAN_STATE_ERROR_ACTIVE:
-			cf->can_id |= CAN_ERR_CNT;
-			cf->data[1] = CAN_ERR_CRTL_ACTIVE;
-			cf->data[6] = bec.txerr;
-			cf->data[7] = bec.rxerr;
+			if (skb) {
+				cf->can_id |= CAN_ERR_CNT;
+				cf->data[1] = CAN_ERR_CRTL_ACTIVE;
+				cf->data[6] = bec.txerr;
+				cf->data[7] = bec.rxerr;
+			}
 			break;
 		default:
 			netdev_warn(ndev, "unhandled error state (%d:%s)!\n",
Signature · 1 line
2.47.2
author maintainer
#5 lore raw

PATCH 4/6 can: c_can: fix unbalanced runtime PM disable in error path

In reply to Marc Kleine-Budde

From: Krzysztof Kozlowski <[email protected]>

Runtime PM is enabled as one of the last steps of probe(), so all earlier gotos to "exit_free_device" label were not correct and were leading to unbalanced runtime PM disable depth.

Fixes 6e2fe01dd6f9 ("can: c_can: move runtime PM enable/disable to c_can_platform")
---
 drivers/net/can/c_can/c_can_platform.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/can/c_can/c_can_platform.c +3 -2
index 6cba9717a6d8..399844809bbe 100644
@@ -385,15 +385,16 @@ static int c_can_plat_probe(struct platform_device *pdev)
 	if (ret) {
 		dev_err(&pdev->dev, "registering %s failed (err=%d)\n",
 			KBUILD_MODNAME, ret);
-		goto exit_free_device;
+		goto exit_pm_runtime;
 	}
 
 	dev_info(&pdev->dev, "%s device registered (regs=%p, irq=%d)\n",
 		 KBUILD_MODNAME, priv->base, dev->irq);
 	return 0;
 
-exit_free_device:
+exit_pm_runtime:
 	pm_runtime_disable(priv->device);
+exit_free_device:
 	free_c_can_dev(dev);
 exit:
 	dev_err(&pdev->dev, "probe failed\n");
Signature · 1 line
2.47.2
author maintainer
#6 lore raw

PATCH 5/6 can: etas_es58x: fix potential NULL pointer dereference on udev->serial

In reply to Marc Kleine-Budde

From: Vincent Mailhol <[email protected]>

The driver assumed that es58x_dev->udev->serial could never be NULL. While this is true on commercially available devices, an attacker could spoof the device identity providing a NULL USB serial number. That would trigger a NULL pointer dereference.

Add a check on es58x_dev->udev->serial before accessing it.

---
 drivers/net/can/usb/etas_es58x/es58x_devlink.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/can/usb/etas_es58x/es58x_devlink.c +5 -1
index eee20839d96f..0d155eb1b9e9 100644
@@ -248,7 +248,11 @@ static int es58x_devlink_info_get(struct devlink *devlink,
 			return ret;
 	}
 
-	return devlink_info_serial_number_put(req, es58x_dev->udev->serial);
+	if (es58x_dev->udev->serial)
+		ret = devlink_info_serial_number_put(req,
+						     es58x_dev->udev->serial);
+
+	return ret;
 }
 
 const struct devlink_ops es58x_dl_ops = {
Signature · 1 line
2.47.2
author maintainer
#7 lore raw

PATCH 6/6 can: rockchip: rkcanfd_handle_rx_fifo_overflow_int(): bail out if skb cannot be allocated

In reply to Marc Kleine-Budde

From: Robin van der Gracht <[email protected]>

Fix NULL pointer check in rkcanfd_handle_rx_fifo_overflow_int() to bail out if skb cannot be allocated.

Fixes ff60bfbaf67f ("can: rockchip_canfd: add driver for Rockchip CAN-FD controller")
---
 drivers/net/can/rockchip/rockchip_canfd-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/rockchip/rockchip_canfd-core.c +1 -1
index df18c85fc078..d9a937ba126c 100644
@@ -622,7 +622,7 @@ rkcanfd_handle_rx_fifo_overflow_int(struct rkcanfd_priv *priv)
 	netdev_dbg(priv->ndev, "RX-FIFO overflow\n");
 
 	skb = rkcanfd_alloc_can_err_skb(priv, &cf, &timestamp);
-	if (skb)
+	if (!skb)
 		return 0;
 
 	rkcanfd_get_berr_counter_corrected(priv, &bec);
Signature · 1 line
2.47.2