Skip to contentSkip to conversation

net/bonding: fix stack overflow in selection logic

PATCH Superseded [email protected] 5 participants 12 messages Aug 5, 2019 – Nov 15, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 net/bonding: fix stack overflow in selection logic

From: Krzysztof Kanas <[email protected]>

Bonding selection logic uses agg_bandwidth, agg_count indexed by port_id but those arrays are 8 entries long.

Fixes 6d72657ce379 ("net/bonding: add other aggregator modes")
---
 drivers/net/bonding/rte_eth_bond_8023ad.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/bonding/rte_eth_bond_8023ad.c +2 -2
index d764dad331ed..89a8ba3de963 100644
@@ -670,8 +670,8 @@ selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
 	struct port *agg, *port;
 	uint16_t slaves_count, new_agg_id, i, j = 0;
 	uint16_t *slaves;
-	uint64_t agg_bandwidth[8] = {0};
-	uint64_t agg_count[8] = {0};
+	uint64_t agg_bandwidth[RTE_MAX_ETHPORTS] = {0};
+	uint64_t agg_count[RTE_MAX_ETHPORTS] = {0};
 	uint16_t default_slave = 0;
 	uint8_t mode_count_id, mode_band_id;
 	struct rte_eth_link link_info;
Signature · 1 line
2.21.0
#1 lore raw

PATCH 2/2 net/bonding: fix selection logic

From: Krzysztof Kanas <[email protected]>

Fix max_index to return uint16_t as it is valid slave_id type.

Arrays agg_count and agg_bandwidth should be indexed by slave_id not by aggregator port_id.

Fixes 6d72657ce379 ("net/bonding: add other aggregator modes")
---
 drivers/net/bonding/rte_eth_bond_8023ad.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
drivers/net/bonding/rte_eth_bond_8023ad.c +8 -10
index 89a8ba3de963..b923e69ef23a 100644
@@ -639,7 +639,7 @@ tx_machine(struct bond_dev_private *internals, uint16_t slave_id)
 	SM_FLAG_CLR(port, NTT);
 }
 
