mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net] bonding: reject a non-Ethernet 802.3ad slave even when the type matches
@ 2026-11-18 13:38 Kyuwon Cho
  2026-11-18 19:37 ` Jay Vosburgh
  0 siblings, 1 reply; 2+ messages in thread
From: Kyuwon Cho @ 2026-11-18 13:38 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+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.

Fixes: c84fcb79e5db ("bonding: limit BOND_MODE_8023AD to Ethernet devices")
Signed-off-by: Kyuwon Cho <kyuwoncho18@gmail.com>
Reviewed-by: Eric Dumazet <edumazet@kernel.org>
---
This was first reported privately to security@kernel.org. 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(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 042d7c75548f..f2e645f869b1 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -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);
 

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

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

Kyuwon Cho <kyuwoncho18@gmail.com> 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
>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.
>
>Fixes: c84fcb79e5db ("bonding: limit BOND_MODE_8023AD to Ethernet devices")
>Signed-off-by: Kyuwon Cho <kyuwoncho18@gmail.com>
>Reviewed-by: Eric Dumazet <edumazet@kernel.org>

	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):

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 7019e5d8fdc8..b5d7e0ebaf21 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -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

>---
>This was first reported privately to security@kernel.org. 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(-)
>
>diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
>index 042d7c75548f..f2e645f869b1 100644
>--- a/drivers/net/bonding/bond_main.c
>+++ b/drivers/net/bonding/bond_main.c
>@@ -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, jv@jvosburgh.net

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

end of thread, other threads:[~2026-11-18 19:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 13:38 [PATCH net] bonding: reject a non-Ethernet 802.3ad slave even when the type matches Kyuwon Cho
2026-11-18 19:37 ` Jay Vosburgh

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®