Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

can: dev: can_dev_dropped_skb: drop CAN FD skbs if FD is off

Currently, the CAN FD skb validation logic is based on the MTU: the
interface is deemed FD capable if and only if its MTU is greater or
equal to CANFD_MTU.

This logic is showing its limit with the introduction of CAN XL. For
example, consider the two scenarios below:

1. An interface configured with CAN FD on and CAN XL on

2. An interface configured with CAN FD off and CAN XL on

In those two scenarios, the interfaces would have the same MTU:

CANXL_MTU

making it impossible to differentiate which one has CAN FD turned on
and which one has it off.

Because of the limitation, the only non-UAPI-breaking workaround is to
do the check at the device level using the can_priv->ctrlmode flags.
Unfortunately, the virtual interfaces (vcan, vxcan), which do not have
a can_priv, are left behind.

Add a check on the CAN_CTRLMODE_FD flag in can_dev_dropped_skb() and
drop FD frames whenever the feature is turned off.

Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://patch.msgid.link/20251126-canxl-v8-3-e7e3eb74f889@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

authored by

Vincent Mailhol and committed by
Marc Kleine-Budde
d037d05c 585a4f22

+11 -3
+11 -3
include/linux/can/dev.h
··· 103 103 if (priv->ctrlmode & CAN_CTRLMODE_LISTENONLY) { 104 104 netdev_info_once(dev, 105 105 "interface in listen only mode, dropping skb\n"); 106 - kfree_skb(skb); 107 - dev->stats.tx_dropped++; 108 - return true; 106 + goto invalid_skb; 107 + } 108 + 109 + if (!(priv->ctrlmode & CAN_CTRLMODE_FD) && can_is_canfd_skb(skb)) { 110 + netdev_info_once(dev, "CAN FD is disabled, dropping skb\n"); 111 + goto invalid_skb; 109 112 } 110 113 111 114 return can_dropped_invalid_skb(dev, skb); 115 + 116 + invalid_skb: 117 + kfree_skb(skb); 118 + dev->stats.tx_dropped++; 119 + return true; 112 120 } 113 121 114 122 void can_setup(struct net_device *dev);