* [PATCH net 0/7] pull-request: can 2025-09-23
@ 2025-09-23 7:32 Marc Kleine-Budde
2025-09-23 7:32 ` [PATCH net 1/7] can: hi311x: fix null pointer dereference when resuming from sleep before interface was enabled Marc Kleine-Budde
` (6 more replies)
0 siblings, 7 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2025-09-23 7:32 UTC (permalink / raw)
To: netdev; +Cc: davem, kuba, linux-can, kernel
Hello netdev-team,
this is a pull request of 7 patches for net/main.
The 1st patch is by Chen Yufeng and fixes a potential NULL pointer
deref in the hi311x driver.
Duy Nguyen contributes a patch for the rcar_canfd driver to fix the
controller mode setting.
The next 4 patches are by Vincent Mailhol and populate the
ndo_change_mtu(( callback in the etas_es58x, hi311x, sun4i_can and
mcba_usb driver to prevent buffer overflows.
Stéphane Grosjean's patch for the peak_usb driver fixes a
shift-out-of-bounds issue.
regards,
Marc
---
The following changes since commit cbf658dd09419f1ef9de11b9604e950bdd5c170b:
Merge tag 'net-6.17-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net (2025-09-18 10:22:02 -0700)
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.17-20250923
for you to fetch changes up to c443be70aaee42c2d1d251e0329e0a69dd96ae54:
can: peak_usb: fix shift-out-of-bounds issue (2025-09-19 19:17:37 +0200)
----------------------------------------------------------------
linux-can-fixes-for-6.17-20250923
----------------------------------------------------------------
Chen Yufeng (1):
can: hi311x: fix null pointer dereference when resuming from sleep before interface was enabled
Duy Nguyen (1):
can: rcar_canfd: Fix controller mode setting
Marc Kleine-Budde (1):
Merge patch series "can: populate ndo_change_mtu() to prevent buffer overflow"
Stéphane Grosjean (1):
can: peak_usb: fix shift-out-of-bounds issue
Vincent Mailhol (4):
can: etas_es58x: populate ndo_change_mtu() to prevent buffer overflow
can: hi311x: populate ndo_change_mtu() to prevent buffer overflow
can: sun4i_can: populate ndo_change_mtu() to prevent buffer overflow
can: mcba_usb: populate ndo_change_mtu() to prevent buffer overflow
drivers/net/can/rcar/rcar_canfd.c | 7 +++---
drivers/net/can/spi/hi311x.c | 34 +++++++++++++++-------------
drivers/net/can/sun4i_can.c | 1 +
drivers/net/can/usb/etas_es58x/es58x_core.c | 3 ++-
drivers/net/can/usb/mcba_usb.c | 1 +
drivers/net/can/usb/peak_usb/pcan_usb_core.c | 2 +-
6 files changed, 27 insertions(+), 21 deletions(-)
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH net 1/7] can: hi311x: fix null pointer dereference when resuming from sleep before interface was enabled
2025-09-23 7:32 [PATCH net 0/7] pull-request: can 2025-09-23 Marc Kleine-Budde
@ 2025-09-23 7:32 ` Marc Kleine-Budde
2025-09-24 0:00 ` patchwork-bot+netdevbpf
2025-09-24 8:53 ` [PATCH net 1/7] can: hi311x: fix null pointer dereference when resuming from sleep before interface was enabled: manual merge Matthieu Baerts
2025-09-23 7:32 ` [PATCH net 2/7] can: rcar_canfd: Fix controller mode setting Marc Kleine-Budde
` (5 subsequent siblings)
6 siblings, 2 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2025-09-23 7:32 UTC (permalink / raw)
To: netdev; +Cc: davem, kuba, linux-can, kernel, Chen Yufeng, Marc Kleine-Budde
From: Chen Yufeng <chenyufeng@iie.ac.cn>
This issue is similar to the vulnerability in the `mcp251x` driver,
which was fixed in commit 03c427147b2d ("can: mcp251x: fix resume from
sleep before interface was brought up").
In the `hi311x` driver, when the device resumes from sleep, the driver
schedules `priv->restart_work`. However, if the network interface was
not previously enabled, the `priv->wq` (workqueue) is not allocated and
initialized, leading to a null pointer dereference.
To fix this, we move the allocation and initialization of the workqueue
from the `hi3110_open` function to the `hi3110_can_probe` function.
This ensures that the workqueue is properly initialized before it is
used during device resume. And added logic to destroy the workqueue
in the error handling paths of `hi3110_can_probe` and in the
`hi3110_can_remove` function to prevent resource leaks.
Signed-off-by: Chen Yufeng <chenyufeng@iie.ac.cn>
Link: https://patch.msgid.link/20250911150820.250-1-chenyufeng@iie.ac.cn
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/spi/hi311x.c | 33 +++++++++++++++++----------------
1 file changed, 17 insertions(+), 16 deletions(-)
diff --git a/drivers/net/can/spi/hi311x.c b/drivers/net/can/spi/hi311x.c
index 09ae218315d7..96bef8f384c4 100644
--- a/drivers/net/can/spi/hi311x.c
+++ b/drivers/net/can/spi/hi311x.c
@@ -545,8 +545,6 @@ static int hi3110_stop(struct net_device *net)
priv->force_quit = 1;
free_irq(spi->irq, priv);
- destroy_workqueue(priv->wq);
- priv->wq = NULL;
mutex_lock(&priv->hi3110_lock);
@@ -770,34 +768,23 @@ static int hi3110_open(struct net_device *net)
goto out_close;
}
- priv->wq = alloc_workqueue("hi3110_wq", WQ_FREEZABLE | WQ_MEM_RECLAIM,
- 0);
- if (!priv->wq) {
- ret = -ENOMEM;
- goto out_free_irq;
- }
- INIT_WORK(&priv->tx_work, hi3110_tx_work_handler);
- INIT_WORK(&priv->restart_work, hi3110_restart_work_handler);
-
ret = hi3110_hw_reset(spi);
if (ret)
- goto out_free_wq;
+ goto out_free_irq;
ret = hi3110_setup(net);
if (ret)
- goto out_free_wq;
+ goto out_free_irq;
ret = hi3110_set_normal_mode(spi);
if (ret)
- goto out_free_wq;
+ goto out_free_irq;
netif_wake_queue(net);
mutex_unlock(&priv->hi3110_lock);
return 0;
- out_free_wq:
- destroy_workqueue(priv->wq);
out_free_irq:
free_irq(spi->irq, priv);
hi3110_hw_sleep(spi);
@@ -908,6 +895,15 @@ static int hi3110_can_probe(struct spi_device *spi)
if (ret)
goto out_clk;
+ priv->wq = alloc_workqueue("hi3110_wq", WQ_FREEZABLE | WQ_MEM_RECLAIM,
+ 0);
+ if (!priv->wq) {
+ ret = -ENOMEM;
+ goto out_clk;
+ }
+ INIT_WORK(&priv->tx_work, hi3110_tx_work_handler);
+ INIT_WORK(&priv->restart_work, hi3110_restart_work_handler);
+
priv->spi = spi;
mutex_init(&priv->hi3110_lock);
@@ -943,6 +939,8 @@ static int hi3110_can_probe(struct spi_device *spi)
return 0;
error_probe:
+ destroy_workqueue(priv->wq);
+ priv->wq = NULL;
hi3110_power_enable(priv->power, 0);
out_clk:
@@ -963,6 +961,9 @@ static void hi3110_can_remove(struct spi_device *spi)
hi3110_power_enable(priv->power, 0);
+ destroy_workqueue(priv->wq);
+ priv->wq = NULL;
+
clk_disable_unprepare(priv->clk);
free_candev(net);
base-commit: cbf658dd09419f1ef9de11b9604e950bdd5c170b
--
2.51.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH net 2/7] can: rcar_canfd: Fix controller mode setting
2025-09-23 7:32 [PATCH net 0/7] pull-request: can 2025-09-23 Marc Kleine-Budde
2025-09-23 7:32 ` [PATCH net 1/7] can: hi311x: fix null pointer dereference when resuming from sleep before interface was enabled Marc Kleine-Budde
@ 2025-09-23 7:32 ` Marc Kleine-Budde
2025-09-23 7:32 ` [PATCH net 3/7] can: etas_es58x: populate ndo_change_mtu() to prevent buffer overflow Marc Kleine-Budde
` (4 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2025-09-23 7:32 UTC (permalink / raw)
To: netdev
Cc: davem, kuba, linux-can, kernel, Duy Nguyen, Tranh Ha,
Marc Kleine-Budde
From: Duy Nguyen <duy.nguyen.rh@renesas.com>
Driver configures register to choose controller mode before
setting all channels to reset mode leading to failure.
The patch corrects operation of mode setting.
Signed-off-by: Duy Nguyen <duy.nguyen.rh@renesas.com>
Signed-off-by: Tranh Ha <tranh.ha.xb@renesas.com>
Link: https://patch.msgid.link/TYWPR01MB87434739F83E27EDCD23DF44B416A@TYWPR01MB8743.jpnprd01.prod.outlook.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/rcar/rcar_canfd.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/net/can/rcar/rcar_canfd.c b/drivers/net/can/rcar/rcar_canfd.c
index b3c8c592fb0e..7e8b1d2f1af6 100644
--- a/drivers/net/can/rcar/rcar_canfd.c
+++ b/drivers/net/can/rcar/rcar_canfd.c
@@ -823,9 +823,6 @@ static int rcar_canfd_reset_controller(struct rcar_canfd_global *gpriv)
/* Reset Global error flags */
rcar_canfd_write(gpriv->base, RCANFD_GERFL, 0x0);
- /* Set the controller into appropriate mode */
- rcar_canfd_set_mode(gpriv);
-
/* Transition all Channels to reset mode */
for_each_set_bit(ch, &gpriv->channels_mask, gpriv->info->max_channels) {
rcar_canfd_clear_bit(gpriv->base,
@@ -844,6 +841,10 @@ static int rcar_canfd_reset_controller(struct rcar_canfd_global *gpriv)
return err;
}
}
+
+ /* Set the controller into appropriate mode */
+ rcar_canfd_set_mode(gpriv);
+
return 0;
}
--
2.51.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH net 3/7] can: etas_es58x: populate ndo_change_mtu() to prevent buffer overflow
2025-09-23 7:32 [PATCH net 0/7] pull-request: can 2025-09-23 Marc Kleine-Budde
2025-09-23 7:32 ` [PATCH net 1/7] can: hi311x: fix null pointer dereference when resuming from sleep before interface was enabled Marc Kleine-Budde
2025-09-23 7:32 ` [PATCH net 2/7] can: rcar_canfd: Fix controller mode setting Marc Kleine-Budde
@ 2025-09-23 7:32 ` Marc Kleine-Budde
2025-09-23 7:32 ` [PATCH net 4/7] can: hi311x: " Marc Kleine-Budde
` (3 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2025-09-23 7:32 UTC (permalink / raw)
To: netdev; +Cc: davem, kuba, linux-can, kernel, Vincent Mailhol,
Marc Kleine-Budde
From: Vincent Mailhol <mailhol@kernel.org>
Sending an PF_PACKET allows to bypass the CAN framework logic and to
directly reach the xmit() function of a CAN driver. The only check
which is performed by the PF_PACKET framework is to make sure that
skb->len fits the interface's MTU.
Unfortunately, because the etas_es58x driver does not populate its
net_device_ops->ndo_change_mtu(), it is possible for an attacker to
configure an invalid MTU by doing, for example:
$ ip link set can0 mtu 9999
After doing so, the attacker could open a PF_PACKET socket using the
ETH_P_CANXL protocol:
socket(PF_PACKET, SOCK_RAW, htons(ETH_P_CANXL));
to inject a malicious CAN XL frames. For example:
struct canxl_frame frame = {
.flags = 0xff,
.len = 2048,
};
The CAN drivers' xmit() function are calling can_dev_dropped_skb() to
check that the skb is valid, unfortunately under above conditions, the
malicious packet is able to go through can_dev_dropped_skb() checks:
1. the skb->protocol is set to ETH_P_CANXL which is valid (the
function does not check the actual device capabilities).
2. the length is a valid CAN XL length.
And so, es58x_start_xmit() receives a CAN XL frame which it is not
able to correctly handle and will thus misinterpret it as a CAN(FD)
frame.
This can result in a buffer overflow. For example, using the es581.4
variant, the frame will be dispatched to es581_4_tx_can_msg(), go
through the last check at the beginning of this function:
if (can_is_canfd_skb(skb))
return -EMSGSIZE;
and reach this line:
memcpy(tx_can_msg->data, cf->data, cf->len);
Here, cf->len corresponds to the flags field of the CAN XL frame. In
our previous example, we set canxl_frame->flags to 0xff. Because the
maximum expected length is 8, a buffer overflow of 247 bytes occurs!
Populate net_device_ops->ndo_change_mtu() to ensure that the
interface's MTU can not be set to anything bigger than CAN_MTU or
CANFD_MTU (depending on the device capabilities). By fixing the root
cause, this prevents the buffer overflow.
Fixes: 8537257874e9 ("can: etas_es58x: add core support for ETAS ES58X CAN USB interfaces")
Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
Link: https://patch.msgid.link/20250918-can-fix-mtu-v1-1-0d1cada9393b@kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/usb/etas_es58x/es58x_core.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/net/can/usb/etas_es58x/es58x_core.c b/drivers/net/can/usb/etas_es58x/es58x_core.c
index db1acf6d504c..adc91873c083 100644
--- a/drivers/net/can/usb/etas_es58x/es58x_core.c
+++ b/drivers/net/can/usb/etas_es58x/es58x_core.c
@@ -7,7 +7,7 @@
*
* Copyright (c) 2019 Robert Bosch Engineering and Business Solutions. All rights reserved.
* Copyright (c) 2020 ETAS K.K.. All rights reserved.
- * Copyright (c) 2020-2022 Vincent Mailhol <mailhol.vincent@wanadoo.fr>
+ * Copyright (c) 2020-2025 Vincent Mailhol <mailhol@kernel.org>
*/
#include <linux/unaligned.h>
@@ -1977,6 +1977,7 @@ static const struct net_device_ops es58x_netdev_ops = {
.ndo_stop = es58x_stop,
.ndo_start_xmit = es58x_start_xmit,
.ndo_eth_ioctl = can_eth_ioctl_hwts,
+ .ndo_change_mtu = can_change_mtu,
};
static const struct ethtool_ops es58x_ethtool_ops = {
--
2.51.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH net 4/7] can: hi311x: populate ndo_change_mtu() to prevent buffer overflow
2025-09-23 7:32 [PATCH net 0/7] pull-request: can 2025-09-23 Marc Kleine-Budde
` (2 preceding siblings ...)
2025-09-23 7:32 ` [PATCH net 3/7] can: etas_es58x: populate ndo_change_mtu() to prevent buffer overflow Marc Kleine-Budde
@ 2025-09-23 7:32 ` Marc Kleine-Budde
2025-09-23 7:32 ` [PATCH net 5/7] can: sun4i_can: " Marc Kleine-Budde
` (2 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2025-09-23 7:32 UTC (permalink / raw)
To: netdev; +Cc: davem, kuba, linux-can, kernel, Vincent Mailhol,
Marc Kleine-Budde
From: Vincent Mailhol <mailhol@kernel.org>
Sending an PF_PACKET allows to bypass the CAN framework logic and to
directly reach the xmit() function of a CAN driver. The only check
which is performed by the PF_PACKET framework is to make sure that
skb->len fits the interface's MTU.
Unfortunately, because the sun4i_can driver does not populate its
net_device_ops->ndo_change_mtu(), it is possible for an attacker to
configure an invalid MTU by doing, for example:
$ ip link set can0 mtu 9999
After doing so, the attacker could open a PF_PACKET socket using the
ETH_P_CANXL protocol:
socket(PF_PACKET, SOCK_RAW, htons(ETH_P_CANXL))
to inject a malicious CAN XL frames. For example:
struct canxl_frame frame = {
.flags = 0xff,
.len = 2048,
};
The CAN drivers' xmit() function are calling can_dev_dropped_skb() to
check that the skb is valid, unfortunately under above conditions, the
malicious packet is able to go through can_dev_dropped_skb() checks:
1. the skb->protocol is set to ETH_P_CANXL which is valid (the
function does not check the actual device capabilities).
2. the length is a valid CAN XL length.
And so, hi3110_hard_start_xmit() receives a CAN XL frame which it is
not able to correctly handle and will thus misinterpret it as a CAN
frame. The driver will consume frame->len as-is with no further
checks.
This can result in a buffer overflow later on in hi3110_hw_tx() on
this line:
memcpy(buf + HI3110_FIFO_EXT_DATA_OFF,
frame->data, frame->len);
Here, frame->len corresponds to the flags field of the CAN XL frame.
In our previous example, we set canxl_frame->flags to 0xff. Because
the maximum expected length is 8, a buffer overflow of 247 bytes
occurs!
Populate net_device_ops->ndo_change_mtu() to ensure that the
interface's MTU can not be set to anything bigger than CAN_MTU. By
fixing the root cause, this prevents the buffer overflow.
Fixes: 57e83fb9b746 ("can: hi311x: Add Holt HI-311x CAN driver")
Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
Link: https://patch.msgid.link/20250918-can-fix-mtu-v1-2-0d1cada9393b@kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/spi/hi311x.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/net/can/spi/hi311x.c b/drivers/net/can/spi/hi311x.c
index 96bef8f384c4..963ea8510dd9 100644
--- a/drivers/net/can/spi/hi311x.c
+++ b/drivers/net/can/spi/hi311x.c
@@ -799,6 +799,7 @@ static const struct net_device_ops hi3110_netdev_ops = {
.ndo_open = hi3110_open,
.ndo_stop = hi3110_stop,
.ndo_start_xmit = hi3110_hard_start_xmit,
+ .ndo_change_mtu = can_change_mtu,
};
static const struct ethtool_ops hi3110_ethtool_ops = {
--
2.51.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH net 5/7] can: sun4i_can: populate ndo_change_mtu() to prevent buffer overflow
2025-09-23 7:32 [PATCH net 0/7] pull-request: can 2025-09-23 Marc Kleine-Budde
` (3 preceding siblings ...)
2025-09-23 7:32 ` [PATCH net 4/7] can: hi311x: " Marc Kleine-Budde
@ 2025-09-23 7:32 ` Marc Kleine-Budde
2025-09-23 7:32 ` [PATCH net 6/7] can: mcba_usb: " Marc Kleine-Budde
2025-09-23 7:32 ` [PATCH net 7/7] can: peak_usb: fix shift-out-of-bounds issue Marc Kleine-Budde
6 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2025-09-23 7:32 UTC (permalink / raw)
To: netdev; +Cc: davem, kuba, linux-can, kernel, Vincent Mailhol,
Marc Kleine-Budde
From: Vincent Mailhol <mailhol@kernel.org>
Sending an PF_PACKET allows to bypass the CAN framework logic and to
directly reach the xmit() function of a CAN driver. The only check
which is performed by the PF_PACKET framework is to make sure that
skb->len fits the interface's MTU.
Unfortunately, because the sun4i_can driver does not populate its
net_device_ops->ndo_change_mtu(), it is possible for an attacker to
configure an invalid MTU by doing, for example:
$ ip link set can0 mtu 9999
After doing so, the attacker could open a PF_PACKET socket using the
ETH_P_CANXL protocol:
socket(PF_PACKET, SOCK_RAW, htons(ETH_P_CANXL))
to inject a malicious CAN XL frames. For example:
struct canxl_frame frame = {
.flags = 0xff,
.len = 2048,
};
The CAN drivers' xmit() function are calling can_dev_dropped_skb() to
check that the skb is valid, unfortunately under above conditions, the
malicious packet is able to go through can_dev_dropped_skb() checks:
1. the skb->protocol is set to ETH_P_CANXL which is valid (the
function does not check the actual device capabilities).
2. the length is a valid CAN XL length.
And so, sun4ican_start_xmit() receives a CAN XL frame which it is not
able to correctly handle and will thus misinterpret it as a CAN frame.
This can result in a buffer overflow. The driver will consume cf->len
as-is with no further checks on this line:
dlc = cf->len;
Here, cf->len corresponds to the flags field of the CAN XL frame. In
our previous example, we set canxl_frame->flags to 0xff. Because the
maximum expected length is 8, a buffer overflow of 247 bytes occurs a
couple line below when doing:
for (i = 0; i < dlc; i++)
writel(cf->data[i], priv->base + (dreg + i * 4));
Populate net_device_ops->ndo_change_mtu() to ensure that the
interface's MTU can not be set to anything bigger than CAN_MTU. By
fixing the root cause, this prevents the buffer overflow.
Fixes: 0738eff14d81 ("can: Allwinner A10/A20 CAN Controller support - Kernel module")
Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
Link: https://patch.msgid.link/20250918-can-fix-mtu-v1-3-0d1cada9393b@kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/sun4i_can.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/net/can/sun4i_can.c b/drivers/net/can/sun4i_can.c
index 6fcb301ef611..53bfd873de9b 100644
--- a/drivers/net/can/sun4i_can.c
+++ b/drivers/net/can/sun4i_can.c
@@ -768,6 +768,7 @@ static const struct net_device_ops sun4ican_netdev_ops = {
.ndo_open = sun4ican_open,
.ndo_stop = sun4ican_close,
.ndo_start_xmit = sun4ican_start_xmit,
+ .ndo_change_mtu = can_change_mtu,
};
static const struct ethtool_ops sun4ican_ethtool_ops = {
--
2.51.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH net 6/7] can: mcba_usb: populate ndo_change_mtu() to prevent buffer overflow
2025-09-23 7:32 [PATCH net 0/7] pull-request: can 2025-09-23 Marc Kleine-Budde
` (4 preceding siblings ...)
2025-09-23 7:32 ` [PATCH net 5/7] can: sun4i_can: " Marc Kleine-Budde
@ 2025-09-23 7:32 ` Marc Kleine-Budde
2025-09-23 7:32 ` [PATCH net 7/7] can: peak_usb: fix shift-out-of-bounds issue Marc Kleine-Budde
6 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2025-09-23 7:32 UTC (permalink / raw)
To: netdev; +Cc: davem, kuba, linux-can, kernel, Vincent Mailhol,
Marc Kleine-Budde
From: Vincent Mailhol <mailhol@kernel.org>
Sending an PF_PACKET allows to bypass the CAN framework logic and to
directly reach the xmit() function of a CAN driver. The only check
which is performed by the PF_PACKET framework is to make sure that
skb->len fits the interface's MTU.
Unfortunately, because the mcba_usb driver does not populate its
net_device_ops->ndo_change_mtu(), it is possible for an attacker to
configure an invalid MTU by doing, for example:
$ ip link set can0 mtu 9999
After doing so, the attacker could open a PF_PACKET socket using the
ETH_P_CANXL protocol:
socket(PF_PACKET, SOCK_RAW, htons(ETH_P_CANXL))
to inject a malicious CAN XL frames. For example:
struct canxl_frame frame = {
.flags = 0xff,
.len = 2048,
};
The CAN drivers' xmit() function are calling can_dev_dropped_skb() to
check that the skb is valid, unfortunately under above conditions, the
malicious packet is able to go through can_dev_dropped_skb() checks:
1. the skb->protocol is set to ETH_P_CANXL which is valid (the
function does not check the actual device capabilities).
2. the length is a valid CAN XL length.
And so, mcba_usb_start_xmit() receives a CAN XL frame which it is not
able to correctly handle and will thus misinterpret it as a CAN frame.
This can result in a buffer overflow. The driver will consume cf->len
as-is with no further checks on these lines:
usb_msg.dlc = cf->len;
memcpy(usb_msg.data, cf->data, usb_msg.dlc);
Here, cf->len corresponds to the flags field of the CAN XL frame. In
our previous example, we set canxl_frame->flags to 0xff. Because the
maximum expected length is 8, a buffer overflow of 247 bytes occurs!
Populate net_device_ops->ndo_change_mtu() to ensure that the
interface's MTU can not be set to anything bigger than CAN_MTU. By
fixing the root cause, this prevents the buffer overflow.
Fixes: 51f3baad7de9 ("can: mcba_usb: Add support for Microchip CAN BUS Analyzer")
Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
Link: https://patch.msgid.link/20250918-can-fix-mtu-v1-4-0d1cada9393b@kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/usb/mcba_usb.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/net/can/usb/mcba_usb.c b/drivers/net/can/usb/mcba_usb.c
index 41c0a1c399bf..1f9b915094e6 100644
--- a/drivers/net/can/usb/mcba_usb.c
+++ b/drivers/net/can/usb/mcba_usb.c
@@ -761,6 +761,7 @@ static const struct net_device_ops mcba_netdev_ops = {
.ndo_open = mcba_usb_open,
.ndo_stop = mcba_usb_close,
.ndo_start_xmit = mcba_usb_start_xmit,
+ .ndo_change_mtu = can_change_mtu,
};
static const struct ethtool_ops mcba_ethtool_ops = {
--
2.51.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH net 7/7] can: peak_usb: fix shift-out-of-bounds issue
2025-09-23 7:32 [PATCH net 0/7] pull-request: can 2025-09-23 Marc Kleine-Budde
` (5 preceding siblings ...)
2025-09-23 7:32 ` [PATCH net 6/7] can: mcba_usb: " Marc Kleine-Budde
@ 2025-09-23 7:32 ` Marc Kleine-Budde
6 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2025-09-23 7:32 UTC (permalink / raw)
To: netdev
Cc: davem, kuba, linux-can, kernel, Stéphane Grosjean,
Marc Kleine-Budde
From: Stéphane Grosjean <stephane.grosjean@hms-networks.com>
Explicitly uses a 64-bit constant when the number of bits used for its
shifting is 32 (which is the case for PC CAN FD interfaces supported by
this driver).
Signed-off-by: Stéphane Grosjean <stephane.grosjean@hms-networks.com>
Link: https://patch.msgid.link/20250918132413.30071-1-stephane.grosjean@free.fr
Reported-by: Marc Kleine-Budde <mkl@pengutronix.de>
Closes: https://lore.kernel.org/20250917-aboriginal-refined-honeybee-82b1aa-mkl@pengutronix.de
Fixes: bb4785551f64 ("can: usb: PEAK-System Technik USB adapters driver core")
[mkl: update subject, apply manually]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/usb/peak_usb/pcan_usb_core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
index 117637b9b995..dd5caa1c302b 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
@@ -111,7 +111,7 @@ void peak_usb_update_ts_now(struct peak_time_ref *time_ref, u32 ts_now)
u32 delta_ts = time_ref->ts_dev_2 - time_ref->ts_dev_1;
if (time_ref->ts_dev_2 < time_ref->ts_dev_1)
- delta_ts &= (1 << time_ref->adapter->ts_used_bits) - 1;
+ delta_ts &= (1ULL << time_ref->adapter->ts_used_bits) - 1;
time_ref->ts_total += delta_ts;
}
--
2.51.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH net 1/7] can: hi311x: fix null pointer dereference when resuming from sleep before interface was enabled
2025-09-23 7:32 ` [PATCH net 1/7] can: hi311x: fix null pointer dereference when resuming from sleep before interface was enabled Marc Kleine-Budde
@ 2025-09-24 0:00 ` patchwork-bot+netdevbpf
2025-09-24 8:53 ` [PATCH net 1/7] can: hi311x: fix null pointer dereference when resuming from sleep before interface was enabled: manual merge Matthieu Baerts
1 sibling, 0 replies; 11+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-09-24 0:00 UTC (permalink / raw)
To: Marc Kleine-Budde; +Cc: netdev, davem, kuba, linux-can, kernel, chenyufeng
Hello:
This series was applied to netdev/net.git (main)
by Marc Kleine-Budde <mkl@pengutronix.de>:
On Tue, 23 Sep 2025 09:32:47 +0200 you wrote:
> From: Chen Yufeng <chenyufeng@iie.ac.cn>
>
> This issue is similar to the vulnerability in the `mcp251x` driver,
> which was fixed in commit 03c427147b2d ("can: mcp251x: fix resume from
> sleep before interface was brought up").
>
> In the `hi311x` driver, when the device resumes from sleep, the driver
> schedules `priv->restart_work`. However, if the network interface was
> not previously enabled, the `priv->wq` (workqueue) is not allocated and
> initialized, leading to a null pointer dereference.
>
> [...]
Here is the summary with links:
- [net,1/7] can: hi311x: fix null pointer dereference when resuming from sleep before interface was enabled
https://git.kernel.org/netdev/net/c/6b6968084721
- [net,2/7] can: rcar_canfd: Fix controller mode setting
https://git.kernel.org/netdev/net/c/5cff263606a1
- [net,3/7] can: etas_es58x: populate ndo_change_mtu() to prevent buffer overflow
https://git.kernel.org/netdev/net/c/38c0abad45b1
- [net,4/7] can: hi311x: populate ndo_change_mtu() to prevent buffer overflow
https://git.kernel.org/netdev/net/c/ac1c7656fa71
- [net,5/7] can: sun4i_can: populate ndo_change_mtu() to prevent buffer overflow
https://git.kernel.org/netdev/net/c/61da0bd4102c
- [net,6/7] can: mcba_usb: populate ndo_change_mtu() to prevent buffer overflow
https://git.kernel.org/netdev/net/c/17c8d794527f
- [net,7/7] can: peak_usb: fix shift-out-of-bounds issue
https://git.kernel.org/netdev/net/c/c443be70aaee
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/7] can: hi311x: fix null pointer dereference when resuming from sleep before interface was enabled: manual merge
2025-09-23 7:32 ` [PATCH net 1/7] can: hi311x: fix null pointer dereference when resuming from sleep before interface was enabled Marc Kleine-Budde
2025-09-24 0:00 ` patchwork-bot+netdevbpf
@ 2025-09-24 8:53 ` Matthieu Baerts
2025-09-24 9:03 ` Marc Kleine-Budde
1 sibling, 1 reply; 11+ messages in thread
From: Matthieu Baerts @ 2025-09-24 8:53 UTC (permalink / raw)
To: Marc Kleine-Budde, netdev
Cc: davem, kuba, linux-can, kernel, Chen Yufeng, Stephen Rothwell
[-- Attachment #1: Type: text/plain, Size: 2226 bytes --]
Hello,
On 23/09/2025 08:32, Marc Kleine-Budde wrote:
> From: Chen Yufeng <chenyufeng@iie.ac.cn>
>
> This issue is similar to the vulnerability in the `mcp251x` driver,
> which was fixed in commit 03c427147b2d ("can: mcp251x: fix resume from
> sleep before interface was brought up").
>
> In the `hi311x` driver, when the device resumes from sleep, the driver
> schedules `priv->restart_work`. However, if the network interface was
> not previously enabled, the `priv->wq` (workqueue) is not allocated and
> initialized, leading to a null pointer dereference.
>
> To fix this, we move the allocation and initialization of the workqueue
> from the `hi3110_open` function to the `hi3110_can_probe` function.
> This ensures that the workqueue is properly initialized before it is
> used during device resume. And added logic to destroy the workqueue
> in the error handling paths of `hi3110_can_probe` and in the
> `hi3110_can_remove` function to prevent resource leaks.
FYI, we got a small conflict when merging 'net' in 'net-next' in the
MPTCP tree due to this patch applied in 'net':
6b6968084721 ("can: hi311x: fix null pointer dereference when resuming
from sleep before interface was enabled")
and this one from 'net-next':
27ce71e1ce81 ("net: WQ_PERCPU added to alloc_workqueue users")
----- Generic Message -----
The best is to avoid conflicts between 'net' and 'net-next' trees but if
they cannot be avoided when preparing patches, a note about how to fix
them is much appreciated.
The conflict has been resolved on our side[1] and the resolution we
suggest is attached to this email. Please report any issues linked to
this conflict resolution as it might be used by others. If you worked on
the mentioned patches, don't hesitate to ACK this conflict resolution.
---------------------------
Regarding this conflict, I simply added "WQ_PERCPU" flag to
alloc_workqueue() in hi3110_can_probe() -- the new location after the
modification in 'net' -- instead of in hi3110_open().
Rerere cache is available in [2].
Cheers,
Matt
1: https://github.com/multipath-tcp/mptcp_net-next/commit/4ef39a01f1f0
2: https://github.com/multipath-tcp/mptcp-upstream-rr-cache/commit/1a8b8
--
Sponsored by the NGI0 Core fund.
[-- Attachment #2: 4ef39a01f1f0d195d0d4daae6312d1ae71d59188.patch --]
[-- Type: text/x-patch, Size: 682 bytes --]
diff --cc drivers/net/can/spi/hi311x.c
index 96f23311b4ee,963ea8510dd9..6d4b643e135f
--- a/drivers/net/can/spi/hi311x.c
+++ b/drivers/net/can/spi/hi311x.c
@@@ -909,6 -896,15 +896,16 @@@ static int hi3110_can_probe(struct spi_
if (ret)
goto out_clk;
- priv->wq = alloc_workqueue("hi3110_wq", WQ_FREEZABLE | WQ_MEM_RECLAIM,
++ priv->wq = alloc_workqueue("hi3110_wq",
++ WQ_FREEZABLE | WQ_MEM_RECLAIM | WQ_PERCPU,
+ 0);
+ if (!priv->wq) {
+ ret = -ENOMEM;
+ goto out_clk;
+ }
+ INIT_WORK(&priv->tx_work, hi3110_tx_work_handler);
+ INIT_WORK(&priv->restart_work, hi3110_restart_work_handler);
+
priv->spi = spi;
mutex_init(&priv->hi3110_lock);
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH net 1/7] can: hi311x: fix null pointer dereference when resuming from sleep before interface was enabled: manual merge
2025-09-24 8:53 ` [PATCH net 1/7] can: hi311x: fix null pointer dereference when resuming from sleep before interface was enabled: manual merge Matthieu Baerts
@ 2025-09-24 9:03 ` Marc Kleine-Budde
0 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2025-09-24 9:03 UTC (permalink / raw)
To: Matthieu Baerts
Cc: netdev, davem, kuba, linux-can, kernel, Chen Yufeng,
Stephen Rothwell
[-- Attachment #1: Type: text/plain, Size: 2548 bytes --]
On 24.09.2025 09:53:42, Matthieu Baerts wrote:
> Hello,
>
> On 23/09/2025 08:32, Marc Kleine-Budde wrote:
> > From: Chen Yufeng <chenyufeng@iie.ac.cn>
> >
> > This issue is similar to the vulnerability in the `mcp251x` driver,
> > which was fixed in commit 03c427147b2d ("can: mcp251x: fix resume from
> > sleep before interface was brought up").
> >
> > In the `hi311x` driver, when the device resumes from sleep, the driver
> > schedules `priv->restart_work`. However, if the network interface was
> > not previously enabled, the `priv->wq` (workqueue) is not allocated and
> > initialized, leading to a null pointer dereference.
> >
> > To fix this, we move the allocation and initialization of the workqueue
> > from the `hi3110_open` function to the `hi3110_can_probe` function.
> > This ensures that the workqueue is properly initialized before it is
> > used during device resume. And added logic to destroy the workqueue
> > in the error handling paths of `hi3110_can_probe` and in the
> > `hi3110_can_remove` function to prevent resource leaks.
>
> FYI, we got a small conflict when merging 'net' in 'net-next' in the
> MPTCP tree due to this patch applied in 'net':
Thanks for the heads up!
> 6b6968084721 ("can: hi311x: fix null pointer dereference when resuming
> from sleep before interface was enabled")
>
> and this one from 'net-next':
>
> 27ce71e1ce81 ("net: WQ_PERCPU added to alloc_workqueue users")
>
> ----- Generic Message -----
> The best is to avoid conflicts between 'net' and 'net-next' trees but if
> they cannot be avoided when preparing patches, a note about how to fix
> them is much appreciated.
> The conflict has been resolved on our side[1] and the resolution we
> suggest is attached to this email. Please report any issues linked to
> this conflict resolution as it might be used by others. If you worked on
> the mentioned patches, don't hesitate to ACK this conflict resolution.
> ---------------------------
>
> Regarding this conflict, I simply added "WQ_PERCPU" flag to
> alloc_workqueue() in hi3110_can_probe() -- the new location after the
> modification in 'net' -- instead of in hi3110_open().
>
> Rerere cache is available in [2].
Looks good to me!
Thanks,
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
end of thread, other threads:[~2025-09-24 9:04 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-23 7:32 [PATCH net 0/7] pull-request: can 2025-09-23 Marc Kleine-Budde
2025-09-23 7:32 ` [PATCH net 1/7] can: hi311x: fix null pointer dereference when resuming from sleep before interface was enabled Marc Kleine-Budde
2025-09-24 0:00 ` patchwork-bot+netdevbpf
2025-09-24 8:53 ` [PATCH net 1/7] can: hi311x: fix null pointer dereference when resuming from sleep before interface was enabled: manual merge Matthieu Baerts
2025-09-24 9:03 ` Marc Kleine-Budde
2025-09-23 7:32 ` [PATCH net 2/7] can: rcar_canfd: Fix controller mode setting Marc Kleine-Budde
2025-09-23 7:32 ` [PATCH net 3/7] can: etas_es58x: populate ndo_change_mtu() to prevent buffer overflow Marc Kleine-Budde
2025-09-23 7:32 ` [PATCH net 4/7] can: hi311x: " Marc Kleine-Budde
2025-09-23 7:32 ` [PATCH net 5/7] can: sun4i_can: " Marc Kleine-Budde
2025-09-23 7:32 ` [PATCH net 6/7] can: mcba_usb: " Marc Kleine-Budde
2025-09-23 7:32 ` [PATCH net 7/7] can: peak_usb: fix shift-out-of-bounds issue Marc Kleine-Budde
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).