All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] team: reject ARPHRD_CAN devices in team_port_add
@ 2026-07-23  4:00 Jiale Yao
  2026-07-28  1:24 ` Jakub Kicinski
  2026-07-28  7:11 ` Oliver Hartkopp
  0 siblings, 2 replies; 4+ messages in thread
From: Jiale Yao @ 2026-07-23  4:00 UTC (permalink / raw)
  To: Jiri Pirko, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, linux-kernel
  Cc: Jiale Yao

Enslaving a CAN device (e.g. vxcan) to a team master triggers a
NULL pointer dereference in can_rx_unregister() inside
net/can/af_can.c.

During team_port_add(), the code only checks IFF_LOOPBACK but
does not reject ARPHRD_CAN devices.  After passing this gate,
team_dev_type_check_change() calls team_setup_by_port() which
sets dev->type = port_dev->type, adopting the CAN type for the
team device.  However, CAN devices operate on a fundamentally
different Layer 2 architecture, relying on the CAN mid-layer
private data structure (can_ml_priv) instead of standard
Ethernet structures.  Since the team driver never initializes
can_ml_priv, subsequent CAN subsystem operations -- such as
closing an ISOTP socket bound to the team interface via
isotp_release() -- reach can_rx_unregister() which dereferences
the NULL can_ml_priv, causing a kernel crash.

The bonding driver already rejects CAN devices since commit
8ba68464e478 ("bonding: refuse to enslave CAN devices").
Team, as a sibling aggregation path, needs the same protection.

Fix this by adding an explicit ARPHRD_CAN check in
team_port_add(), directly after the IFF_LOOPBACK guard,
consistent with the approach taken in bond_enslave().

Fixes: 1d76efe1577b ("team: add support for non-ethernet devices")
Assisted-by: Claude:deepseek-v4-pro
Signed-off-by: Jiale Yao <yaojiale02@163.com>
---
 drivers/net/team/team_core.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/net/team/team_core.c b/drivers/net/team/team_core.c
index feaa75fbf8fc..38f88a836010 100644
--- a/drivers/net/team/team_core.c
+++ b/drivers/net/team/team_core.c
@@ -1224,6 +1224,13 @@ static int team_port_add(struct team *team, struct net_device *port_dev,
 		return -EINVAL;
 	}
 
