bonding: keep non-Ethernet slaves out of 802.3ad bonds
Subsystems (3)
v3 cover bonding: keep non-Ethernet slaves out of 802.3ad bonds
bond_open() adds the 8-byte lacpdu_mcast_addr to every slave of an 802.3ad bond, so a slave whose addr_len is 16, such as an ip6tnl device, makes dev_mc_add() read past it. Patch 1 rejects such a slave at enslave time in every case; patch 2 stops an enslaved bond from changing its type afterwards.
The issue was found by an LLM-guided test generator that we are developing as a research prototype.
v3:
- Add patch 2: as the Sashiko review of v1 pointed out, a bond enslaved to an 802.3ad bond could still change its type.
- Patch 1 is unchanged; its tags are kept.
- Hangbin asked on v2 whether the bond type should be reset when the
mode is set to 802.3ad; as answered there, the first Ethernet slave resets it, so this series leaves it alone.
v2: https://lore.kernel.org/netdev/[email protected]/
- Move the check above the type handling, as Jay suggested.
v1: https://lore.kernel.org/netdev/[email protected]/
The patches were written with LLM assistance; we reviewed and tested them. With them, neither the direct nor the nested reproducer triggers the report. Enslaving Ethernet devices into an 802.3ad bond, a non-Ethernet device into an active-backup bond, and the type change of a bond enslaved to a balance-rr bond, as in bond-eth-type-change.sh, work as before.
Kyuwon Cho (2):
bonding: reject a non-Ethernet 802.3ad slave even when the type
matches
bonding: don't let an 802.3ad slave change its type
drivers/net/bonding/bond_main.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
Signature · 1 line
2.43.0
PATCH v3 1/2 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 (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.
--- drivers/net/bonding/bond_main.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/net/bonding/bond_main.c +7 -6
@@ -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);
Signature · 1 line
2.43.0
Re: [PATCH net v3 1/2] bonding: reject a non-Ethernet 802.3ad slave even when the type matches
Quoted 70 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 (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 <[email protected]>Signed-off-by Kyuwon Cho <[email protected]>Reviewed-by Eric Dumazet <[email protected]>--- drivers/net/bonding/bond_main.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)drivers/net/bonding/bond_main.c +7
-6@@ -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);Signature · 1 line
2.43.0
PATCH v3 2/2 bonding: don't let an 802.3ad slave change its type
In reply to Kyuwon ChoA bond can be a slave of another bond. Enslaving a non-Ethernet device to an empty inner bond changes the inner bond's type in bond_setup_by_slave() after NETDEV_PRE_TYPE_CHANGE, and nothing refuses that while the inner bond is a slave of an 802.3ad bond. The outer bond then adds the 8-byte lacpdu_mcast_addr to a slave whose addr_len is 16, the same global out-of-bounds read as when such a slave is enslaved directly:
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 Call Trace: __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)
Refuse 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.
--- drivers/net/bonding/bond_main.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/bonding/bond_main.c +4 -0
@@ -3981,6 +3981,10 @@ static int bond_slave_netdev_event(unsigned long event,slave_dbg (bond_dev, slave_dev,"%s called\n" , __func__);switch (event) { +case NETDEV_PRE_TYPE_CHANGE : +if (BOND_MODE (bond) ==BOND_MODE_8023AD ) +return NOTIFY_BAD ; +break ;case NETDEV_UNREGISTER :if (bond_dev->type !=ARPHRD_ETHER )bond_release_and_destroy (bond_dev, slave_dev);
Signature · 1 line
2.43.0
Re: [PATCH net v3 2/2] bonding: don't let an 802.3ad slave change its type
Quoted 42 lines · Kyuwon Cho
A bond can be a slave of another bond. Enslaving a non-Ethernet device to an empty inner bond changes the inner bond's type in
bond_setup_by_slave()afterNETDEV_PRE_TYPE_CHANGE, and nothing refuses that while the inner bond is a slave of an 802.3ad bond. The outer bond then adds the 8-bytelacpdu_mcast_addrto a slave whoseaddr_lenis 16, the same global out-of-bounds read as when such a slave is enslaved directly: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 Call Trace: __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)Refuse
NETDEV_PRE_TYPE_CHANGEfor a slave of an 802.3ad bond, as team does for its ports. Other modes still allow it, asbond-eth-type-change.shexpects.Fixes c84fcb79e5db ("bonding: limit BOND_MODE_8023AD to Ethernet devices")Signed-off-by Kyuwon Cho <[email protected]>--- drivers/net/bonding/bond_main.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/net/bonding/bond_main.c +4
-0@@ -3981,6 +3981,10 @@ static int bond_slave_netdev_event(unsigned long event,slave_dbg (bond_dev, slave_dev,"%s called\n" , __func__);switch (event) { +case NETDEV_PRE_TYPE_CHANGE : +if (BOND_MODE (bond) ==BOND_MODE_8023AD ) +return NOTIFY_BAD ; +break ;case NETDEV_UNREGISTER :if (bond_dev->type !=ARPHRD_ETHER )bond_release_and_destroy (bond_dev, slave_dev);Signature · 1 line
2.43.0
Hmm, I personally prefer the approach used by vlan and team, which disallows changing the slave type after enslavement. If you think we should only disable the 802.3ad-specific part, this change should be merged with patch 1, as they address the same issue.
Cc Nikolay since he add the bond-eth-type-change.sh test.
Thanks
Hangbin
Re: [PATCH net v3 2/2] bonding: don't let an 802.3ad slave change its type
Quoted 4 lines · Hangbin Liu
Hmm, I personally prefer the approach used by vlan and team, which disallows changing the slave type after enslavement. If you think we should only disable the 802.3ad-specific part, this change should be merged with patch 1, as they address the same issue.
For net I would keep it to 802.3ad, where the type change leads to the out-of-bounds read, and merge it into patch 1 as you suggest. Refusing the type change in every mode would also make the enslave of the nlmon device in bond-eth-type-change.sh fail. The test would still pass, as it does not check that enslave, but it would no longer change the type it is there to test, so that change seems better made in net-next.
Nikolay, would you rather have the general check?
I will send v4 with the two patches merged once this is settled.
Thanks,
Kyuwon Cho
Re: [PATCH net v3 2/2] bonding: don't let an 802.3ad slave change its type
Quoted 13 lines · Kyuwon Cho
Quoted 4 lines · Hangbin Liu
Hmm, I personally prefer the approach used by vlan and team, which disallows changing the slave type after enslavement. If you think we should only disable the 802.3ad-specific part, this change should be merged with patch 1, as they address the same issue.
For net I would keep it to 802.3ad, where the type change leads to the out-of-bounds read, and merge it into patch 1 as you suggest. Refusing the type change in every mode would also make the enslave of the nlmon device in
bond-eth-type-change.shfail. The test would still pass, as it does not check that enslave, but it would no longer change the type it is there to test, so that change seems better made in net-next.
Quoted 6 lines
Nikolay, would you rather have the general check?
I will send v4 with the two patches merged once this is settled.
Thanks,
Kyuwon Cho
Since this requires purposefully breaking the bond with CAP_NET_ADMIN, I'd go for net-next. About the general check - unfortunately I don't think we can do it at all due to one, rather weird, use case that comes to mind - nested bonds. There are setups which use bonds of bonds and that will put ordering on the setup, potentially could break scripts.
Cheers,
Nik
Re: [PATCH net v3 2/2] bonding: don't let an 802.3ad slave change its type
Quoted 21 lines · Nikolay Aleksandrov
Quoted 13 lines · Kyuwon Cho
Quoted 4 lines · Hangbin Liu
Hmm, I personally prefer the approach used by vlan and team, which disallows changing the slave type after enslavement. If you think we should only disable the 802.3ad-specific part, this change should be merged with patch 1, as they address the same issue.
For net I would keep it to 802.3ad, where the type change leads to the out-of-bounds read, and merge it into patch 1 as you suggest. Refusing the type change in every mode would also make the enslave of the nlmon device in
bond-eth-type-change.shfail. The test would still pass, as it does not check that enslave, but it would no longer change the type it is there to test, so that change seems better made in net-next.Quoted 6 lines
Nikolay, would you rather have the general check?
I will send v4 with the two patches merged once this is settled.
Thanks,
Kyuwon Cho
Quoted 8 lines
Since this requires purposefully breaking the bond with
CAP_NET_ADMIN, I'd go for net-next. About the general check - unfortunately I don't think we can do it at all due to one, rather weird, use case that comes to mind - nested bonds. There are setups which use bonds of bonds and that will put ordering on the setup, potentially could break scripts.Cheers,
Nik
On a second thought - the bond is ARPHRD device by default, so nested bond would affect only non-ARPHRD setups, I'm not sure if there are any such setups. Just saying, it could be a path to stopping all type changes after enslave. :)