bonding: reject a non-Ethernet 802.3ad slave even when the type matches
Subsystems (3)
PATCH 1/1 bonding: reject a non-Ethernet 802.3ad slave even when the type matches
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+0x26a/0x6d0 Read of size 16 at addr ffffffff878a1620 by task test/115 Call Trace: <TASK> __asan_memcpy+0x23/0x60 __hw_addr_add_ex+0x26a/0x6d0 dev_mc_add+0xb1/0xf0 bond_open+0xaa6/0xf90 __dev_open+0x2fd/0x7f0 __dev_change_flags+0x480/0x670 netif_change_flags+0x7b/0x160 do_setlink.isra.0+0x16f8/0x3960 rtnl_setlink+0x474/0x870
An unprivileged user can set this up in its own user and network namespace.
Do the 802.3ad check for every first slave, not only when the bond's type changes.
---
This was first reported privately to [email protected]. Eric reviewed the patch there, judged that no embargo is needed, and asked for it to be posted here with his Reviewed-by.
The patch was written with LLM assistance; we reviewed and tested it. With it our reproducer is clean in 6 of 6 runs on v7.4-rc3 and in 6 of 6 runs on net (2a324a58a084).
drivers/net/bonding/bond_main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/net/bonding/bond_main.c +6 -6
@@ -1959,13 +1959,13 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,* ether type (eg ARPHRD_ETHER and ARPHRD_INFINIBAND) share the same bond */ if (!bond_has_slaves (bond)) { +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 ; + }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);
Jay Vosburgh
maintainerQuoted 26 lines · Kyuwon Cho
Commit
c84fcb79e5db("bonding: limitBOND_MODE_8023ADto 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 anARPHRD_TUNNEL6slave 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-bytelacpdu_mcast_addrto that slave withdev_mc_add(), which copies the slave's 16-byteaddr_len:BUG: KASAN: global-out-of-bounds in __hw_addr_add_ex+0x26a/0x6d0 Read of size 16 at addr ffffffff878a1620 by task test/115 Call Trace: <TASK> __asan_memcpy+0x23/0x60 __hw_addr_add_ex+0x26a/0x6d0 dev_mc_add+0xb1/0xf0 bond_open+0xaa6/0xf90 __dev_open+0x2fd/0x7f0 __dev_change_flags+0x480/0x670 netif_change_flags+0x7b/0x160 do_setlink.isra.0+0x16f8/0x3960 rtnl_setlink+0x474/0x870An unprivileged user can set this up in its own user and network namespace.
Quoted 6 lines
Do the 802.3ad check for every first slave, not only when the bond's type changes.
Fixes c84fcb79e5db ("bonding: limit BOND_MODE_8023AD to Ethernet devices")Signed-off-by Kyuwon Cho <[email protected]>Reviewed-by Eric Dumazet <[email protected]>
This patch looks like it will work, but, since 802.3ad is only
allowed for ARPHRD_ETHER, I think it would be clearer if the block were moved up a level, i.e., above the "set bonding device ether type by slave" commentary, something like (not tested):
drivers/net/bonding/bond_main.c +7 -6
@@ -1948,6 +1948,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.
@@ -1957,12 +1964,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);
In my opinion, this would be clearer to the reader, in that the
802.3ad restriction has nothing to do with whether the bond is empty or not.
-J
Quoted 26 lines
---
This was first reported privately to [email protected]. Eric reviewed the patch there, judged that no embargo is needed, and asked for it to be posted here with his Reviewed-by.The patch was written with LLM assistance; we reviewed and tested it. With it our reproducer is clean in 6 of 6 runs on v7.4-rc3 and in 6 of 6 runs on net (
2a324a58a084).
drivers/net/bonding/bond_main.c| 12 ++++++------1 file changed, 6 insertions(+), 6 deletions(-)drivers/net/bonding/bond_main.c +6
-0@@ -1959,13 +1959,13 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,* ether type (eg ARPHRD_ETHER and ARPHRD_INFINIBAND) share the same bond */ if (!bond_has_slaves (bond)) { +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 ; + }
drivers/net/bonding/bond_main.c int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev, · line 1971
Quoted 10 lines
drivers/net/bonding/bond_main.c +0
-6if (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);
---
-Jay Vosburgh, [email protected]
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
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 moves the 802.3ad Ethernet-only check in bond_enslave() so that it runs for every first slave, not only when enslaving changes the bond's type. The goal is to stop the global out-of-bounds read of lacpdu_mcast_addr in bond_open() when a slave with a 16-byte addr_len ends up in an 802.3ad bond.
Quoted 5 lines
drivers/net/bonding/bond_main.c +0
-0
drivers/net/bonding/bond_main.c int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev, · line 1967
Quoted 9 lines
drivers/net/bonding/bond_main.c +6
-0@@ -1959,13 +1959,13 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,* ether type (eg ARPHRD_ETHER and ARPHRD_INFINIBAND) share the same bond */ if (!bond_has_slaves (bond)) { +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]
Is this check enough to keep a non-Ethernet slave out of an 802.3ad bond? It only looks at the slave's type when the slave is enslaved. A slave that is itself a bond can still change type after that.
Consider this sequence:
ip link add bondA type bond mode 802.3ad
ip link add bondB type bond mode active-backup
ip link set bondB master bondA <- bondB is ARPHRD_ETHER, passes
ip link set ip6tnl0 master bondB <- bondB has no slaves yet
The second enslave goes through bond_enslave(bondB), which sends NETDEV_PRE_TYPE_CHANGE for bondB:
res = call_netdevice_notifiers(NETDEV_PRE_TYPE_CHANGE, bond_dev);
bond_netdev_event() passes the event to bond_master_netdev_event() and bond_slave_netdev_event(). Neither one has a NETDEV_PRE_TYPE_CHANGE case, so both reach:
default: break; } return NOTIFY_DONE;
vlan_device_event() only refuses this when VLAN upper devices exist. So bond_setup_by_slave() goes ahead and sets bondB->type to ARPHRD_TUNNEL6 and bondB->addr_len to 16, while bondB is still a slave of bondA.
When bondA is brought up, bond_open() does:
bond_for_each_slave(bond, slave, iter) dev_mc_add(slave->dev, lacpdu_mcast_addr);
but lacpdu_mcast_addr in bond_3ad.c is only 8 bytes:
const u8 lacpdu_mcast_addr[ETH_ALEN + 2] __long_aligned = {Does this lead to the same global out-of-bounds read as the KASAN report in the commit message?
If bondA is already up, a later release of bondB has the same problem. bond_hw_addr_flush() calls dev_mc_del(slave_dev, lacpdu_mcast_addr), which compares 16 bytes against the same 8-byte array.
Changing the type of an enslaved bond seems to be supported behaviour. bond_test_enslave_type_change() in tools/testing/selftests/drivers/net/bonding/bond-eth-type-change.sh enslaves one bond to another, then enslaves a non-Ethernet device to the inner bond. In its successful variant, the test expects the type change to stick.
For comparison, team_device_event() in drivers/net/team/team_core.c refuses this event for its ports:
case NETDEV_PRE_TYPE_CHANGE: /* Forbid to change type of underlaying device */ return NOTIFY_BAD;
Should bond_slave_netdev_event() also veto NETDEV_PRE_TYPE_CHANGE? That could apply only when the bond is in 802.3ad mode and the new type is not Ethernet, or, as team does, whenever the slave's type would no longer match bond_dev->type.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179500849159.1877154.14715369660816392826%40gmail.com
Quoted 4 lines · On Sun, 22 Nov 2026 13:02:33 +0000, [email protected] wrote:
[Severity: High]
Is this check enough to keep a non-Ethernet slave out of an 802.3ad bond? It only looks at the slave's type when the slave is enslaved. A slave that is itself a bond can still change type after that.
The issue is real: the nested case gives the same KASAN report in bond_open(), also with v2 applied. v3 adds a second patch that refuses NETDEV_PRE_TYPE_CHANGE for a slave of an 802.3ad bond, as team does for its ports; other modes still allow it, as bond-eth-type-change.sh expects.
Kyuwon Cho
pw-bot: cr