Skip to contentSkip to conversation

bonding: fix crash when no slave devices

PATCH Superseded Bernard Iremonger 3 participants 6 messages Feb 23, 2016 – Mar 11, 2016

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

PATCH 1/1 bonding: fix crash when no slave devices

If a bonded device is created when there are no slave devices there is loop in bond_ethdev_promiscous_enable() which results in a segmentation fault.
I have applied a similar fix to bond_ethdev_promiscous_disable() where a similar loop could occur.

Fixes 2efb58cbab6e ("bond: new link bonding library")
---
 drivers/net/bonding/rte_eth_bond_pmd.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/bonding/rte_eth_bond_pmd.c +4 -2
index b63c886..78972fc 100644
@@ -1870,7 +1870,8 @@ bond_ethdev_promiscuous_enable(struct rte_eth_dev *eth_dev)
 	case BONDING_MODE_TLB:
 	case BONDING_MODE_ALB:
 	default:
-		rte_eth_promiscuous_enable(internals->current_primary_port);
+		if (internals->slave_count > 0)
+			rte_eth_promiscuous_enable(internals->current_primary_port);
 	}
 }
 
@@ -1898,7 +1899,8 @@ bond_ethdev_promiscuous_disable(struct rte_eth_dev *dev)
 	case BONDING_MODE_TLB:
 	case BONDING_MODE_ALB:
 	default:
-		rte_eth_promiscuous_disable(internals->current_primary_port);
+		if (internals->slave_count > 0)
+			rte_eth_promiscuous_disable(internals->current_primary_port);
 	}
 }
 
Signature · 1 line
2.6.3
#1 lore raw
Quoted 28 lines · Bernard Iremonger

If a bonded device is created when there are no slave devices there is loop in bond_ethdev_promiscous_enable() which results in a segmentation fault.
I have applied a similar fix to bond_ethdev_promiscous_disable() where a similar loop could occur.

Fixes 2efb58cbab6e ("bond: new link bonding library")
---
 drivers/net/bonding/rte_eth_bond_pmd.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/bonding/rte_eth_bond_pmd.c +2 -1
index b63c886..78972fc 100644
@@ -1870,7 +1870,8 @@ bond_ethdev_promiscuous_enable(struct rte_eth_dev *eth_dev)
 	case BONDING_MODE_TLB:
 	case BONDING_MODE_ALB:
 	default:
-		rte_eth_promiscuous_enable(internals->current_primary_port);
+		if (internals->slave_count > 0)
+			rte_eth_promiscuous_enable(internals->current_primary_port);
 	}
 }
 

drivers/net/bonding/rte_eth_bond_pmd.c bond_ethdev_promiscuous_disable(struct rte_eth_dev *dev) · line 1906

Quoted 9 lines
drivers/net/bonding/rte_eth_bond_pmd.c +2 -1
@@ -1898,7 +1899,8 @@ bond_ethdev_promiscuous_disable(struct rte_eth_dev *dev)
 	case BONDING_MODE_TLB:
 	case BONDING_MODE_ALB:
 	default:
-		rte_eth_promiscuous_disable(internals->current_primary_port);
+		if (internals->slave_count > 0)
+			rte_eth_promiscuous_disable(internals->current_primary_port);
 	}
 }
 

Hi Bernard,

The reason of this crash is when there is no slave, the value of current_primary_port is 0, which is valid port_id, is this correct?

Does it make sense, instead of slave_count check, to make default current_primary_port value a non valid port_id, like -1, so is_valid_port() check catches it to prevents crash? For this and any other cases.

Thanks,
ferruh

#2 lore raw

Hi Ferruh,

Quoted 53 lines

-----Original Message-----
From: Yigit, Ferruh
Sent: Friday, March 4, 2016 5:14 PM
To: Iremonger, Bernard <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH] bonding: fix crash when no slave devices