-static uint8_t
+static uint16_t
 max_index(uint64_t *a, int n)
 {
 	if (n <= 0)
@@ -673,8 +673,8 @@ selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
 	uint64_t agg_bandwidth[RTE_MAX_ETHPORTS] = {0};
 	uint64_t agg_count[RTE_MAX_ETHPORTS] = {0};
 	uint16_t default_slave = 0;
-	uint8_t mode_count_id, mode_band_id;
 	struct rte_eth_link link_info;
+	uint16_t agg_new_idx = 0;
 
 	slaves = internals->active_slaves;
 	slaves_count = internals->active_slave_count;
@@ -687,9 +687,9 @@ selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
 		if (agg->aggregator_port_id != slaves[i])
 			continue;
 
-		agg_count[agg->aggregator_port_id] += 1;
+		agg_count[i] += 1;
 		rte_eth_link_get_nowait(slaves[i], &link_info);
-		agg_bandwidth[agg->aggregator_port_id] += link_info.link_speed;
+		agg_bandwidth[i] += link_info.link_speed;
 
 		/* Actors system ID is not checked since all slave device have the same
 		 * ID (MAC address). */
@@ -710,14 +710,12 @@ selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
 
 	switch (internals->mode4.agg_selection) {
 	case AGG_COUNT:
-		mode_count_id = max_index(
-				(uint64_t *)agg_count, slaves_count);
-		new_agg_id = mode_count_id;
+		agg_new_idx = max_index(agg_count, slaves_count);
+		new_agg_id = slaves[agg_new_idx];
 		break;
 	case AGG_BANDWIDTH:
-		mode_band_id = max_index(
-				(uint64_t *)agg_bandwidth, slaves_count);
-		new_agg_id = mode_band_id;
+		agg_new_idx = max_index(agg_bandwidth, slaves_count);
+		new_agg_id = slaves[agg_new_idx];
 		break;
 	case AGG_STABLE:
 		if (default_slave == slaves_count)
Signature · 1 line
2.21.0
#2 lore raw

Re: [dpdk-dev] [PATCH 2/2] net/bonding: fix selection logic

Quoted 6 lines · On 8/5/2019 3:44 PM, [email protected] wrote:

From: Krzysztof Kanas <[email protected]>

Fix max_index to return uint16_t as it is valid slave_id type.

Arrays agg_count and agg_bandwidth should be indexed by slave_id not by aggregator port_id.

The port_id type has been fixed already with another patch [1] and it has been merged, but this patch does more,
Can you please send a new version on top of latest next-net?

[1]
https://patches.dpdk.org/patch/51491/
Commit b15a8a91432b ("net/bonding: fix more incorrect slave id types")

Quoted 64 lines
Fixes 6d72657ce379 ("net/bonding: add other aggregator modes")
---
 drivers/net/bonding/rte_eth_bond_8023ad.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
drivers/net/bonding/rte_eth_bond_8023ad.c +8 -10
index 89a8ba3de963..b923e69ef23a 100644
@@ -639,7 +639,7 @@ tx_machine(struct bond_dev_private *internals, uint16_t slave_id)
 	SM_FLAG_CLR(port, NTT);
 }
 
-static uint8_t
+static uint16_t
 max_index(uint64_t *a, int n)
 {
 	if (n <= 0)
@@ -673,8 +673,8 @@ selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
 	uint64_t agg_bandwidth[RTE_MAX_ETHPORTS] = {0};
 	uint64_t agg_count[RTE_MAX_ETHPORTS] = {0};
 	uint16_t default_slave = 0;
-	uint8_t mode_count_id, mode_band_id;
 	struct rte_eth_link link_info;
+	uint16_t agg_new_idx = 0;
 
 	slaves = internals->active_slaves;
 	slaves_count = internals->active_slave_count;
@@ -687,9 +687,9 @@ selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
 		if (agg->aggregator_port_id != slaves[i])
 			continue;
 
-		agg_count[agg->aggregator_port_id] += 1;
+		agg_count[i] += 1;
 		rte_eth_link_get_nowait(slaves[i], &link_info);
-		agg_bandwidth[agg->aggregator_port_id] += link_info.link_speed;
+		agg_bandwidth[i] += link_info.link_speed;
 
 		/* Actors system ID is not checked since all slave device have the same
 		 * ID (MAC address). */
@@ -710,14 +710,12 @@ selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
 
 	switch (internals->mode4.agg_selection) {
 	case AGG_COUNT:
-		mode_count_id = max_index(
-				(uint64_t *)agg_count, slaves_count);
-		new_agg_id = mode_count_id;
+		agg_new_idx = max_index(agg_count, slaves_count);
+		new_agg_id = slaves[agg_new_idx];
 		break;
 	case AGG_BANDWIDTH:
-		mode_band_id = max_index(
-				(uint64_t *)agg_bandwidth, slaves_count);
-		new_agg_id = mode_band_id;
+		agg_new_idx = max_index(agg_bandwidth, slaves_count);
+		new_agg_id = slaves[agg_new_idx];
 		break;
 	case AGG_STABLE:
 		if (default_slave == slaves_count)
#3 lore raw

PATCH v2 1/1 net/bonding: fix selection logic

From: Krzysztof Kanas <[email protected]>

Arrays agg_count and agg_bandwidth should be indexed by slave_id not by aggregator port_id.

Fixes 6d72657ce379 ("net/bonding: add other aggregator modes")
---
 drivers/net/bonding/rte_eth_bond_8023ad.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/net/bonding/rte_eth_bond_8023ad.c +7 -8
index 7d8da2b318f5..5b489b070b09 100644
@@ -673,9 +673,8 @@ selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
 	uint64_t agg_bandwidth[RTE_MAX_ETHPORTS] = {0};
 	uint64_t agg_count[RTE_MAX_ETHPORTS] = {0};
 	uint16_t default_slave = 0;
-	uint16_t mode_count_id;
-	uint16_t mode_band_id;
 	struct rte_eth_link link_info;
+	uint16_t agg_new_idx = 0;
 	int ret;
 
 	slaves = internals->active_slaves;
@@ -696,8 +695,8 @@ selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
 				slaves[i], rte_strerror(-ret));
 			continue;
 		}
-		agg_count[agg->aggregator_port_id] += 1;
-		agg_bandwidth[agg->aggregator_port_id] += link_info.link_speed;
+		agg_count[i] += 1;
+		agg_bandwidth[i] += link_info.link_speed;
 
 		/* Actors system ID is not checked since all slave device have the same
 		 * ID (MAC address). */
@@ -717,13 +716,13 @@ selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
 	}
 
 	switch (internals->mode4.agg_selection) {
+		agg_new_idx = max_index(agg_count, slaves_count);
+		new_agg_id = slaves[agg_new_idx];
 	case AGG_COUNT:
-		mode_count_id = max_index(agg_count, slaves_count);
-		new_agg_id = mode_count_id;
 		break;
 	case AGG_BANDWIDTH:
-		mode_band_id = max_index(agg_bandwidth, slaves_count);
-		new_agg_id = mode_band_id;
+		agg_new_idx = max_index(agg_bandwidth, slaves_count);
+		new_agg_id = slaves[agg_new_idx];
 		break;
 	case AGG_STABLE:
 		if (default_slave == slaves_count)
Signature · 1 line
2.21.0
#4 lore raw

Re: [dpdk-dev] [PATCH v2] net/bonding: fix selection logic

Quoted 40 lines · On 10/10/19 4:27 AM, [email protected] wrote:

From: Krzysztof Kanas <[email protected]>

Arrays agg_count and agg_bandwidth should be indexed by slave_id not by aggregator port_id.

Fixes 6d72657ce379 ("net/bonding: add other aggregator modes")
---
  drivers/net/bonding/rte_eth_bond_8023ad.c | 15 +++++++--------
  1 file changed, 7 insertions(+), 8 deletions(-)
drivers/net/bonding/rte_eth_bond_8023ad.c +3 -4
index 7d8da2b318f5..5b489b070b09 100644
@@ -673,9 +673,8 @@ selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
  	uint64_t agg_bandwidth[RTE_MAX_ETHPORTS] = {0};
  	uint64_t agg_count[RTE_MAX_ETHPORTS] = {0};
  	uint16_t default_slave = 0;
-	uint16_t mode_count_id;
-	uint16_t mode_band_id;
  	struct rte_eth_link link_info;
+	uint16_t agg_new_idx = 0;
  	int ret;
 
  	slaves = internals->active_slaves;
@@ -696,8 +695,8 @@ selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
  				slaves[i], rte_strerror(-ret));
  			continue;
  		}
