Netdev List
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, linux-can@vger.kernel.org,
	kernel@pengutronix.de, Vincent Mailhol <mailhol@kernel.org>,
	stable@kernel.org, Marc Kleine-Budde <mkl@pengutronix.de>
Subject: [PATCH net 01/16] can: dev: can_dropped_invalid_skb: drop CAN XL frames on non-CAN XL devices
Date: Tue, 29 Sep 2026 22:43:51 +0200	[thread overview]
Message-ID: <20260929210700.1183036-2-mkl@pengutronix.de> (raw)
In-Reply-To: <20260929210700.1183036-1-mkl@pengutronix.de>

From: Vincent Mailhol <mailhol@kernel.org>

Sending a PF_PACKET bypasses the CAN framework logic and can directly
reach a CAN driver's xmit() function. The PF_PACKET framework only
checks that skb->len does not exceed the net_device MTU.

For a CAN device that is not CAN XL capable, anything above CANFD_MTU
(72 bytes) is therefore dropped before it reaches the driver. However,
CAN XL frames are variable length. can_is_canxl_skb() accepts lengths in
the range CANXL_HDR_SIZE + CANXL_MIN_DLEN up to CANXL_MTU, i.e. 13 to
2060 bytes.

As a result, an ETH_P_CANXL skb with a length between 13 and 72 bytes
can pass both the MTU and the can_dropped_invalid_skb() checks.

A driver that does not support CAN XL will interpret canxl_frame->flags
as a length because of the overlap with can_frame->len. And because
CANXL_XLF is set, the resulting length is between 128 and 255. For
drivers that do not check can_frame->len before copying can_frame->data,
as most drivers do, this results in a buffer overflow of up to 247
bytes.

Drop ETH_P_CANXL skbs if the device does not have the CAN_CAP_XL
capability. Keep can_is_canxl_skb() for the validation of CAN XL skbs.

Closes: https://sashiko.dev/#/patchset/20260731-master-v5-0-5b27029dee20@qq.com?part=1
Fixes: fb08cba12b52 ("can: canxl: update CAN infrastructure for CAN XL frames")
Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
Link: https://patch.msgid.link/20260731-drop_canxl_frames-v1-1-7387b70353b3@kernel.org
Cc: stable@kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/dev/skb.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/dev/skb.c b/drivers/net/can/dev/skb.c
index 95fcdc1026f8..4f7a189de265 100644
--- a/drivers/net/can/dev/skb.c
+++ b/drivers/net/can/dev/skb.c
@@ -4,6 +4,7 @@
  * Copyright (C) 2008-2009 Wolfgang Grandegger <wg@grandegger.com>
  */
 
+#include <linux/can/can-ml.h>
 #include <linux/can/dev.h>
 #include <linux/module.h>
 #include <net/can.h>
@@ -384,7 +385,7 @@ bool can_dropped_invalid_skb(struct net_device *dev, struct sk_buff *skb)
 		break;
 
 	case ETH_P_CANXL:
-		if (!can_is_canxl_skb(skb))
+		if (!can_cap_enabled(dev, CAN_CAP_XL) || !can_is_canxl_skb(skb))
 			goto inval_skb;
 		break;
 

base-commit: a7bfaba4823e3c165bb2004c74eff7c096672bc7
-- 
2.53.0


  reply	other threads:[~2026-09-29 21:07 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-29 20:43 [PATCH net 0/16] pull-request: can 2026-09-29 Marc Kleine-Budde
2026-09-29 20:43 ` Marc Kleine-Budde [this message]
2026-09-29 21:13   ` [PATCH net 01/16] can: dev: can_dropped_invalid_skb: drop CAN XL frames on non-CAN XL devices netdev-bot+sinfo
2026-09-29 20:43 ` [PATCH net 02/16] can: dev: init_can_skb(): restore skb header initialization Marc Kleine-Budde
2026-09-29 20:43 ` [PATCH net 03/16] can: remove CAN filters independent from namespace Marc Kleine-Budde
2026-09-29 20:43 ` [PATCH net 04/16] can: convert unreliable ARPHRD_CAN type checks to robust can_get_ml_priv() Marc Kleine-Budde
2026-09-29 20:43 ` [PATCH net 05/16] can: fix unique skb identifier regression under RPS Marc Kleine-Budde
2026-09-29 20:43 ` [PATCH net 06/16] can: isotp: check the frame type, not just the length Marc Kleine-Budde
2026-09-29 20:43 ` [PATCH net 07/16] can: m_can: pci: add missing pm_runtime_dont_use_autosuspend() call Marc Kleine-Budde
2026-09-29 20:43 ` [PATCH net 08/16] can: xilinx_can: set CAN FD flags on received frames Marc Kleine-Budde
2026-09-29 20:43 ` [PATCH net 09/16] can: mcp251xfd: mcp251xfd_probe(): reject devices without match data Marc Kleine-Budde
2026-09-29 20:44 ` [PATCH net 10/16] usb: f81604: fix struct f81604_int_data size mismatch Marc Kleine-Budde
2026-09-29 20:44 ` [PATCH net 11/16] can: gs_usb: kill RX URBs before destroying the netdevs Marc Kleine-Budde
2026-09-29 20:44 ` [PATCH net 12/16] can: gs_usb: add workarounds for HScanT USB to CAN adapter Marc Kleine-Budde
2026-09-29 20:44 ` [PATCH net 13/16] can: kvaser_usb: validate command format before parsing in hydra receive path Marc Kleine-Budde
2026-09-29 20:44 ` [PATCH net 14/16] can: peak_usb: fix missing CAN_ERR_FLAG when reporting error counters Marc Kleine-Budde
2026-09-29 20:44 ` [PATCH net 15/16] can: rx-offload: add IRQ queue flush predicate Marc Kleine-Budde
2026-09-29 20:44 ` [PATCH net 16/16] can: mcp251xfd: flush RX offload queue during long IRQs Marc Kleine-Budde
2026-10-01  8:40 ` [PATCH net 0/16] pull-request: can 2026-09-29 Paolo Abeni
2026-10-01  9:23   ` Oliver Hartkopp
2026-10-01 10:13     ` Paolo Abeni
2026-10-01 10:28       ` Oliver Hartkopp
2026-10-01 10:55         ` Marc Kleine-Budde
2026-10-01 15:25           ` Jakub Kicinski
2026-10-01 15:38             ` Marc Kleine-Budde
2026-10-01 18:19               ` Jakub Kicinski
2026-10-05  7:28                 ` Oliver Hartkopp
2026-10-05  9:20                   ` Marc Kleine-Budde
2026-10-05  9:24                     ` Oliver Hartkopp
2026-10-05  9:32                       ` Marc Kleine-Budde
2026-10-01 15:28 ` Jakub Kicinski
2026-10-01 15:37   ` Marc Kleine-Budde

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260929210700.1183036-2-mkl@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=davem@davemloft.net \
    --cc=kernel@pengutronix.de \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=mailhol@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stable@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox