Skip to content

Commit a6d190f

Browse files
vincent-mailholmarckleinebudde
authored andcommitted
can: skb: drop tx skb if in listen only mode
Frames can be directly injected to a can driver via the packet socket. By doing so, it is possible to reach the net_device_ops::ndo_start_xmit function even if the driver is configured in listen only mode. Add a check in can_dropped_invalid_skb() to discard the skb if CAN_CTRLMODE_LISTENONLY is set. Link: https://lore.kernel.org/all/[email protected] Signed-off-by: Vincent Mailhol <[email protected]> Acked-by: Max Staudt <[email protected]> Tested-by: Oliver Hartkopp <[email protected]> Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent ccd8a93 commit a6d190f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

drivers/net/can/dev/skb.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include <linux/can/dev.h>
8+
#include <linux/can/netlink.h>
89
#include <linux/module.h>
910

1011
#define MOD_DESC "CAN device driver interface"
@@ -293,6 +294,7 @@ static bool can_skb_headroom_valid(struct net_device *dev, struct sk_buff *skb)
293294
bool can_dropped_invalid_skb(struct net_device *dev, struct sk_buff *skb)
294295
{
295296
const struct canfd_frame *cfd = (struct canfd_frame *)skb->data;
297+
struct can_priv *priv = netdev_priv(dev);
296298

297299
if (skb->protocol == htons(ETH_P_CAN)) {
298300
if (unlikely(skb->len != CAN_MTU ||
@@ -306,8 +308,13 @@ bool can_dropped_invalid_skb(struct net_device *dev, struct sk_buff *skb)
306308
goto inval_skb;
307309
}
308310

309-
if (!can_skb_headroom_valid(dev, skb))
311+
if (!can_skb_headroom_valid(dev, skb)) {
312+
goto inval_skb;
313+
} else if (priv->ctrlmode & CAN_CTRLMODE_LISTENONLY) {
314+
netdev_info_once(dev,
315+
"interface in listen only mode, dropping skb\n");
310316
goto inval_skb;
317+
}
311318

312319
return false;
313320

0 commit comments

Comments
 (0)