mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net v2] bonding: reject a non-Ethernet 802.3ad slave even when the type matches
@ 2026-11-19  3:31 Kyuwon Cho
  2026-11-19 10:01 ` Hangbin Liu
  2026-11-23  3:32 ` netdev-bot+sashiko
  0 siblings, 2 replies; 4+ messages in thread
From: Kyuwon Cho @ 2026-11-19  3:31 UTC (permalink / raw)
  To: netdev
  Cc: Jay Vosburgh, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, linux-kernel

Commit c84fcb79e5db ("bonding: limit BOND_MODE_8023AD to Ethernet
devices") rejects a non-Ethernet first slave in 802.3ad mode, but only
when enslaving it changes the bond's type. A bond keeps the type of its
last slave after that slave is released, so a bond that once had an
ARPHRD_TUNNEL6 slave can be set to 802.3ad and take another TUNNEL6
device, such as a second bond prepared the same way, without the check.
bond_open() then adds the 8-byte lacpdu_mcast_addr to that slave with
dev_mc_add(), which copies the slave's 16-byte addr_len:

  BUG: KASAN: global-out-of-bounds in __hw_addr_add_ex (net/core/dev_addr_lists.c:102 net/core/dev_addr_lists.c:157)
  Read of size 16 at addr ffffffff878a2940 by task test/114
  Call Trace:
   <TASK>
   __hw_addr_add_ex (net/core/dev_addr_lists.c:102 net/core/dev_addr_lists.c:157)
   dev_mc_add (net/core/dev_addr_lists.c:1036 net/core/dev_addr_lists.c:1054)
   bond_open (drivers/net/bonding/bond_main.c:4405)
   __dev_open (net/core/dev.c:1762)
   __dev_change_flags (net/core/dev.c:10022)
   netif_change_flags (net/core/dev.c:10087)
   do_setlink.isra.0 (net/core/rtnetlink.c:3294)
   rtnl_setlink (net/core/rtnetlink.c:3633)

An unprivileged user can set this up in its own user and network
namespace.

Check that an 802.3ad slave is an Ethernet device before the type
handling, for every slave.

Fixes: c84fcb79e5db ("bonding: limit BOND_MODE_8023AD to Ethernet devices")
Suggested-by: Jay Vosburgh <jv@jvosburgh.net>
Signed-off-by: Kyuwon Cho <kyuwoncho18@gmail.com>
Reviewed-by: Eric Dumazet <edumazet@kernel.org>
---
v2:
- Move the check above the type handling, as Jay suggested, so it
  covers every slave. There is no functional change: the bond mode
  cannot change while it has slaves, and a later slave of another type
  was already rejected, only with a different message. Kept Eric's
  Reviewed-by.
v1: https://lore.kernel.org/netdev/179500849159.1877154.14715369660816392826@gmail.com/

The patch was written with LLM assistance; we reviewed and tested it.
With it, our reproducer no longer triggers the report, and enslaving
Ethernet devices into an 802.3ad bond, or a non-Ethernet device into
an active-backup bond, works as before.

 drivers/net/bonding/bond_main.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 042d7c75548f..bcc12ef34d9a 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1951,6 +1951,13 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
 		return -EPERM;
 	}
 