-		agg_count[agg->aggregator_port_id] += 1;
-		agg_bandwidth[agg->aggregator_port_id] += link_info.link_speed;
+		agg_count[i] += 1;
+		agg_bandwidth[i] += link_info.link_speed;
 
  		/* Actors system ID is not checked since all slave device have the same
  		 * ID (MAC address). */

drivers/net/bonding/rte_eth_bond_8023ad.c selection_logic(struct bond_dev_private *internals, uint16_t slave_id) · line 722

Quoted 8 lines
drivers/net/bonding/rte_eth_bond_8023ad.c +2 -2
@@ -717,13 +716,13 @@ selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
  	}
 
  	switch (internals->mode4.agg_selection) {
+		agg_new_idx = max_index(agg_count, slaves_count);
+		new_agg_id = slaves[agg_new_idx];
  	case AGG_COUNT:
-		mode_count_id = max_index(agg_count, slaves_count);
-		new_agg_id = mode_count_id;

This change doesn't look right. Did you really want to do this, put the code outside of the case statement?

Quoted 10 lines
drivers/net/bonding/rte_eth_bond_8023ad.c +2 -2
  		break;
  	case AGG_BANDWIDTH:
-		mode_band_id = max_index(agg_bandwidth, slaves_count);
-		new_agg_id = mode_band_id;
+		agg_new_idx = max_index(agg_bandwidth, slaves_count);
+		new_agg_id = slaves[agg_new_idx];
  		break;
  	case AGG_STABLE:
  		if (default_slave == slaves_count)
#5 lore raw

PATCH v3 1/1 net/bonding: fix selection logic

From: Krzysztof Kanas <[email protected]>

Arrays agg_count and agg_bandwidth should be indexed by slave_id not by aggregator port_id.

Fixes 6d72657ce379 ("net/bonding: add other aggregator modes")

---
v3:
* fix incorrect reabse
v2:
* rebase patch to latest master

 drivers/net/bonding/rte_eth_bond_8023ad.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

--

drivers/net/bonding/rte_eth_bond_8023ad.c +7 -8
index 7d8da2b318f5..698311e15c31 100644
@@ -673,9 +673,8 @@ selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
 	uint64_t agg_bandwidth[RTE_MAX_ETHPORTS] = {0};
 	uint64_t agg_count[RTE_MAX_ETHPORTS] = {0};
 	uint16_t default_slave = 0;
-	uint16_t mode_count_id;
-	uint16_t mode_band_id;
 	struct rte_eth_link link_info;
+	uint16_t agg_new_idx = 0;
 	int ret;
 
 	slaves = internals->active_slaves;
@@ -696,8 +695,8 @@ selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
 				slaves[i], rte_strerror(-ret));
 			continue;
 		}
