Skip to contentSkip to conversation

net: fix a potential recursive NETDEV_FEAT_CHANGE

PATCH Superseded Cong Wang 3 participants 9 messages May 5, 2020 – May 6, 2020

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 net: fix a potential recursive NETDEV_FEAT_CHANGE

syzbot managed to trigger a recursive NETDEV_FEAT_CHANGE event between bonding master and slave. I managed to find a reproducer for this:

ip li set bond0 up
ifenslave bond0 eth0
brctl addbr br0
ethtool -K eth0 lro off
brctl addif br0 bond0
ip li set br0 up

When a NETDEV_FEAT_CHANGE event is triggered on a bonding slave, it captures this and calls bond_compute_features() to fixup its master's and other slaves' features. However, when syncing with its lower devices by netdev_sync_lower_features() this event is triggered again on slaves, so it goes back and forth recursively until the kernel stack is exhausted.

It is unnecessary to trigger it for a second time, because when we update the features from top down, we rely on each dev->netdev_ops->ndo_fix_features() to do the job, each stacked device should implement it. NETDEV_FEAT_CHANGE event is necessary when we update from bottom up, like in existing stacked device implementations.

Just calling __netdev_update_features() is sufficient to fix this issue.

Fixes fd867d51f889 ("net/core: generic support for disabling netdev features down stack")
Reported-by [email protected]
Reported-by [email protected]
Cc Jarod Wilson <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Jay Vosburgh <[email protected]>
Cc Jann Horn <[email protected]>
---
 net/core/dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/dev.c +1 -1
index 522288177bbd..ece50ae346c3 100644
@@ -8907,7 +8907,7 @@ static void netdev_sync_lower_features(struct net_device *upper,
 			netdev_dbg(upper, "Disabling feature %pNF on lower dev %s.\n",
 				   &feature, lower->name);
 			lower->wanted_features &= ~feature;
-			netdev_update_features(lower);
+			__netdev_update_features(lower);
 
 			if (unlikely(lower->features & feature))
 				netdev_WARN(upper, "failed to disable %pNF on %s!\n",
Signature · 1 line
2.26.2
#1 lore raw
Quoted 45 lines · Cong Wang

syzbot managed to trigger a recursive NETDEV_FEAT_CHANGE event between bonding master and slave. I managed to find a reproducer for this:

ip li set bond0 up
ifenslave bond0 eth0
brctl addbr br0
ethtool -K eth0 lro off
brctl addif br0 bond0
ip li set br0 up

When a NETDEV_FEAT_CHANGE event is triggered on a bonding slave, it captures this and calls bond_compute_features() to fixup its master's and other slaves' features. However, when syncing with its lower devices by netdev_sync_lower_features() this event is triggered again on slaves, so it goes back and forth recursively until the kernel stack is exhausted.

It is unnecessary to trigger it for a second time, because when we update the features from top down, we rely on each dev->netdev_ops->ndo_fix_features() to do the job, each stacked device should implement it. NETDEV_FEAT_CHANGE event is necessary when we update from bottom up, like in existing stacked device implementations.

Just calling __netdev_update_features() is sufficient to fix this issue.

Fixes fd867d51f889 ("net/core: generic support for disabling netdev features down stack")
Reported-by [email protected]
Reported-by [email protected]
Cc Jarod Wilson <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Jay Vosburgh <[email protected]>
Cc Jann Horn <[email protected]>
---
 net/core/dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/dev.c +0 -0
index 522288177bbd..ece50ae346c3 100644

net/core/dev.c static void netdev_sync_lower_features(struct net_device *upper, · line 8913

Quoted 8 lines
net/core/dev.c +1 -1
@@ -8907,7 +8907,7 @@ static void netdev_sync_lower_features(struct net_device *upper,
 			netdev_dbg(upper, "Disabling feature %pNF on lower dev %s.\n",
 				   &feature, lower->name);
 			lower->wanted_features &= ~feature;
-			netdev_update_features(lower);
+			__netdev_update_features(lower);
 
 			if (unlikely(lower->features & feature))
 				netdev_WARN(upper, "failed to disable %pNF on %s!\n",

Wouldn't this mean that when we disable LRO on a bond manually with "ethtool -K", LRO will be also disabled on its slaves but no netlink notification for them would be sent to userspace?

Michal

author
#2 lore raw
Quoted 53 lines · Michal Kubecek
Quoted 51 lines · Cong Wang

syzbot managed to trigger a recursive NETDEV_FEAT_CHANGE event between bonding master and slave. I managed to find a reproducer for this:

ip li set bond0 up
ifenslave bond0 eth0
brctl addbr br0
ethtool -K eth0 lro off
brctl addif br0 bond0
ip li set br0 up

When a NETDEV_FEAT_CHANGE event is triggered on a bonding slave, it captures this and calls bond_compute_features() to fixup its master's and other slaves' features. However, when syncing with its lower devices by netdev_sync_lower_features() this event is triggered again on slaves, so it goes back and forth recursively until the kernel stack is exhausted.

It is unnecessary to trigger it for a second time, because when we update the features from top down, we rely on each dev->netdev_ops->ndo_fix_features() to do the job, each stacked device should implement it. NETDEV_FEAT_CHANGE event is necessary when we update from bottom up, like in existing stacked device implementations.

Just calling __netdev_update_features() is sufficient to fix this issue.

Fixes fd867d51f889 ("net/core: generic support for disabling netdev features down stack")
Reported-by [email protected]
Reported-by [email protected]
Cc Jarod Wilson <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Jay Vosburgh <[email protected]>
Cc Jann Horn <[email protected]>
---
 net/core/dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/dev.c +1 -1
index 522288177bbd..ece50ae346c3 100644
@@ -8907,7 +8907,7 @@ static void netdev_sync_lower_features(struct net_device *upper,
                      netdev_dbg(upper, "Disabling feature %pNF on lower dev %s.\n",
                                 &feature, lower->name);
                      lower->wanted_features &= ~feature;
-                     netdev_update_features(lower);
+                     __netdev_update_features(lower);
 
Quoted 6 lines

net/core/dev.c static void netdev_sync_lower_features(struct net_device *upper, · line 8913

Quoted 2 lines
net/core/dev.c +0 -0
                      if (unlikely(lower->features & feature))
                              netdev_WARN(upper, "failed to disable %pNF on %s!\n",

Wouldn't this mean that when we disable LRO on a bond manually with "ethtool -K", LRO will be also disabled on its slaves but no netlink notification for them would be sent to userspace?

What netlink notification are you talking about?

When we change features from top down, ->ndo_fix_features() does the work, in bonding case, it is bond_fix_features(). I see no netlink notification either in bond_compute_features() or bond_fix_features().

Thanks.

#3 lore raw
Quoted 13 lines · Cong Wang
Quoted 12 lines · Michal Kubecek
Quoted 11 lines · Cong Wang
net/core/dev.c +1 -1
index 522288177bbd..ece50ae346c3 100644
@@ -8907,7 +8907,7 @@ static void netdev_sync_lower_features(struct net_device *upper,
                      netdev_dbg(upper, "Disabling feature %pNF on lower dev %s.\n",
                                 &feature, lower->name);
                      lower->wanted_features &= ~feature;
-                     netdev_update_features(lower);
+                     __netdev_update_features(lower);
 
Quoted 8 lines
Quoted 6 lines

net/core/dev.c static void netdev_sync_lower_features(struct net_device *upper, · line 8913

Quoted 2 lines
net/core/dev.c +0 -0
                      if (unlikely(lower->features & feature))
                              netdev_WARN(upper, "failed to disable %pNF on %s!\n",

Wouldn't this mean that when we disable LRO on a bond manually with "ethtool -K", LRO will be also disabled on its slaves but no netlink notification for them would be sent to userspace?

What netlink notification are you talking about?

There is ethtool notification sent by ethnl_netdev_event() and rtnetlink notification sent by rtnetlink_event(). Both are triggered by NETDEV_FEAT_CHANGE notifier so unless I missed something, when you suppress the notifier, there will be no netlink notifications to userspace.

Michal

Quoted 6 lines

When we change features from top down, ->ndo_fix_features() does the work, in bonding case, it is bond_fix_features(). I see no netlink notification either in bond_compute_features() or bond_fix_features().

Thanks.

author
#4 lore raw
Quoted 22 lines · Michal Kubecek
Quoted 20 lines · Cong Wang
Quoted 18 lines · Michal Kubecek

net/core/dev.c static void netdev_sync_lower_features(struct net_device *upper, · line 8913

Quoted 13 lines · Cong Wang
net/core/dev.c +1 -1
index 522288177bbd..ece50ae346c3 100644
@@ -8907,7 +8907,7 @@ static void netdev_sync_lower_features(struct net_device *upper,
                      netdev_dbg(upper, "Disabling feature %pNF on lower dev %s.\n",
                                 &feature, lower->name);
                      lower->wanted_features &= ~feature;
-                     netdev_update_features(lower);
+                     __netdev_update_features(lower);
 
                      if (unlikely(lower->features & feature))
                              netdev_WARN(upper, "failed to disable %pNF on %s!\n",

Wouldn't this mean that when we disable LRO on a bond manually with "ethtool -K", LRO will be also disabled on its slaves but no netlink notification for them would be sent to userspace?

Quoted 7 lines
Quoted 1 line

What netlink notification are you talking about?

There is ethtool notification sent by ethnl_netdev_event() and rtnetlink notification sent by rtnetlink_event(). Both are triggered by NETDEV_FEAT_CHANGE notifier so unless I missed something, when you suppress the notifier, there will be no netlink notifications to userspace.

Oh, interesting, why ethtool_notify() can't be called directly, for example, in netdev_update_features()? To me, using a NETDEV_FEAT_CHANGE event handler seems unnecessary for ethtool netlink.

BTW, as pointed out by Jay, actually we only need to skip NETDEV_FEAT_CHANGE for failure case, so I will update my patch.

Thanks.

#5 lore raw
Quoted 31 lines · Cong Wang
Quoted 22 lines · Michal Kubecek
Quoted 20 lines · Cong Wang
Quoted 18 lines · Michal Kubecek

net/core/dev.c static void netdev_sync_lower_features(struct net_device *upper, · line 8913

Quoted 13 lines · Cong Wang
net/core/dev.c +1 -1
index 522288177bbd..ece50ae346c3 100644
@@ -8907,7 +8907,7 @@ static void netdev_sync_lower_features(struct net_device *upper,
                      netdev_dbg(upper, "Disabling feature %pNF on lower dev %s.\n",
                                 &feature, lower->name);
                      lower->wanted_features &= ~feature;
-                     netdev_update_features(lower);
+                     __netdev_update_features(lower);
 
                      if (unlikely(lower->features & feature))
                              netdev_WARN(upper, "failed to disable %pNF on %s!\n",

Wouldn't this mean that when we disable LRO on a bond manually with "ethtool -K", LRO will be also disabled on its slaves but no netlink notification for them would be sent to userspace?

Quoted 7 lines
Quoted 1 line

What netlink notification are you talking about?

There is ethtool notification sent by ethnl_netdev_event() and rtnetlink notification sent by rtnetlink_event(). Both are triggered by NETDEV_FEAT_CHANGE notifier so unless I missed something, when you suppress the notifier, there will be no netlink notifications to userspace.

Quoted 3 lines

Oh, interesting, why ethtool_notify() can't be called directly, for example, in netdev_update_features()? To me, using a NETDEV_FEAT_CHANGE event handler seems unnecessary for ethtool netlink.

It is certainly an option and as this is the only use of netdev notifiers in ethtool code, it might even be more convenient. I rather felt that when the call of notifier chain is in netdev_features_change() already, it would be cleaner to use it. But my point rather was that the NETDEV_FEAT_CHANGE event is used for more than only feature propagation between upper/lower devices so that suppressing it may have unwanted side effects (ethtool notifications were of course the first example that came to my mind).

Quoted 2 lines

BTW, as pointed out by Jay, actually we only need to skip NETDEV_FEAT_CHANGE for failure case, so I will update my patch.

Sounds like a good idea. I was wondering about this myself yesterday but I didn't have time to look into it deeper so I only realized the problem would probably be a difference between features and wanted_features.

Michal

#6 lore raw
In reply to Cong Wang
Quoted 10 lines · Cong Wang

syzbot managed to trigger a recursive NETDEV_FEAT_CHANGE event between bonding master and slave. I managed to find a reproducer for this:

ip li set bond0 up
ifenslave bond0 eth0
brctl addbr br0
ethtool -K eth0 lro off
brctl addif br0 bond0
ip li set br0 up

Presumably this is tied to the LRO feature being special in
netdev_sync_lower_features (via NETIF_F_UPPER_DISABLES), but why doesn't LRO become disabled and stop the recursion once the test

		if (!(features & feature) && (lower->features & feature)) {

	no longer evalutes to true (in theory)?

	-J
Quoted 45 lines

When a NETDEV_FEAT_CHANGE event is triggered on a bonding slave, it captures this and calls bond_compute_features() to fixup its master's and other slaves' features. However, when syncing with its lower devices by netdev_sync_lower_features() this event is triggered again on slaves, so it goes back and forth recursively until the kernel stack is exhausted.

It is unnecessary to trigger it for a second time, because when we update the features from top down, we rely on each dev->netdev_ops->ndo_fix_features() to do the job, each stacked device should implement it. NETDEV_FEAT_CHANGE event is necessary when we update from bottom up, like in existing stacked device implementations.

Just calling __netdev_update_features() is sufficient to fix this issue.

Fixes fd867d51f889 ("net/core: generic support for disabling netdev features down stack")
Reported-by [email protected]
Reported-by [email protected]
Cc Jarod Wilson <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Jay Vosburgh <[email protected]>
Cc Jann Horn <[email protected]>

---
net/core/dev.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
net/core/dev.c +1 -1
index 522288177bbd..ece50ae346c3 100644
@@ -8907,7 +8907,7 @@ static void netdev_sync_lower_features(struct net_device *upper,
 			netdev_dbg(upper, "Disabling feature %pNF on lower dev %s.\n",
 				   &feature, lower->name);
 			lower->wanted_features &= ~feature;
-			netdev_update_features(lower);
+			__netdev_update_features(lower);
 
 			if (unlikely(lower->features & feature))
 				netdev_WARN(upper, "failed to disable %pNF on %s!\n",
Signature · 1 line
2.26.2

---
-Jay Vosburgh, [email protected]

author
#7 lore raw
Quoted 14 lines · Jay Vosburgh
Quoted 10 lines · Cong Wang

syzbot managed to trigger a recursive NETDEV_FEAT_CHANGE event between bonding master and slave. I managed to find a reproducer for this:

ip li set bond0 up
ifenslave bond0 eth0
brctl addbr br0
ethtool -K eth0 lro off
brctl addif br0 bond0
ip li set br0 up

Quoted 7 lines

Presumably this is tied to the LRO feature being special in
netdev_sync_lower_features (via NETIF_F_UPPER_DISABLES), but why doesn't LRO become disabled and stop the recursion once the test

if (!(features & feature) && (lower->features & feature)) {

no longer evalutes to true (in theory)?

Good point!

Actually the LRO feature fails to disable:

[   62.559537] netdevice: bond0: failed to disable 0x0000000000008000 on eth0!
...
[   78.312003] netdevice: eth0: failed to disable LRO!

It seems we should only skip netdev_update_features() for such case, like below. Note __netdev_update_features() intentionally returns -1 for this failure, so I am afraid we just have to live with it.

net/core/dev.c +0 -0
index 522288177bbd..8040b07214fa 100644
@@ -8907,11 +8907,13 @@ static void netdev_sync_lower_features(struct

net_device *upper,
netdev_dbg(upper, "Disabling feature %pNF on
lower dev %s.\n",

                                   &feature, lower->name);
                        lower->wanted_features &= ~feature;

- netdev_update_features(lower);
+ __netdev_update_features(lower);

if (unlikely(lower->features & feature))
netdev_WARN(upper, "failed to disable
%pNF on %s!\n",

                                            &feature, lower->name);
+                       else
+                               netdev_update_features(lower);
                }
        }

}

author
#8 lore raw
Quoted 28 lines · Cong Wang
Quoted 14 lines · Jay Vosburgh
Quoted 10 lines · Cong Wang

syzbot managed to trigger a recursive NETDEV_FEAT_CHANGE event between bonding master and slave. I managed to find a reproducer for this:

ip li set bond0 up
ifenslave bond0 eth0
brctl addbr br0
ethtool -K eth0 lro off
brctl addif br0 bond0
ip li set br0 up

Quoted 7 lines

Presumably this is tied to the LRO feature being special in
netdev_sync_lower_features (via NETIF_F_UPPER_DISABLES), but why doesn't LRO become disabled and stop the recursion once the test

if (!(features & feature) && (lower->features & feature)) {

no longer evalutes to true (in theory)?

Good point!

Actually the LRO feature fails to disable:

Quoted 7 lines
[   62.559537] netdevice: bond0: failed to disable 0x0000000000008000 on eth0!
...
[   78.312003] netdevice: eth0: failed to disable LRO!

It seems we should only skip netdev_update_features() for such case, like below. Note __netdev_update_features() intentionally returns -1 for this failure, so I am afraid we just have to live with it.

Oops, I meant netdev_features_change() of course.