+	if (port_dev->type == ARPHRD_CAN) {
+		NL_SET_ERR_MSG(extack, "CAN device can't be added as a team port");
+		netdev_err(dev, "Device %s is CAN device. CAN devices can't be added as a team port\n",
+			   portname);
+		return -EINVAL;
+	}
+
 	if (netif_is_team_port(port_dev)) {
 		NL_SET_ERR_MSG(extack, "Device is already a port of a team device");
 		netdev_err(dev, "Device %s is already a port "
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] team: reject ARPHRD_CAN devices in team_port_add
  2026-07-23  4:00 [PATCH] team: reject ARPHRD_CAN devices in team_port_add Jiale Yao
@ 2026-07-28  1:24 ` Jakub Kicinski
  2026-07-28  5:18   ` jiale yao
  2026-07-28  7:11 ` Oliver Hartkopp
  1 sibling, 1 reply; 4+ messages in thread
From: Jakub Kicinski @ 2026-07-28  1:24 UTC (permalink / raw)
  To: Jiale Yao
  Cc: Jiri Pirko, Andrew Lunn, David S. Miller, Eric Dumazet,
	Paolo Abeni, netdev, linux-kernel

On Thu, 23 Jul 2026 12:00:32 +0800 Jiale Yao wrote:
> Enslaving a CAN device (e.g. vxcan) to a team master triggers a
> NULL pointer dereference in can_rx_unregister() inside
> net/can/af_can.c.

Gemini review says that similar issue is possible with
ARPHRD_IEEE802154 devices, could you double check that,
see if there are any others, and all these in a single
patch?
-- 
pw-bot: cr

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re:Re: [PATCH] team: reject ARPHRD_CAN devices in team_port_add
  2026-07-28  1:24 ` Jakub Kicinski
@ 2026-07-28  5:18   ` jiale yao
  0 siblings, 0 replies; 4+ messages in thread
From: jiale yao @ 2026-07-28  5:18 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Jiri Pirko, Andrew Lunn, David S. Miller, Eric Dumazet,
	Paolo Abeni, netdev, linux-kernel

Hi

Sure, I will check, and send v2 patch if there are any others.

Jiale Yao

At 2026-07-28 09:24:47, "Jakub Kicinski" <kuba@kernel.org> wrote:
>On Thu, 23 Jul 2026 12:00:32 +0800 Jiale Yao wrote:
>> Enslaving a CAN device (e.g. vxcan) to a team master triggers a
>> NULL pointer dereference in can_rx_unregister() inside
>> net/can/af_can.c.
>
>Gemini review says that similar issue is possible with
>ARPHRD_IEEE802154 devices, could you double check that,
>see if there are any others, and all these in a single
>patch?
>-- 
>pw-bot: cr

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] team: reject ARPHRD_CAN devices in team_port_add
  2026-07-23  4:00 [PATCH] team: reject ARPHRD_CAN devices in team_port_add Jiale Yao
  2026-07-28  1:24 ` Jakub Kicinski
@ 2026-07-28  7:11 ` Oliver Hartkopp
  1 sibling, 0 replies; 4+ messages in thread
From: Oliver Hartkopp @ 2026-07-28  7:11 UTC (permalink / raw)
  To: Jiale Yao, Jiri Pirko, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, linux-kernel



On 23.07.26 06:00, Jiale Yao wrote:
> Enslaving a CAN device (e.g. vxcan) to a team master triggers a
> NULL pointer dereference in can_rx_unregister() inside
> net/can/af_can.c.
> 
> During team_port_add(), the code only checks IFF_LOOPBACK but
> does not reject ARPHRD_CAN devices.  After passing this gate,
> team_dev_type_check_change() calls team_setup_by_port() which
> sets dev->type = port_dev->type, adopting the CAN type for the
> team device.  However, CAN devices operate on a fundamentally
> different Layer 2 architecture, relying on the CAN mid-layer
> private data structure (can_ml_priv) instead of standard
> Ethernet structures.  Since the team driver never initializes
> can_ml_priv, subsequent CAN subsystem operations -- such as
> closing an ISOTP socket bound to the team interface via
> isotp_release() -- reach can_rx_unregister() which dereferences
> the NULL can_ml_priv, causing a kernel crash.
> 
> The bonding driver already rejects CAN devices since commit
> 8ba68464e478 ("bonding: refuse to enslave CAN devices").
> Team, as a sibling aggregation path, needs the same protection.
> 
> Fix this by adding an explicit ARPHRD_CAN check in
> team_port_add(), directly after the IFF_LOOPBACK guard,
> consistent with the approach taken in bond_enslave().
> 
> Fixes: 1d76efe1577b ("team: add support for non-ethernet devices")
> Assisted-by: Claude:deepseek-v4-pro
> Signed-off-by: Jiale Yao <yaojiale02@163.com>

Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>

I did not know that the team driver had the same approach.
Thanks for catching this!

Best regards,
Oliver

> ---
>   drivers/net/team/team_core.c | 7 +++++++
>   1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/net/team/team_core.c b/drivers/net/team/team_core.c
> index feaa75fbf8fc..38f88a836010 100644
> --- a/drivers/net/team/team_core.c
> +++ b/drivers/net/team/team_core.c
> @@ -1224,6 +1224,13 @@ static int team_port_add(struct team *team, struct net_device *port_dev,
>   		return -EINVAL;
>   	}
>   
> +	if (port_dev->type == ARPHRD_CAN) {
> +		NL_SET_ERR_MSG(extack, "CAN device can't be added as a team port");
> +		netdev_err(dev, "Device %s is CAN device. CAN devices can't be added as a team port\n",
> +			   portname);
> +		return -EINVAL;
> +	}
> +
>   	if (netif_is_team_port(port_dev)) {
>   		NL_SET_ERR_MSG(extack, "Device is already a port of a team device");
>   		netdev_err(dev, "Device %s is already a port "


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-07-28  7:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-23  4:00 [PATCH] team: reject ARPHRD_CAN devices in team_port_add Jiale Yao
2026-07-28  1:24 ` Jakub Kicinski
2026-07-28  5:18   ` jiale yao
2026-07-28  7:11 ` Oliver Hartkopp

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.