-		agg_count[agg->aggregator_port_id] += 1;
-		agg_bandwidth[agg->aggregator_port_id] += link_info.link_speed;
+		agg_count[i] += 1;
+		agg_bandwidth[i] += link_info.link_speed;
 
 		/* Actors system ID is not checked since all slave device have the same
 		 * ID (MAC address). */
@@ -718,12 +717,12 @@ selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
 
 	switch (internals->mode4.agg_selection) {
 	case AGG_COUNT:
-		mode_count_id = max_index(agg_count, slaves_count);
-		new_agg_id = mode_count_id;
+		agg_new_idx = max_index(agg_count, slaves_count);
+		new_agg_id = slaves[agg_new_idx];
 		break;
 	case AGG_BANDWIDTH:
-		mode_band_id = max_index(agg_bandwidth, slaves_count);
-		new_agg_id = mode_band_id;
+		agg_new_idx = max_index(agg_bandwidth, slaves_count);
+		new_agg_id = slaves[agg_new_idx];
 		break;
 	case AGG_STABLE:
 		if (default_slave == slaves_count)
Signature · 1 line
2.21.0
#6 lore raw

Re: [dpdk-dev] [PATCH v3] net/bonding: fix selection logic

This looks better. While reviewing this I noticed that a few lines:

        case AGG_STABLE:
                if (default_slave == slaves_count)
                        new_agg_id = slave_id;  <<<<<<<<<<<<<<<<<
                else
                        new_agg_id = slaves[default_slave];
                break;
        default:
                if (default_slave == slaves_count)
                        new_agg_id = slave_id;	<<<<<<<<<<<<<
                else
                        new_agg_id = slaves[default_slave];
                break;
        }

I don't think the new_agg_id should be the slave_id directly but rather slaves[slave_id]. Would you mind fixing that as well here if that is the case?

Quoted 63 lines · On 10/11/19 2:34 AM, [email protected] wrote:

From: Krzysztof Kanas <[email protected]>

Arrays agg_count and agg_bandwidth should be indexed by slave_id not by aggregator port_id.

Fixes 6d72657ce379 ("net/bonding: add other aggregator modes")

---
v3:
* fix incorrect reabse
v2:
* rebase patch to latest master

  drivers/net/bonding/rte_eth_bond_8023ad.c | 15 +++++++--------
  1 file changed, 7 insertions(+), 8 deletions(-)

--

drivers/net/bonding/rte_eth_bond_8023ad.c +7 -8
index 7d8da2b318f5..698311e15c31 100644
@@ -673,9 +673,8 @@ selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
  	uint64_t agg_bandwidth[RTE_MAX_ETHPORTS] = {0};
  	uint64_t agg_count[RTE_MAX_ETHPORTS] = {0};
  	uint16_t default_slave = 0;
-	uint16_t mode_count_id;
-	uint16_t mode_band_id;
  	struct rte_eth_link link_info;
+	uint16_t agg_new_idx = 0;
  	int ret;
 
  	slaves = internals->active_slaves;
@@ -696,8 +695,8 @@ selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
  				slaves[i], rte_strerror(-ret));
  			continue;
  		}
-		agg_count[agg->aggregator_port_id] += 1;
-		agg_bandwidth[agg->aggregator_port_id] += link_info.link_speed;
+		agg_count[i] += 1;
+		agg_bandwidth[i] += link_info.link_speed;
 
  		/* Actors system ID is not checked since all slave device have the same
  		 * ID (MAC address). */
@@ -718,12 +717,12 @@ selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
 
  	switch (internals->mode4.agg_selection) {
  	case AGG_COUNT:
-		mode_count_id = max_index(agg_count, slaves_count);
-		new_agg_id = mode_count_id;
+		agg_new_idx = max_index(agg_count, slaves_count);
+		new_agg_id = slaves[agg_new_idx];
  		break;
  	case AGG_BANDWIDTH:
-		mode_band_id = max_index(agg_bandwidth, slaves_count);
-		new_agg_id = mode_band_id;
+		agg_new_idx = max_index(agg_bandwidth, slaves_count);
+		new_agg_id = slaves[agg_new_idx];
  		break;
  	case AGG_STABLE:
  		if (default_slave == slaves_count)
#7 lore raw

PATCH v4 1/1 net/bonding: fix selection logic

From: Krzysztof Kanas <[email protected]>

Arrays agg_count and agg_bandwidth should be indexed by slave_id not by aggregator port_id.

The new_agg_id should be chosen as slave_id from slaves table in different selection modes.

Fixes 6d72657ce379 ("net/bonding: add other aggregator modes")

---
v4:
* add fix for new_agg_id in AGG_COUNT and AGG_STABLE agg_selection
v3:
* fix incorrect reabse
v2:
* rebase patch to latest maste

---
 drivers/net/bonding/rte_eth_bond_8023ad.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/net/bonding/rte_eth_bond_8023ad.c +9 -10
index 7d8da2b318f5..19e2e880a808 100644
@@ -673,9 +673,8 @@ selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
 	uint64_t agg_bandwidth[RTE_MAX_ETHPORTS] = {0};
 	uint64_t agg_count[RTE_MAX_ETHPORTS] = {0};
 	uint16_t default_slave = 0;
-	uint16_t mode_count_id;
-	uint16_t mode_band_id;
 	struct rte_eth_link link_info;
+	uint16_t agg_new_idx = 0;
 	int ret;
 
 	slaves = internals->active_slaves;
@@ -696,8 +695,8 @@ selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
 				slaves[i], rte_strerror(-ret));
 			continue;
 		}
