All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] bonding: fix event handling for stacked bonds
@ 2019-04-12 13:04 Sabrina Dubroca
  2019-04-12 13:57 ` Jiri Pirko
  2019-04-15 20:23 ` David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: Sabrina Dubroca @ 2019-04-12 13:04 UTC (permalink / raw)
  To: netdev
  Cc: Sabrina Dubroca, Jay Vosburgh, Veaceslav Falico, Andy Gospodarek,
	Jarod Wilson

When a bond is enslaved to another bond, bond_netdev_event() only
handles the event as if the bond is a master, and skips treating the
bond as a slave.

This leads to a refcount leak on the slave, since we don't remove the
adjacency to its master and the master holds a reference on the slave.

Reproducer:
  ip link add bondL type bond
  ip link add bondU type bond
  ip link set bondL master bondU
  ip link del bondL

No "Fixes:" tag, this code is older than git history.

Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
---
I also spotted some lockdep warnings when I started stacking random
devices on top of random devices, I'm trying to clean that up too, but
this fix is independent of that.

 drivers/net/bonding/bond_main.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index b59708c35faf..ee610721098e 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -3213,8 +3213,12 @@ static int bond_netdev_event(struct notifier_block *this,
 		return NOTIFY_DONE;
 
 	if (event_dev->flags & IFF_MASTER) {
+		int ret;
+
 		netdev_dbg(event_dev, "IFF_MASTER\n");
-		return bond_master_netdev_event(event, event_dev);
+		ret = bond_master_netdev_event(event, event_dev);
+		if (ret != NOTIFY_DONE)
+			return ret;
 	}
 
 	if (event_dev->flags & IFF_SLAVE) {
-- 
2.21.0


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

* Re: [PATCH net] bonding: fix event handling for stacked bonds
  2019-04-12 13:04 [PATCH net] bonding: fix event handling for stacked bonds Sabrina Dubroca
@ 2019-04-12 13:57 ` Jiri Pirko
  2019-04-12 14:12   ` Sabrina Dubroca
  2019-04-15 20:23 ` David Miller
  1 sibling, 1 reply; 4+ messages in thread
From: Jiri Pirko @ 2019-04-12 13:57 UTC (permalink / raw)
  To: Sabrina Dubroca
  Cc: netdev, Jay Vosburgh, Veaceslav Falico, Andy Gospodarek, Jarod Wilson

Fri, Apr 12, 2019 at 03:04:10PM CEST, sd@queasysnail.net wrote:
>When a bond is enslaved to another bond, bond_netdev_event() only
>handles the event as if the bond is a master, and skips treating the
>bond as a slave.
>
>This leads to a refcount leak on the slave, since we don't remove the
>adjacency to its master and the master holds a reference on the slave.
>
>Reproducer:
>  ip link add bondL type bond
>  ip link add bondU type bond
>  ip link set bondL master bondU
>  ip link del bondL

Out of curiosity, what is a usecase of stacked bonds? I don't see any.


>
>No "Fixes:" tag, this code is older than git history.
>
>Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
>---
>I also spotted some lockdep warnings when I started stacking random
>devices on top of random devices, I'm trying to clean that up too, but
>this fix is independent of that.
>
> drivers/net/bonding/bond_main.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
>diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
>index b59708c35faf..ee610721098e 100644
>--- a/drivers/net/bonding/bond_main.c
>+++ b/drivers/net/bonding/bond_main.c
>@@ -3213,8 +3213,12 @@ static int bond_netdev_event(struct notifier_block *this,
> 		return NOTIFY_DONE;
> 
> 	if (event_dev->flags & IFF_MASTER) {
>+		int ret;
>+
> 		netdev_dbg(event_dev, "IFF_MASTER\n");
>-		return bond_master_netdev_event(event, event_dev);
>+		ret = bond_master_netdev_event(event, event_dev);
>+		if (ret != NOTIFY_DONE)
>+			return ret;
> 	}
> 
> 	if (event_dev->flags & IFF_SLAVE) {
>-- 
>2.21.0
>

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

* Re: [PATCH net] bonding: fix event handling for stacked bonds
  2019-04-12 13:57 ` Jiri Pirko
@ 2019-04-12 14:12   ` Sabrina Dubroca
  0 siblings, 0 replies; 4+ messages in thread
From: Sabrina Dubroca @ 2019-04-12 14:12 UTC (permalink / raw)
  To: Jiri Pirko
  Cc: netdev, Jay Vosburgh, Veaceslav Falico, Andy Gospodarek, Jarod Wilson

2019-04-12, 15:57:55 +0200, Jiri Pirko wrote:
> Fri, Apr 12, 2019 at 03:04:10PM CEST, sd@queasysnail.net wrote:
> >When a bond is enslaved to another bond, bond_netdev_event() only
> >handles the event as if the bond is a master, and skips treating the
> >bond as a slave.
> >
> >This leads to a refcount leak on the slave, since we don't remove the
> >adjacency to its master and the master holds a reference on the slave.
> >
> >Reproducer:
> >  ip link add bondL type bond
> >  ip link add bondU type bond
> >  ip link set bondL master bondU
> >  ip link del bondL
> 
> Out of curiosity, what is a usecase of stacked bonds? I don't see any.

I don't have one, but nothing is preventing that setup. It's just
something I accidentally ran into while testing other things. If you
want to prevent bond-bond, you also need to prevent things like
bond-macvlan-bond for example. The set of rules of what types of
stacking make sense seems a bit hairy.

-- 
Sabrina

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

* Re: [PATCH net] bonding: fix event handling for stacked bonds
  2019-04-12 13:04 [PATCH net] bonding: fix event handling for stacked bonds Sabrina Dubroca
  2019-04-12 13:57 ` Jiri Pirko
@ 2019-04-15 20:23 ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2019-04-15 20:23 UTC (permalink / raw)
  To: sd; +Cc: netdev, j.vosburgh, vfalico, andy, jarod

From: Sabrina Dubroca <sd@queasysnail.net>
Date: Fri, 12 Apr 2019 15:04:10 +0200

> When a bond is enslaved to another bond, bond_netdev_event() only
> handles the event as if the bond is a master, and skips treating the
> bond as a slave.
> 
> This leads to a refcount leak on the slave, since we don't remove the
> adjacency to its master and the master holds a reference on the slave.
> 
> Reproducer:
>   ip link add bondL type bond
>   ip link add bondU type bond
>   ip link set bondL master bondU
>   ip link del bondL
> 
> No "Fixes:" tag, this code is older than git history.
> 
> Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>

Applied and queued up for -stable, thanks Sabrina.

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

end of thread, other threads:[~2019-04-15 20:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-12 13:04 [PATCH net] bonding: fix event handling for stacked bonds Sabrina Dubroca
2019-04-12 13:57 ` Jiri Pirko
2019-04-12 14:12   ` Sabrina Dubroca
2019-04-15 20:23 ` David Miller

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.