+	if (slave_dev->type != ARPHRD_ETHER &&
+	    BOND_MODE(bond) == BOND_MODE_8023AD) {
+		SLAVE_NL_ERR(bond_dev, slave_dev, extack,
+			     "8023AD mode requires Ethernet devices");
+		return -EINVAL;
+	}
+
 	/* set bonding device ether type by slave - bonding netdevices are
 	 * created with ether_setup, so when the slave type is not ARPHRD_ETHER
 	 * there is a need to override some of the type dependent attribs/funcs.
@@ -1960,12 +1967,6 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
 	 */
 	if (!bond_has_slaves(bond)) {
 		if (bond_dev->type != slave_dev->type) {
-			if (slave_dev->type != ARPHRD_ETHER &&
-			    BOND_MODE(bond) == BOND_MODE_8023AD) {
-				SLAVE_NL_ERR(bond_dev, slave_dev, extack,
-					     "8023AD mode requires Ethernet devices");
-				return -EINVAL;
-			}
 			slave_dbg(bond_dev, slave_dev, "change device type from %d to %d\n",
 				  bond_dev->type, slave_dev->type);
 

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

* Re: [PATCH net v2] bonding: reject a non-Ethernet 802.3ad slave even when the type matches
  2026-11-19  3:31 [PATCH net v2] bonding: reject a non-Ethernet 802.3ad slave even when the type matches Kyuwon Cho
@ 2026-11-19 10:01 ` Hangbin Liu
  2026-11-20 15:29   ` Kyuwon Cho
  2026-11-23  3:32 ` netdev-bot+sashiko
  1 sibling, 1 reply; 4+ messages in thread
From: Hangbin Liu @ 2026-11-19 10:01 UTC (permalink / raw)
  To: Kyuwon Cho
  Cc: netdev, Jay Vosburgh, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, linux-kernel

On Wed, Nov 18, 2026 at 07:31:10PM -0800, Kyuwon Cho wrote:
> Commit c84fcb79e5db ("bonding: limit BOND_MODE_8023AD to Ethernet
> devices") rejects a non-Ethernet first slave in 802.3ad mode, but only
> when enslaving it changes the bond's type. A bond keeps the type of its
> last slave after that slave is released, so a bond that once had an
> ARPHRD_TUNNEL6 slave can be set to 802.3ad and take another TUNNEL6

Hmm, should we also check and set the bond device type back to Ethernet
when set mode to 8023AD?

Thanks
Hangbin

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

* Re: [PATCH net v2] bonding: reject a non-Ethernet 802.3ad slave even when the type matches
  2026-11-19 10:01 ` Hangbin Liu
@ 2026-11-20 15:29   ` Kyuwon Cho
  0 siblings, 0 replies; 4+ messages in thread
From: Kyuwon Cho @ 2026-11-20 15:29 UTC (permalink / raw)
  To: Hangbin Liu
  Cc: netdev, Jay Vosburgh, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, linux-kernel

On Thu, Nov 19, 2026 at 06:01:55PM +0800, Hangbin Liu wrote:
> Hmm, should we also check and set the bond device type back to Ethernet
> when set mode to 8023AD?

With this patch the leftover type should not matter for 802.3ad: the
mode can only be changed while the bond has no slaves, every slave of
an 802.3ad bond now has to be an Ethernet device, and enslaving the
first one turns the bond back into an Ethernet device through
bond_ether_setup(). I checked that on this patch: a bond left as
ARPHRD_TUNNEL6 stays so after the mode change, becomes ARPHRD_ETHER
when the first Ethernet slave is added, and comes up fine.

Resetting the type at the mode change would also make an empty 802.3ad
bond look like Ethernet, which seems a reasonable cleanup, but it
changes the device type outside of enslave, so I would keep it out of
this fix. I can send it separately for net-next if you and Jay think it
is worth it.

Thanks,
Kyuwon Cho

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

* Re: [PATCH net v2] bonding: reject a non-Ethernet 802.3ad slave even when the type matches
  2026-11-19  3:31 [PATCH net v2] bonding: reject a non-Ethernet 802.3ad slave even when the type matches Kyuwon Cho
  2026-11-19 10:01 ` Hangbin Liu
@ 2026-11-23  3:32 ` netdev-bot+sashiko
  1 sibling, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23  3:32 UTC (permalink / raw)
  To: kyuwoncho18
  Cc: netdev, jv, andrew+netdev, davem, edumazet, kuba, pabeni, linux-kernel

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The fix is incomplete.

--

bonding: reject a non-Ethernet 802.3ad slave even when the type matches

This patch moves the "8023AD mode requires Ethernet devices" check in
bond_enslave() above the bond type handling. The check now applies to
every slave, not only to a first slave that changes the bond's type. It
targets a KASAN global-out-of-bounds read in bond_open(), where
dev_mc_add() copies a 16-byte addr_len from the 8-byte lacpdu_mcast_addr.

> diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
> index 042d7c75548fa..bcc12ef34d9ab 100644
> --- a/drivers/net/bonding/bond_main.c
> +++ b/drivers/net/bonding/bond_main.c
> @@ -1951,6 +1951,13 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
>  		return -EPERM;
>  	}
>  
> +	if (slave_dev->type != ARPHRD_ETHER &&
> +	    BOND_MODE(bond) == BOND_MODE_8023AD) {
> +		SLAVE_NL_ERR(bond_dev, slave_dev, extack,
> +			     "8023AD mode requires Ethernet devices");
> +		return -EINVAL;
> +	}
> +

[Severity: High]
Does this fully close the out-of-bounds read on lacpdu_mcast_addr? The
check only looks at slave_dev->type when the device is enslaved. A slave
that is itself a bond can still change type afterwards, while it stays a
slave of the 802.3ad bond.

Here is a possible sequence:

  1) Create B1 in 802.3ad mode and B2 in active-backup mode. B2 is
     ARPHRD_ETHER because bonds are created with ether_setup.
  2) Enslave B2 into B1. Bond masters are allowed as slaves, and B2 is
     ARPHRD_ETHER, so the new check passes.
  3) Enslave an ip6tnl device (ARPHRD_TUNNEL6, addr_len 16) into B2.

Step 3 goes through:

bond_enslave(B2, ip6tnl)
  call_netdevice_notifiers(NETDEV_PRE_TYPE_CHANGE, B2)
    bond_netdev_event()
      bond_master_netdev_event()   returns NOTIFY_DONE
      bond_slave_netdev_event()    returns NOTIFY_DONE, no PRE_TYPE_CHANGE case
  bond_setup_by_slave(B2, ip6tnl)
    bond_dev->type     = slave_dev->type;      /* ARPHRD_TUNNEL6 */
    bond_dev->addr_len = slave_dev->addr_len;  /* 16 */

Nothing in bonding vetoes the type change, so B2 is now a TUNNEL6 slave
of the 802.3ad bond B1. Setting B1 down and then up again reaches the
same sink as in the commit message:

bond_open(B1)
  dev_mc_add(slave->dev, lacpdu_mcast_addr)
    __dev_mc_add()
      __hw_addr_add_ex(&dev->mc, addr, dev->addr_len, ...)
        memcpy(ha->addr, addr, addr_len)   /* 16 bytes from an 8-byte global */

with:

drivers/net/bonding/bond_3ad.c:
const u8 lacpdu_mcast_addr[ETH_ALEN + 2] __long_aligned = {

bond_hw_addr_flush() has the same problem through
dev_mc_del(slave_dev, lacpdu_mcast_addr). The bytes read past the end of
the global end up in B2's mc list, and /proc/net/dev_mcast prints them.

A team device used as the inner device should follow the same path,
because team_dev_type_check_change() also relies on the notifier chain.

Other upper drivers block type changes of their lower devices. For
example, team_device_event():

	case NETDEV_PRE_TYPE_CHANGE:
		/* Forbid to change type of underlaying device */
		return NOTIFY_BAD;

Bridge, macvlan, ipvlan, hsr and vlan do the same.

Could bond_slave_netdev_event() refuse NETDEV_PRE_TYPE_CHANGE, at least
in 802.3ad mode? Another option would be to check the slave's addr_len
before dev_mc_add()/dev_mc_del() of lacpdu_mcast_addr.

>  	/* set bonding device ether type by slave - bonding netdevices are
>  	 * created with ether_setup, so when the slave type is not ARPHRD_ETHER
>  	 * there is a need to override some of the type dependent attribs/funcs.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179505868590.3571070.12381528230330714812%40gmail.com

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

end of thread, other threads:[~2026-11-23  3:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19  3:31 [PATCH net v2] bonding: reject a non-Ethernet 802.3ad slave even when the type matches Kyuwon Cho
2026-11-19 10:01 ` Hangbin Liu
2026-11-20 15:29   ` Kyuwon Cho
2026-11-23  3:32 ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®