drivers/net/bonding/rte_eth_bond_pmd.c bond_ethdev_promiscuous_enable(struct

Quoted 18 lines · Bernard Iremonger

If a bonded device is created when there are no slave devices there is loop in bond_ethdev_promiscous_enable() which results in a segmentation fault.
I have applied a similar fix to bond_ethdev_promiscous_disable() where a similar loop could occur.

Fixes 2efb58cbab6e ("bond: new link bonding library")
---
 drivers/net/bonding/rte_eth_bond_pmd.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/bonding/rte_eth_bond_pmd.c +0 -0
index b63c886..78972fc 100644
@@ -1870,7 +1870,8 @@ bond_ethdev_promiscuous_enable(struct

rte_eth_dev *eth_dev)

drivers/net/bonding/rte_eth_bond_pmd.c bond_ethdev_promiscuous_disable(struct

Quoted 12 lines
drivers/net/bonding/rte_eth_bond_pmd.c +2 -1
 	case BONDING_MODE_TLB:
 	case BONDING_MODE_ALB:
 	default:
-		rte_eth_promiscuous_enable(internals-
 current_primary_port);
+		if (internals->slave_count > 0)
+			rte_eth_promiscuous_enable(internals-
 current_primary_port);
 	}

}

drivers/net/bonding/rte_eth_bond_pmd.c +0 -0
@@ -1898,7 +1899,8 @@ bond_ethdev_promiscuous_disable(struct

rte_eth_dev *dev)

Quoted 9 lines
drivers/net/bonding/rte_eth_bond_pmd.c +2 -1
 	case BONDING_MODE_TLB:
 	case BONDING_MODE_ALB:
 	default:
-		rte_eth_promiscuous_disable(internals-
 current_primary_port);
+		if (internals->slave_count > 0)
+			rte_eth_promiscuous_disable(internals-
 current_primary_port);
 	}
Quoted 3 lines

}

Hi Bernard,

Quoted 2 lines

The reason of this crash is when there is no slave, the value of current_primary_port is 0, which is valid port_id, is this correct?

Yes.

Quoted 7 lines

Does it make sense, instead of slave_count check, to make default current_primary_port value a non valid port_id, like -1, so is_valid_port() check catches it to prevents crash? For this and any other cases.

Thanks,
Ferruh

I will try initializing current_primary_port to -1 and see if this helps. Thanks for reviewing.

Regards,

Bernard.

#3 lore raw

PATCH v2 1/1 bonding: fix crash when no slave devices

In reply to Bernard Iremonger

If a bonded device is created when there are no slave devices there is loop in bond_ethdev_promiscous_enable() which results in a segmentation fault.

The solution is to initialise the current_primary_port to an invalid port value when the bonded port is created.

Fixes 2efb58cbab6e ("bond: new link bonding library")

---
Changes in V2:
Set current_primary_port to an invalid value.

 drivers/net/bonding/rte_eth_bond_api.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/bonding/rte_eth_bond_api.c +1 -1
index a0995ec..1d67a0c 100644
@@ -231,7 +231,7 @@ rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id)
 
 	internals->port_id = eth_dev->data->port_id;
 	internals->mode = BONDING_MODE_INVALID;
-	internals->current_primary_port = 0;
+	internals->current_primary_port = RTE_MAX_ETHPORTS + 1;
 	internals->balance_xmit_policy = BALANCE_XMIT_POLICY_LAYER2;
 	internals->xmit_hash = xmit_l2_hash;
 	internals->user_defined_mac = 0;
Signature · 1 line
2.6.3
Acked-by on v2 1/1
#4 lore raw
Quoted 9 lines · Bernard Iremonger

If a bonded device is created when there are no slave devices there is loop in bond_ethdev_promiscous_enable() which results in a segmentation fault.

The solution is to initialise the current_primary_port to an invalid port value when the bonded port is created.

Fixes 2efb58cbab6e ("bond: new link bonding library")
#5 lore raw
Quoted 5 lines · Ferruh Yigit
Quoted 4 lines · Bernard Iremonger

If a bonded device is created when there are no slave devices there is loop in bond_ethdev_promiscous_enable() which results in a segmentation fault.

Quoted 7 lines
Quoted 5 lines

The solution is to initialise the current_primary_port to an invalid port value when the bonded port is created.

Fixes 2efb58cbab6e ("bond: new link bonding library")

Applied to dpdk-next-net/rel_16_04

/Bruce