* [PATCH net 1/4] Revert "can: raw: instantly reject unsupported CAN frames"
2026-01-15 8:57 [PATCH net 0/4] pull-request: can 2026-01-15 Marc Kleine-Budde
@ 2026-01-15 8:57 ` Marc Kleine-Budde
2026-01-15 12:20 ` patchwork-bot+netdevbpf
2026-01-15 13:18 ` Arnd Bergmann
2026-01-15 8:57 ` [PATCH net 2/4] can: propagate CAN device capabilities via ml_priv Marc Kleine-Budde
` (3 subsequent siblings)
4 siblings, 2 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2026-01-15 8:57 UTC (permalink / raw)
To: netdev
Cc: davem, kuba, linux-can, kernel, Oliver Hartkopp,
Marc Kleine-Budde, Arnd Bergmann, Vincent Mailhol
From: Oliver Hartkopp <socketcan@hartkopp.net>
This reverts commit 1a620a723853a0f49703c317d52dc6b9602cbaa8
and its follow-up fixes for the introduced dependency issues.
commit 1a620a723853 ("can: raw: instantly reject unsupported CAN frames")
commit cb2dc6d2869a ("can: Kconfig: select CAN driver infrastructure by default")
commit 6abd4577bccc ("can: fix build dependency")
commit 5a5aff6338c0 ("can: fix build dependency")
The entire problem was caused by the requirement that a new network layer
feature needed to know about the protocol capabilities of the CAN devices.
Instead of accessing CAN device internal data structures which caused the
dependency problems a better approach has been developed which makes use of
CAN specific ml_priv data which is accessible from both sides.
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Vincent Mailhol <mailhol@kernel.org>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://patch.msgid.link/20260109144135.8495-2-socketcan@hartkopp.net
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/Kconfig | 7 +++--
drivers/net/can/Makefile | 2 +-
drivers/net/can/dev/Makefile | 5 ++--
include/linux/can/dev.h | 7 -----
net/can/raw.c | 54 ++++++------------------------------
5 files changed, 17 insertions(+), 58 deletions(-)
diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
index cfaea6178a71..e15e320db476 100644
--- a/drivers/net/can/Kconfig
+++ b/drivers/net/can/Kconfig
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: GPL-2.0-only
menuconfig CAN_DEV
- bool "CAN Device Drivers"
+ tristate "CAN Device Drivers"
default y
depends on CAN
help
@@ -17,7 +17,10 @@ menuconfig CAN_DEV
virtual ones. If you own such devices or plan to use the virtual CAN
interfaces to develop applications, say Y here.
-if CAN_DEV && CAN
+ To compile as a module, choose M here: the module will be called
+ can-dev.
+
+if CAN_DEV
config CAN_VCAN
tristate "Virtual Local CAN Interface (vcan)"
diff --git a/drivers/net/can/Makefile b/drivers/net/can/Makefile
index 37e2f1a2faec..d7bc10a6b8ea 100644
--- a/drivers/net/can/Makefile
+++ b/drivers/net/can/Makefile
@@ -7,7 +7,7 @@ obj-$(CONFIG_CAN_VCAN) += vcan.o
obj-$(CONFIG_CAN_VXCAN) += vxcan.o
obj-$(CONFIG_CAN_SLCAN) += slcan/
-obj-$(CONFIG_CAN_DEV) += dev/
+obj-y += dev/
obj-y += esd/
obj-y += rcar/
obj-y += rockchip/
diff --git a/drivers/net/can/dev/Makefile b/drivers/net/can/dev/Makefile
index 64226acf0f3d..633687d6b6c0 100644
--- a/drivers/net/can/dev/Makefile
+++ b/drivers/net/can/dev/Makefile
@@ -1,8 +1,9 @@
# SPDX-License-Identifier: GPL-2.0
-obj-$(CONFIG_CAN) += can-dev.o
+obj-$(CONFIG_CAN_DEV) += can-dev.o
+
+can-dev-y += skb.o
-can-dev-$(CONFIG_CAN_DEV) += skb.o
can-dev-$(CONFIG_CAN_CALC_BITTIMING) += calc_bittiming.o
can-dev-$(CONFIG_CAN_NETLINK) += bittiming.o
can-dev-$(CONFIG_CAN_NETLINK) += dev.o
diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
index f6416a56e95d..52c8be5c160e 100644
--- a/include/linux/can/dev.h
+++ b/include/linux/can/dev.h
@@ -111,14 +111,7 @@ struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max,
void free_candev(struct net_device *dev);
/* a candev safe wrapper around netdev_priv */
-#if IS_ENABLED(CONFIG_CAN_NETLINK)
struct can_priv *safe_candev_priv(struct net_device *dev);
-#else
-static inline struct can_priv *safe_candev_priv(struct net_device *dev)
-{
- return NULL;
-}
-#endif
int open_candev(struct net_device *dev);
void close_candev(struct net_device *dev);
diff --git a/net/can/raw.c b/net/can/raw.c
index be1ef7cf4204..f36a83d3447c 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -892,58 +892,20 @@ static void raw_put_canxl_vcid(struct raw_sock *ro, struct sk_buff *skb)
}
}
-static inline bool raw_dev_cc_enabled(struct net_device *dev,
- struct can_priv *priv)
+static unsigned int raw_check_txframe(struct raw_sock *ro, struct sk_buff *skb, int mtu)
{
- /* The CANXL-only mode disables error-signalling on the CAN bus
- * which is needed to send CAN CC/FD frames
- */
- if (priv)
- return !can_dev_in_xl_only_mode(priv);
-
- /* virtual CAN interfaces always support CAN CC */
- return true;
-}
-
-static inline bool raw_dev_fd_enabled(struct net_device *dev,
- struct can_priv *priv)
-{
- /* check FD ctrlmode on real CAN interfaces */
- if (priv)
- return (priv->ctrlmode & CAN_CTRLMODE_FD);
-
- /* check MTU for virtual CAN FD interfaces */
- return (READ_ONCE(dev->mtu) >= CANFD_MTU);
-}
-
-static inline bool raw_dev_xl_enabled(struct net_device *dev,
- struct can_priv *priv)
-{
- /* check XL ctrlmode on real CAN interfaces */
- if (priv)
- return (priv->ctrlmode & CAN_CTRLMODE_XL);
-
- /* check MTU for virtual CAN XL interfaces */
- return can_is_canxl_dev_mtu(READ_ONCE(dev->mtu));
-}
-
-static unsigned int raw_check_txframe(struct raw_sock *ro, struct sk_buff *skb,
- struct net_device *dev)
-{
- struct can_priv *priv = safe_candev_priv(dev);
-
- /* Classical CAN */
- if (can_is_can_skb(skb) && raw_dev_cc_enabled(dev, priv))
+ /* Classical CAN -> no checks for flags and device capabilities */
+ if (can_is_can_skb(skb))
return CAN_MTU;
- /* CAN FD */
+ /* CAN FD -> needs to be enabled and a CAN FD or CAN XL device */
if (ro->fd_frames && can_is_canfd_skb(skb) &&
- raw_dev_fd_enabled(dev, priv))
+ (mtu == CANFD_MTU || can_is_canxl_dev_mtu(mtu)))
return CANFD_MTU;
- /* CAN XL */
+ /* CAN XL -> needs to be enabled and a CAN XL device */
if (ro->xl_frames && can_is_canxl_skb(skb) &&
- raw_dev_xl_enabled(dev, priv))
+ can_is_canxl_dev_mtu(mtu))
return CANXL_MTU;
return 0;
@@ -999,7 +961,7 @@ static int raw_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
err = -EINVAL;
/* check for valid CAN (CC/FD/XL) frame content */
- txmtu = raw_check_txframe(ro, skb, dev);
+ txmtu = raw_check_txframe(ro, skb, READ_ONCE(dev->mtu));
if (!txmtu)
goto free_skb;
base-commit: 3879cffd9d07aa0377c4b8835c4f64b4fb24ac78
--
2.51.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH net 1/4] Revert "can: raw: instantly reject unsupported CAN frames"
2026-01-15 8:57 ` [PATCH net 1/4] Revert "can: raw: instantly reject unsupported CAN frames" Marc Kleine-Budde
@ 2026-01-15 12:20 ` patchwork-bot+netdevbpf
2026-01-15 13:18 ` Arnd Bergmann
1 sibling, 0 replies; 11+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-01-15 12:20 UTC (permalink / raw)
To: Marc Kleine-Budde
Cc: netdev, davem, kuba, linux-can, kernel, socketcan, arnd, mailhol
Hello:
This series was applied to netdev/net.git (main)
by Marc Kleine-Budde <mkl@pengutronix.de>:
On Thu, 15 Jan 2026 09:57:08 +0100 you wrote:
> From: Oliver Hartkopp <socketcan@hartkopp.net>
>
> This reverts commit 1a620a723853a0f49703c317d52dc6b9602cbaa8
>
> and its follow-up fixes for the introduced dependency issues.
>
> commit 1a620a723853 ("can: raw: instantly reject unsupported CAN frames")
> commit cb2dc6d2869a ("can: Kconfig: select CAN driver infrastructure by default")
> commit 6abd4577bccc ("can: fix build dependency")
> commit 5a5aff6338c0 ("can: fix build dependency")
>
> [...]
Here is the summary with links:
- [net,1/4] Revert "can: raw: instantly reject unsupported CAN frames"
https://git.kernel.org/netdev/net/c/4650ff58a1b9
- [net,2/4] can: propagate CAN device capabilities via ml_priv
https://git.kernel.org/netdev/net/c/166e87329ce6
- [net,3/4] can: raw: instantly reject disabled CAN frames
https://git.kernel.org/netdev/net/c/faba5860fcf9
- [net,4/4] net: can: j1939: j1939_xtp_rx_rts_session_active(): deactivate session upon receiving the second rts
https://git.kernel.org/netdev/net/c/1809c82aa073
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] 11+ messages in thread* Re: [PATCH net 1/4] Revert "can: raw: instantly reject unsupported CAN frames"
2026-01-15 8:57 ` [PATCH net 1/4] Revert "can: raw: instantly reject unsupported CAN frames" Marc Kleine-Budde
2026-01-15 12:20 ` patchwork-bot+netdevbpf
@ 2026-01-15 13:18 ` Arnd Bergmann
1 sibling, 0 replies; 11+ messages in thread
From: Arnd Bergmann @ 2026-01-15 13:18 UTC (permalink / raw)
To: Marc Kleine-Budde, Netdev
Cc: David S . Miller, Jakub Kicinski, linux-can,
Pengutronix Kernel Team, Oliver Hartkopp, Vincent Mailhol
On Thu, Jan 15, 2026, at 09:57, Marc Kleine-Budde wrote:
> From: Oliver Hartkopp <socketcan@hartkopp.net>
>
> This reverts commit 1a620a723853a0f49703c317d52dc6b9602cbaa8
>
> and its follow-up fixes for the introduced dependency issues.
>
> commit 1a620a723853 ("can: raw: instantly reject unsupported CAN
> frames")
> commit cb2dc6d2869a ("can: Kconfig: select CAN driver infrastructure by
> default")
> commit 6abd4577bccc ("can: fix build dependency")
> commit 5a5aff6338c0 ("can: fix build dependency")
>
> The entire problem was caused by the requirement that a new network layer
> feature needed to know about the protocol capabilities of the CAN devices.
> Instead of accessing CAN device internal data structures which caused the
> dependency problems a better approach has been developed which makes use of
> CAN specific ml_priv data which is accessible from both sides.
>
> Cc: Marc Kleine-Budde <mkl@pengutronix.de>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Vincent Mailhol <mailhol@kernel.org>
> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
> Link: https://patch.msgid.link/20260109144135.8495-2-socketcan@hartkopp.net
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Acked-by: Arnd Bergmann <arnd@arndb.de>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH net 2/4] can: propagate CAN device capabilities via ml_priv
2026-01-15 8:57 [PATCH net 0/4] pull-request: can 2026-01-15 Marc Kleine-Budde
2026-01-15 8:57 ` [PATCH net 1/4] Revert "can: raw: instantly reject unsupported CAN frames" Marc Kleine-Budde
@ 2026-01-15 8:57 ` Marc Kleine-Budde
2026-01-15 8:57 ` [PATCH net 3/4] can: raw: instantly reject disabled CAN frames Marc Kleine-Budde
` (2 subsequent siblings)
4 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2026-01-15 8:57 UTC (permalink / raw)
To: netdev
Cc: davem, kuba, linux-can, kernel, Oliver Hartkopp,
Marc Kleine-Budde, Arnd Bergmann, Vincent Mailhol
From: Oliver Hartkopp <socketcan@hartkopp.net>
Commit 1a620a723853 ("can: raw: instantly reject unsupported CAN frames")
caused a sequence of dependency and linker fixes.
Instead of accessing CAN device internal data structures which caused the
dependency problems this patch introduces capability information into the
CAN specific ml_priv data which is accessible from both sides.
With this change the CAN network layer can check the required features and
the decoupling of the driver layer and network layer is restored.
Fixes: 1a620a723853 ("can: raw: instantly reject unsupported CAN frames")
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Vincent Mailhol <mailhol@kernel.org>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://patch.msgid.link/20260109144135.8495-3-socketcan@hartkopp.net
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/dev/dev.c | 27 +++++++++++++++++++++++++++
drivers/net/can/dev/netlink.c | 1 +
drivers/net/can/vcan.c | 15 +++++++++++++++
drivers/net/can/vxcan.c | 15 +++++++++++++++
include/linux/can/can-ml.h | 24 ++++++++++++++++++++++++
include/linux/can/dev.h | 1 +
6 files changed, 83 insertions(+)
diff --git a/drivers/net/can/dev/dev.c b/drivers/net/can/dev/dev.c
index 091f30e94c61..7ab9578f5b89 100644
--- a/drivers/net/can/dev/dev.c
+++ b/drivers/net/can/dev/dev.c
@@ -375,6 +375,32 @@ void can_set_default_mtu(struct net_device *dev)
}
}
+void can_set_cap_info(struct net_device *dev)
+{
+ struct can_priv *priv = netdev_priv(dev);
+ u32 can_cap;
+
+ if (can_dev_in_xl_only_mode(priv)) {
+ /* XL only mode => no CC/FD capability */
+ can_cap = CAN_CAP_XL;
+ } else {
+ /* mixed mode => CC + FD/XL capability */
+ can_cap = CAN_CAP_CC;
+
+ if (priv->ctrlmode & CAN_CTRLMODE_FD)
+ can_cap |= CAN_CAP_FD;
+
+ if (priv->ctrlmode & CAN_CTRLMODE_XL)
+ can_cap |= CAN_CAP_XL;
+ }
+
+ if (priv->ctrlmode & (CAN_CTRLMODE_LISTENONLY |
+ CAN_CTRLMODE_RESTRICTED))
+ can_cap |= CAN_CAP_RO;
+
+ can_set_cap(dev, can_cap);
+}
+
/* helper to define static CAN controller features at device creation time */
int can_set_static_ctrlmode(struct net_device *dev, u32 static_mode)
{
@@ -390,6 +416,7 @@ int can_set_static_ctrlmode(struct net_device *dev, u32 static_mode)
/* override MTU which was set by default in can_setup()? */
can_set_default_mtu(dev);
+ can_set_cap_info(dev);
return 0;
}
diff --git a/drivers/net/can/dev/netlink.c b/drivers/net/can/dev/netlink.c
index d6b0e686fb11..0498198a4696 100644
--- a/drivers/net/can/dev/netlink.c
+++ b/drivers/net/can/dev/netlink.c
@@ -377,6 +377,7 @@ static int can_ctrlmode_changelink(struct net_device *dev,
}
can_set_default_mtu(dev);
+ can_set_cap_info(dev);
return 0;
}
diff --git a/drivers/net/can/vcan.c b/drivers/net/can/vcan.c
index fdc662aea279..76e6b7b5c6a1 100644
--- a/drivers/net/can/vcan.c
+++ b/drivers/net/can/vcan.c
@@ -130,6 +130,19 @@ static netdev_tx_t vcan_tx(struct sk_buff *skb, struct net_device *dev)
return NETDEV_TX_OK;
}
+static void vcan_set_cap_info(struct net_device *dev)
+{
+ u32 can_cap = CAN_CAP_CC;
+
+ if (dev->mtu > CAN_MTU)
+ can_cap |= CAN_CAP_FD;
+
+ if (dev->mtu >= CANXL_MIN_MTU)
+ can_cap |= CAN_CAP_XL;
+
+ can_set_cap(dev, can_cap);
+}
+
static int vcan_change_mtu(struct net_device *dev, int new_mtu)
{
/* Do not allow changing the MTU while running */
@@ -141,6 +154,7 @@ static int vcan_change_mtu(struct net_device *dev, int new_mtu)
return -EINVAL;
WRITE_ONCE(dev->mtu, new_mtu);
+ vcan_set_cap_info(dev);
return 0;
}
@@ -162,6 +176,7 @@ static void vcan_setup(struct net_device *dev)
dev->tx_queue_len = 0;
dev->flags = IFF_NOARP;
can_set_ml_priv(dev, netdev_priv(dev));
+ vcan_set_cap_info(dev);
/* set flags according to driver capabilities */
if (echo)
diff --git a/drivers/net/can/vxcan.c b/drivers/net/can/vxcan.c
index b2c19f8c5f8e..f14c6f02b662 100644
--- a/drivers/net/can/vxcan.c
+++ b/drivers/net/can/vxcan.c
@@ -125,6 +125,19 @@ static int vxcan_get_iflink(const struct net_device *dev)
return iflink;
}
+static void vxcan_set_cap_info(struct net_device *dev)
+{
+ u32 can_cap = CAN_CAP_CC;
+
+ if (dev->mtu > CAN_MTU)
+ can_cap |= CAN_CAP_FD;
+
+ if (dev->mtu >= CANXL_MIN_MTU)
+ can_cap |= CAN_CAP_XL;
+
+ can_set_cap(dev, can_cap);
+}
+
static int vxcan_change_mtu(struct net_device *dev, int new_mtu)
{
/* Do not allow changing the MTU while running */
@@ -136,6 +149,7 @@ static int vxcan_change_mtu(struct net_device *dev, int new_mtu)
return -EINVAL;
WRITE_ONCE(dev->mtu, new_mtu);
+ vxcan_set_cap_info(dev);
return 0;
}
@@ -167,6 +181,7 @@ static void vxcan_setup(struct net_device *dev)
can_ml = netdev_priv(dev) + ALIGN(sizeof(struct vxcan_priv), NETDEV_ALIGN);
can_set_ml_priv(dev, can_ml);
+ vxcan_set_cap_info(dev);
}
/* forward declaration for rtnl_create_link() */
diff --git a/include/linux/can/can-ml.h b/include/linux/can/can-ml.h
index 8afa92d15a66..1e99fda2b380 100644
--- a/include/linux/can/can-ml.h
+++ b/include/linux/can/can-ml.h
@@ -46,6 +46,12 @@
#include <linux/list.h>
#include <linux/netdevice.h>
+/* exposed CAN device capabilities for network layer */
+#define CAN_CAP_CC BIT(0) /* CAN CC aka Classical CAN */
+#define CAN_CAP_FD BIT(1) /* CAN FD */
+#define CAN_CAP_XL BIT(2) /* CAN XL */
+#define CAN_CAP_RO BIT(3) /* read-only mode (LISTEN/RESTRICTED) */
+
#define CAN_SFF_RCV_ARRAY_SZ (1 << CAN_SFF_ID_BITS)
#define CAN_EFF_RCV_HASH_BITS 10
#define CAN_EFF_RCV_ARRAY_SZ (1 << CAN_EFF_RCV_HASH_BITS)
@@ -64,6 +70,7 @@ struct can_ml_priv {
#ifdef CAN_J1939
struct j1939_priv *j1939_priv;
#endif
+ u32 can_cap;
};
static inline struct can_ml_priv *can_get_ml_priv(struct net_device *dev)
@@ -77,4 +84,21 @@ static inline void can_set_ml_priv(struct net_device *dev,
netdev_set_ml_priv(dev, ml_priv, ML_PRIV_CAN);
}
+static inline bool can_cap_enabled(struct net_device *dev, u32 cap)
+{
+ struct can_ml_priv *can_ml = can_get_ml_priv(dev);
+
+ if (!can_ml)
+ return false;
+
+ return (can_ml->can_cap & cap);
+}
+
+static inline void can_set_cap(struct net_device *dev, u32 cap)
+{
+ struct can_ml_priv *can_ml = can_get_ml_priv(dev);
+
+ can_ml->can_cap = cap;
+}
+
#endif /* CAN_ML_H */
diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
index 52c8be5c160e..6d0710d6f571 100644
--- a/include/linux/can/dev.h
+++ b/include/linux/can/dev.h
@@ -116,6 +116,7 @@ struct can_priv *safe_candev_priv(struct net_device *dev);
int open_candev(struct net_device *dev);
void close_candev(struct net_device *dev);
void can_set_default_mtu(struct net_device *dev);
+void can_set_cap_info(struct net_device *dev);
int __must_check can_set_static_ctrlmode(struct net_device *dev,
u32 static_mode);
int can_hwtstamp_get(struct net_device *netdev,
--
2.51.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH net 3/4] can: raw: instantly reject disabled CAN frames
2026-01-15 8:57 [PATCH net 0/4] pull-request: can 2026-01-15 Marc Kleine-Budde
2026-01-15 8:57 ` [PATCH net 1/4] Revert "can: raw: instantly reject unsupported CAN frames" Marc Kleine-Budde
2026-01-15 8:57 ` [PATCH net 2/4] can: propagate CAN device capabilities via ml_priv Marc Kleine-Budde
@ 2026-01-15 8:57 ` Marc Kleine-Budde
2026-01-15 8:57 ` [PATCH net 4/4] net: can: j1939: j1939_xtp_rx_rts_session_active(): deactivate session upon receiving the second rts Marc Kleine-Budde
2026-01-16 2:51 ` [PATCH net 0/4] pull-request: can 2026-01-15 Jakub Kicinski
4 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2026-01-15 8:57 UTC (permalink / raw)
To: netdev
Cc: davem, kuba, linux-can, kernel, Oliver Hartkopp,
Marc Kleine-Budde, Arnd Bergmann, Vincent Mailhol
From: Oliver Hartkopp <socketcan@hartkopp.net>
For real CAN interfaces the CAN_CTRLMODE_FD and CAN_CTRLMODE_XL control
modes indicate whether an interface can handle those CAN FD/XL frames.
In the case a CAN XL interface is configured in CANXL-only mode with
disabled error-signalling neither CAN CC nor CAN FD frames can be sent.
The checks are now performed on CAN_RAW sockets to give an instant feedback
to the user when writing unsupported CAN frames to the interface or when
the CAN interface is in read-only mode.
Fixes: 1a620a723853 ("can: raw: instantly reject unsupported CAN frames")
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Vincent Mailhol <mailhol@kernel.org>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://patch.msgid.link/20260109144135.8495-4-socketcan@hartkopp.net
[mkl: fix dev reference leak]
Link: https://lore.kernel.org/all/0636c732-2e71-4633-8005-dfa85e1da445@hartkopp.net
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
net/can/raw.c | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/net/can/raw.c b/net/can/raw.c
index f36a83d3447c..12293363413c 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -49,8 +49,8 @@
#include <linux/if_arp.h>
#include <linux/skbuff.h>
#include <linux/can.h>
+#include <linux/can/can-ml.h>
#include <linux/can/core.h>
-#include <linux/can/dev.h> /* for can_is_canxl_dev_mtu() */
#include <linux/can/skb.h>
#include <linux/can/raw.h>
#include <net/sock.h>
@@ -892,20 +892,21 @@ static void raw_put_canxl_vcid(struct raw_sock *ro, struct sk_buff *skb)
}
}
-static unsigned int raw_check_txframe(struct raw_sock *ro, struct sk_buff *skb, int mtu)
+static unsigned int raw_check_txframe(struct raw_sock *ro, struct sk_buff *skb,
+ struct net_device *dev)
{
- /* Classical CAN -> no checks for flags and device capabilities */
- if (can_is_can_skb(skb))
+ /* Classical CAN */
+ if (can_is_can_skb(skb) && can_cap_enabled(dev, CAN_CAP_CC))
return CAN_MTU;
- /* CAN FD -> needs to be enabled and a CAN FD or CAN XL device */
+ /* CAN FD */
if (ro->fd_frames && can_is_canfd_skb(skb) &&
- (mtu == CANFD_MTU || can_is_canxl_dev_mtu(mtu)))
+ can_cap_enabled(dev, CAN_CAP_FD))
return CANFD_MTU;
- /* CAN XL -> needs to be enabled and a CAN XL device */
+ /* CAN XL */
if (ro->xl_frames && can_is_canxl_skb(skb) &&
- can_is_canxl_dev_mtu(mtu))
+ can_cap_enabled(dev, CAN_CAP_XL))
return CANXL_MTU;
return 0;
@@ -944,6 +945,12 @@ static int raw_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
if (!dev)
return -ENXIO;
+ /* no sending on a CAN device in read-only mode */
+ if (can_cap_enabled(dev, CAN_CAP_RO)) {
+ err = -EACCES;
+ goto put_dev;
+ }
+
skb = sock_alloc_send_skb(sk, size + sizeof(struct can_skb_priv),
msg->msg_flags & MSG_DONTWAIT, &err);
if (!skb)
@@ -961,7 +968,7 @@ static int raw_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
err = -EINVAL;
/* check for valid CAN (CC/FD/XL) frame content */
- txmtu = raw_check_txframe(ro, skb, READ_ONCE(dev->mtu));
+ txmtu = raw_check_txframe(ro, skb, dev);
if (!txmtu)
goto free_skb;
--
2.51.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH net 4/4] net: can: j1939: j1939_xtp_rx_rts_session_active(): deactivate session upon receiving the second rts
2026-01-15 8:57 [PATCH net 0/4] pull-request: can 2026-01-15 Marc Kleine-Budde
` (2 preceding siblings ...)
2026-01-15 8:57 ` [PATCH net 3/4] can: raw: instantly reject disabled CAN frames Marc Kleine-Budde
@ 2026-01-15 8:57 ` Marc Kleine-Budde
2026-01-16 2:51 ` [PATCH net 0/4] pull-request: can 2026-01-15 Jakub Kicinski
4 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2026-01-15 8:57 UTC (permalink / raw)
To: netdev
Cc: davem, kuba, linux-can, kernel, Tetsuo Handa, syzbot,
Oleksij Rempel, stable, Marc Kleine-Budde
From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Since j1939_session_deactivate_activate_next() in j1939_tp_rxtimer() is
called only when the timer is enabled, we need to call
j1939_session_deactivate_activate_next() if we cancelled the timer.
Otherwise, refcount for j1939_session leaks, which will later appear as
| unregister_netdevice: waiting for vcan0 to become free. Usage count = 2.
problem.
Reported-by: syzbot <syzbot+881d65229ca4f9ae8c84@syzkaller.appspotmail.com>
Closes: https://syzkaller.appspot.com/bug?extid=881d65229ca4f9ae8c84
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Tested-by: Oleksij Rempel <o.rempel@pengutronix.de>
Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>
Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol")
Link: https://patch.msgid.link/b1212653-8fa1-44e1-be9d-12f950fb3a07@I-love.SAKURA.ne.jp
Cc: stable@vger.kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
net/can/j1939/transport.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c
index 613a911dda10..8656ab388c83 100644
--- a/net/can/j1939/transport.c
+++ b/net/can/j1939/transport.c
@@ -1695,8 +1695,16 @@ static int j1939_xtp_rx_rts_session_active(struct j1939_session *session,
j1939_session_timers_cancel(session);
j1939_session_cancel(session, J1939_XTP_ABORT_BUSY);
- if (session->transmission)
+ if (session->transmission) {
j1939_session_deactivate_activate_next(session);
+ } else if (session->state == J1939_SESSION_WAITING_ABORT) {
+ /* Force deactivation for the receiver.
+ * If we rely on the timer starting in j1939_session_cancel,
+ * a second RTS call here will cancel that timer and fail
+ * to restart it because the state is already WAITING_ABORT.
+ */
+ j1939_session_deactivate_activate_next(session);
+ }
return -EBUSY;
}
--
2.51.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH net 0/4] pull-request: can 2026-01-15
2026-01-15 8:57 [PATCH net 0/4] pull-request: can 2026-01-15 Marc Kleine-Budde
` (3 preceding siblings ...)
2026-01-15 8:57 ` [PATCH net 4/4] net: can: j1939: j1939_xtp_rx_rts_session_active(): deactivate session upon receiving the second rts Marc Kleine-Budde
@ 2026-01-16 2:51 ` Jakub Kicinski
2026-01-16 7:34 ` Marc Kleine-Budde
2026-01-16 17:03 ` Marc Kleine-Budde
4 siblings, 2 replies; 11+ messages in thread
From: Jakub Kicinski @ 2026-01-16 2:51 UTC (permalink / raw)
To: Marc Kleine-Budde; +Cc: netdev, davem, linux-can, kernel
On Thu, 15 Jan 2026 09:57:07 +0100 Marc Kleine-Budde wrote:
> Hello netdev-team,
>
> this is a pull request of 4 patches for net/main, it super-seeds the
> "can 2026-01-14" pull request. The dev refcount leak in patch #3 is
> fixed.
>
> The first 3 patches are by Oliver Hartkopp and revert the approach to
> instantly reject unsupported CAN frames introduced in
> net-next-for-v6.19 and replace it by placing the needed data into the
> CAN specific ml_priv.
>
> The last patch is by Tetsuo Handa and fixes a J1939 refcount leak for
> j1939_session in session deactivation upon receiving the second RTS.
Hi Marc!
Was the AI wrong here
https://lore.kernel.org/all/20260110223836.3890248-1-kuba@kernel.org/
or that fix is still in the works?
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH net 0/4] pull-request: can 2026-01-15
2026-01-16 2:51 ` [PATCH net 0/4] pull-request: can 2026-01-15 Jakub Kicinski
@ 2026-01-16 7:34 ` Marc Kleine-Budde
2026-01-16 17:03 ` Marc Kleine-Budde
1 sibling, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2026-01-16 7:34 UTC (permalink / raw)
To: Jakub Kicinski; +Cc: netdev, davem, linux-can, kernel
[-- Attachment #1: Type: text/plain, Size: 547 bytes --]
Hello Jakub,
On 15.01.2026 18:51:10, Jakub Kicinski wrote:
> Was the AI wrong here
> https://lore.kernel.org/all/20260110223836.3890248-1-kuba@kernel.org/
> or that fix is still in the works?
The AI was probably right, today I'll look into the issue.
regards,
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: 488 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH net 0/4] pull-request: can 2026-01-15
2026-01-16 2:51 ` [PATCH net 0/4] pull-request: can 2026-01-15 Jakub Kicinski
2026-01-16 7:34 ` Marc Kleine-Budde
@ 2026-01-16 17:03 ` Marc Kleine-Budde
2026-01-17 17:30 ` Jakub Kicinski
1 sibling, 1 reply; 11+ messages in thread
From: Marc Kleine-Budde @ 2026-01-16 17:03 UTC (permalink / raw)
To: Jakub Kicinski; +Cc: netdev, davem, linux-can, kernel
[-- Attachment #1: Type: text/plain, Size: 673 bytes --]
On 15.01.2026 18:51:10, Jakub Kicinski wrote:
> Hi Marc!
>
> Was the AI wrong here
> https://lore.kernel.org/all/20260110223836.3890248-1-kuba@kernel.org/
> or that fix is still in the works?
AI was correct, the proposed fix was correct. The patch will be included
in my next PR:
| https://lore.kernel.org/all/20260116-can_usb-fix-reanchor-v1-1-9d74e7289225@pengutronix.de/
regards,
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: 488 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread