Skip to contentSkip to conversation

net: fix a potential recursive NETDEV_FEAT_CHANGE

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

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH v2 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 when the LRO feature fails to change, so it goes back and forth recursively until the kernel stack is exhausted.

Commit 17b85d29e82c intentionally lets __netdev_update_features() return -1 for such a failure case, so we have to just rely on the existing check inside netdev_sync_lower_features() and skip NETDEV_FEAT_CHANGE event only for this specific failure case.

Fixes 17b85d29e82c ("net/core: revert "net: fix __netdev_update_features return.." and add comment")
Reported-by [email protected]
Reported-by [email protected]
Cc Nikolay Aleksandrov <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Jay Vosburgh <[email protected]>
Cc Jann Horn <[email protected]>
---
 net/core/dev.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/core/dev.c +3 -1
index 522288177bbd..6d327b7aa813 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_features_change(lower);
 		}
 	}
 }
Signature · 1 line
2.26.2
#1 lore raw
Quoted 32 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 when the LRO feature fails to change, so it goes back and forth recursively until the kernel stack is exhausted.

Commit 17b85d29e82c intentionally lets __netdev_update_features() return -1 for such a failure case, so we have to just rely on the existing check inside netdev_sync_lower_features() and skip NETDEV_FEAT_CHANGE event only for this specific failure case.

Fixes 17b85d29e82c ("net/core: revert "net: fix __netdev_update_features return.." and add comment")
Reported-by [email protected]
Reported-by [email protected]
Cc Nikolay Aleksandrov <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Jay Vosburgh <[email protected]>
Cc Jann Horn <[email protected]>
Quoted 1 line

---

The patch looks good, but note that __netdev_update_features() used to return -1 before the commit in the Fixes tag above (between 6cb6a27c45ce and 00ee59271777). It only restored that behaviour.

Quoted 23 lines
 net/core/dev.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/core/dev.c +3 -1
index 522288177bbd..6d327b7aa813 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_features_change(lower);
 		}
 	}
 }
author
#2 lore raw
Quoted 3 lines · Nikolay Aleksandrov

The patch looks good, but note that __netdev_update_features() used to return -1 before the commit in the Fixes tag above (between 6cb6a27c45ce and 00ee59271777). It only restored that behaviour.

Good point! But commit fd867d51f889 is the one which started using netdev_update_features() in netdev_sync_lower_features(), your commits 00ee59271777 and 17b85d29e82c are both after it, and returning whatever doesn't matter before commit fd867d51f889, therefore, commit fd867d51f889 is the right one to blame?

I will send V3 to just update this Fixes tag.

Thanks!

#3 lore raw
Quoted 6 lines · Cong Wang
Quoted 3 lines · Nikolay Aleksandrov

The patch looks good, but note that __netdev_update_features() used to return -1 before the commit in the Fixes tag above (between 6cb6a27c45ce and 00ee59271777). It only restored that behaviour.

Quoted 6 lines

Good point! But commit fd867d51f889 is the one which started using netdev_update_features() in netdev_sync_lower_features(), your commits 00ee59271777 and 17b85d29e82c are both after it, and returning whatever doesn't matter before commit fd867d51f889, therefore, commit fd867d51f889 is the right one to blame?

Right, that should be the one.

Quoted 4 lines

I will send V3 to just update this Fixes tag.

Thanks!

Cheers,
Nik

Reviewed-by on v2 1/1
#4 lore raw
In reply to Cong Wang
Quoted 24 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 when the LRO feature fails to change, so it goes back and forth recursively until the kernel stack is exhausted.

Commit 17b85d29e82c intentionally lets __netdev_update_features() return -1 for such a failure case, so we have to just rely on the existing check inside netdev_sync_lower_features() and skip NETDEV_FEAT_CHANGE event only for this specific failure case.

Quoted 8 lines
Fixes 17b85d29e82c ("net/core: revert "net: fix __netdev_update_features return.." and add comment")
Reported-by [email protected]
Reported-by [email protected]
Cc Nikolay Aleksandrov <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Jay Vosburgh <[email protected]>
Cc Jann Horn <[email protected]>
Quoted 26 lines

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

1 file changed, 3 insertions(+), 1 deletion(-)
net/core/dev.c +3 -1
index 522288177bbd..6d327b7aa813 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_features_change(lower);
 		}
 	}
 }
Signature · 1 line
2.26.2