-		agg_count[agg->aggregator_port_id] += 1;
-		agg_bandwidth[agg->aggregator_port_id] += link_info.link_speed;
+		agg_count[i] += 1;
+		agg_bandwidth[i] += link_info.link_speed;
 
 		/* Actors system ID is not checked since all slave device have the same
 		 * ID (MAC address). */
@@ -718,22 +717,22 @@ selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
 
 	switch (internals->mode4.agg_selection) {
 	case AGG_COUNT:
-		mode_count_id = max_index(agg_count, slaves_count);
-		new_agg_id = mode_count_id;
+		agg_new_idx = max_index(agg_count, slaves_count);
+		new_agg_id = slaves[agg_new_idx];
 		break;
 	case AGG_BANDWIDTH:
-		mode_band_id = max_index(agg_bandwidth, slaves_count);
-		new_agg_id = mode_band_id;
+		agg_new_idx = max_index(agg_bandwidth, slaves_count);
+		new_agg_id = slaves[agg_new_idx];
 		break;
 	case AGG_STABLE:
 		if (default_slave == slaves_count)
-			new_agg_id = slave_id;
+			new_agg_id = slaves[slave_id];
 		else
 			new_agg_id = slaves[default_slave];
 		break;
 	default:
 		if (default_slave == slaves_count)
-			new_agg_id = slave_id;
+			new_agg_id = slaves[slave_id];
 		else
 			new_agg_id = slaves[default_slave];
 		break;
Signature · 1 line
2.21.0
Acked-by Chas Williams Acked-by on v4 1/1 Applied
#8 lore raw

Re: [dpdk-dev] [PATCH v4] net/bonding: fix selection logic

Quoted 5 lines · On 11/13/2019 8:22 AM, [email protected] wrote:

From: Krzysztof Kanas <[email protected]>

Arrays agg_count and agg_bandwidth should be indexed by slave_id not by aggregator port_id.

Quoted 7 lines

The new_agg_id should be chosen as slave_id from slaves table in different selection modes.

Fixes 6d72657ce379 ("net/bonding: add other aggregator modes")

Adding Chas' implied ack, since the change request from him, please let me know if this is wrong:

Applied to dpdk-next-net/master, thanks

#10 lore raw
Quoted 5 lines · David Marchand

External Email

----------------------------------------------------------------------

Quoted 1 line · On Mon, Aug 5, 2019 at 4:46 PM <[email protected]> wrote:
Quoted 9 lines
Quoted 4 lines

From: Krzysztof Kanas <[email protected]>

Bonding selection logic uses agg_bandwidth, agg_count indexed by port_id but those arrays are 8 entries long.

Idem http://mails.dpdk.org/archives/dev/2019-July/140020.html

I did not get a reply from you.

Sorry I have look at mailing list and looked that discussion stooped at
http://mails.dpdk.org/archives/dev/2019-March/127444.html
So I prepared fix for and wanted to reply to that thread with new patches.

Unfortunately I added '--reply-to' to git send-email command and not --in-reply-to as I should have done.

Quoted 3 lines
Signature · 2 lines
-- 
David Marchand
#11 lore raw
In reply to [email protected]
Quoted 9 lines · On 8/5/2019 3:44 PM, [email protected] wrote:

From: Krzysztof Kanas <[email protected]>

Bonding selection logic uses agg_bandwidth, agg_count indexed by port_id but those arrays are 8 entries long.

Fixes 6d72657ce379 ("net/bonding: add other aggregator modes")

This is duplication of the an existing patch [1] which has been merged now, rejecting this one.

[1] https://patchwork.dpdk.org/patch/51492/