Skip to contentSkip to conversation

net/bonding: fix segfault using invalid port

PATCH Superseded Jiang JunyuX 5 participants 12 messages Oct 25, 2019 – Oct 30, 2019

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

PATCH 1/1 net/bonding: fix segfault using invalid port

Port validation should be prior to getting dev data to avoid segmentation fault. This patch fixed the issue.

Fixes 6d72657ce379 ("net/bonding: add other aggregator modes")
Fixes 112891cd27e5 ("net/bonding: add dedicated HW queues for LACP control")
---
 drivers/net/bonding/rte_eth_bond_8023ad.c | 32 ++++++++++++++++-------
 1 file changed, 22 insertions(+), 10 deletions(-)
drivers/net/bonding/rte_eth_bond_8023ad.c +22 -10
index 7d8da2b31..682854e39 100644
@@ -1387,11 +1387,12 @@ rte_eth_bond_8023ad_agg_selection_set(uint16_t port_id,
 	struct bond_dev_private *internals;
 	struct mode8023ad_private *mode4;
 
+	if (valid_bonded_port_id(port_id) != 0)
+		return -EINVAL;
+
 	bond_dev = &rte_eth_devices[port_id];
 	internals = bond_dev->data->dev_private;
 
-	if (valid_bonded_port_id(port_id) != 0)
-		return -EINVAL;
 	if (internals->mode != 4)
 		return -EINVAL;
 
@@ -1408,11 +1409,12 @@ int rte_eth_bond_8023ad_agg_selection_get(uint16_t port_id)
 	struct bond_dev_private *internals;
 	struct mode8023ad_private *mode4;
 
+	if (valid_bonded_port_id(port_id) != 0)
+		return -EINVAL;
+
 	bond_dev = &rte_eth_devices[port_id];
 	internals = bond_dev->data->dev_private;
 
-	if (valid_bonded_port_id(port_id) != 0)
-		return -EINVAL;
 	if (internals->mode != 4)
 		return -EINVAL;
 	mode4 = &internals->mode4;
@@ -1665,9 +1667,14 @@ int
 rte_eth_bond_8023ad_dedicated_queues_enable(uint16_t port)
 {
 	int retval = 0;
-	struct rte_eth_dev *dev = &rte_eth_devices[port];
-	struct bond_dev_private *internals = (struct bond_dev_private *)
-		dev->data->dev_private;
+	struct rte_eth_dev *dev;
+	struct bond_dev_private *internals;
+
+	if (valid_bonded_port_id(port) != 0)
+		return -EINVAL;
+
+	dev = &rte_eth_devices[port];
+	internals = dev->data->dev_private;
 
 	if (check_for_bonded_ethdev(dev) != 0)
 		return -1;
@@ -1689,9 +1696,14 @@ int
 rte_eth_bond_8023ad_dedicated_queues_disable(uint16_t port)
 {
 	int retval = 0;
-	struct rte_eth_dev *dev = &rte_eth_devices[port];
-	struct bond_dev_private *internals = (struct bond_dev_private *)
-		dev->data->dev_private;
+	struct rte_eth_dev *dev;
+	struct bond_dev_private *internals;
+
+	if (valid_bonded_port_id(port) != 0)
+		return -EINVAL;
+
+	dev = &rte_eth_devices[port];
+	internals = dev->data->dev_private;
 
 	if (check_for_bonded_ethdev(dev) != 0)
 		return -1;
Signature · 1 line
2.17.1
#1 lore raw

Hi, Junyu

Quoted 62 lines

-----Original Message-----
From: Jiang, JunyuX
Sent: Friday, October 25, 2019 4:56 AM
To: [email protected]
Cc: Chas Williams <[email protected]>; Yang, Qiming <[email protected]>; Jiang, JunyuX <[email protected]>; [email protected]
Subject: [PATCH] net/bonding: fix segfault using invalid port

Port validation should be prior to getting dev data to avoid segmentation fault. This patch fixed the issue.

Fixes 6d72657ce379 ("net/bonding: add other aggregator modes")
Fixes 112891cd27e5 ("net/bonding: add dedicated HW queues for LACP

control")
Cc: [email protected]

---
 drivers/net/bonding/rte_eth_bond_8023ad.c | 32 ++++++++++++++++-------
 1 file changed, 22 insertions(+), 10 deletions(-)
drivers/net/bonding/rte_eth_bond_8023ad.c +6 -4
index 7d8da2b31..682854e39 100644
@@ -1387,11 +1387,12 @@
 rte_eth_bond_8023ad_agg_selection_set(uint16_t port_id,
 	struct bond_dev_private *internals;
 	struct mode8023ad_private *mode4;
 
+	if (valid_bonded_port_id(port_id) != 0)
+		return -EINVAL;
+
 	bond_dev = &rte_eth_devices[port_id];
 	internals = bond_dev->data->dev_private;
 
-	if (valid_bonded_port_id(port_id) != 0)
-		return -EINVAL;
 	if (internals->mode != 4)
 		return -EINVAL;
@@ -1408,11 +1409,12 @@ int
 rte_eth_bond_8023ad_agg_selection_get(uint16_t port_id)
 	struct bond_dev_private *internals;
 	struct mode8023ad_private *mode4;
 
+	if (valid_bonded_port_id(port_id) != 0)
+		return -EINVAL;
+
 	bond_dev = &rte_eth_devices[port_id];
 	internals = bond_dev->data->dev_private;
 
-	if (valid_bonded_port_id(port_id) != 0)
-		return -EINVAL;
 	if (internals->mode != 4)
 		return -EINVAL;
drivers/net/bonding/rte_eth_bond_8023ad.c +0 -1
 	mode4 = &internals->mode4;
@@ -1665,9 +1667,14 @@ int
 rte_eth_bond_8023ad_dedicated_queues_enable(uint16_t port)  {
 	int retval = 0;
-	struct rte_eth_dev *dev = &rte_eth_devices[port];

drivers/net/bonding/rte_eth_bond_8023ad.c int · line 1676

Quoted 10 lines
drivers/net/bonding/rte_eth_bond_8023ad.c +8 -2
-	struct bond_dev_private *internals = (struct bond_dev_private *)
-		dev->data->dev_private;
+	struct rte_eth_dev *dev;
+	struct bond_dev_private *internals;
+
+	if (valid_bonded_port_id(port) != 0)
+		return -EINVAL;
+
+	dev = &rte_eth_devices[port];
+	internals = dev->data->dev_private;

Have you build success? I think we need to add (struct bond_dev_private *) for force transfer

Quoted 7 lines
drivers/net/bonding/rte_eth_bond_8023ad.c +0 -1
 	if (check_for_bonded_ethdev(dev) != 0)
 		return -1;
@@ -1689,9 +1696,14 @@ int
 rte_eth_bond_8023ad_dedicated_queues_disable(uint16_t port)  {
 	int retval = 0;
-	struct rte_eth_dev *dev = &rte_eth_devices[port];

drivers/net/bonding/rte_eth_bond_8023ad.c int · line 1705

Quoted 10 lines
drivers/net/bonding/rte_eth_bond_8023ad.c +8 -2
-	struct bond_dev_private *internals = (struct bond_dev_private *)
-		dev->data->dev_private;
+	struct rte_eth_dev *dev;
+	struct bond_dev_private *internals;
+
+	if (valid_bonded_port_id(port) != 0)
+		return -EINVAL;
+
+	dev = &rte_eth_devices[port];
+	internals = dev->data->dev_private;

Same as before

Quoted 5 lines
drivers/net/bonding/rte_eth_bond_8023ad.c +0 -1
 	if (check_for_bonded_ethdev(dev) != 0)
 		return -1;
--

2.17.1

#2 lore raw
Quoted 5 lines · Qiming

Hi, Junyu

Review

Quoted 2 lines
(quoted diff) +2 -0
+	dev = &rte_eth_devices[port];
+	internals = dev->data->dev_private;

Have you build success? I think we need to add (struct bond_dev_private *) for force transfer

dev_private is a void *, an explicit type conversion is not needed here.

Thanks,
Xiaolong

Quoted 26 lines
Quoted 8 lines
drivers/net/bonding/rte_eth_bond_8023ad.c +0 -1
 	if (check_for_bonded_ethdev(dev) != 0)
 		return -1;
@@ -1689,9 +1696,14 @@ int
 rte_eth_bond_8023ad_dedicated_queues_disable(uint16_t port)  {
 	int retval = 0;
-	struct rte_eth_dev *dev = &rte_eth_devices[port];

drivers/net/bonding/rte_eth_bond_8023ad.c int · line 1705

Quoted 10 lines
drivers/net/bonding/rte_eth_bond_8023ad.c +8 -2
-	struct bond_dev_private *internals = (struct bond_dev_private *)
-		dev->data->dev_private;
+	struct rte_eth_dev *dev;
+	struct bond_dev_private *internals;
+
+	if (valid_bonded_port_id(port) != 0)
+		return -EINVAL;
+
+	dev = &rte_eth_devices[port];
+	internals = dev->data->dev_private;

Same as before

Quoted 5 lines
drivers/net/bonding/rte_eth_bond_8023ad.c +0 -1
 	if (check_for_bonded_ethdev(dev) != 0)
 		return -1;
--

2.17.1

#3 lore raw
Quoted 9 lines

-----Original Message-----
From: Ye, Xiaolong
Sent: Tuesday, October 29, 2019 11:04 AM
To: Yang, Qiming <[email protected]>
Cc: Jiang, JunyuX <[email protected]>; [email protected]; Chas Williams <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH] net/bonding: fix segfault using invalid port

On 10/28, Yang, Qiming wrote:

Quoted 8 lines
Quoted 5 lines

Hi, Junyu

Review

Quoted 2 lines
(quoted diff) +2 -0
+	dev = &rte_eth_devices[port];
+	internals = dev->data->dev_private;

Have you build success? I think we need to add (struct bond_dev_private *)

for force transfer

dev_private is a void *, an explicit type conversion is not needed here.

OK, I saw the original code used.
- struct bond_dev_private *internals = (struct bond_dev_private *)
- dev->data->dev_private;

Quoted 29 lines

Thanks,
Xiaolong

Quoted 26 lines
Quoted 8 lines
drivers/net/bonding/rte_eth_bond_8023ad.c +0 -1
 	if (check_for_bonded_ethdev(dev) != 0)
 		return -1;
@@ -1689,9 +1696,14 @@ int
 rte_eth_bond_8023ad_dedicated_queues_disable(uint16_t port)  {
 	int retval = 0;
-	struct rte_eth_dev *dev = &rte_eth_devices[port];

drivers/net/bonding/rte_eth_bond_8023ad.c int · line 1705

Quoted 10 lines
drivers/net/bonding/rte_eth_bond_8023ad.c +8 -2
-	struct bond_dev_private *internals = (struct bond_dev_private *)
-		dev->data->dev_private;
+	struct rte_eth_dev *dev;
+	struct bond_dev_private *internals;
+
+	if (valid_bonded_port_id(port) != 0)
+		return -EINVAL;
+
+	dev = &rte_eth_devices[port];
+	internals = dev->data->dev_private;

Same as before

Quoted 5 lines
drivers/net/bonding/rte_eth_bond_8023ad.c +0 -1
 	if (check_for_bonded_ethdev(dev) != 0)
 		return -1;
--

2.17.1

#4 lore raw
Quoted 19 lines · Qiming
Quoted 9 lines

-----Original Message-----
From: Ye, Xiaolong
Sent: Tuesday, October 29, 2019 11:04 AM
To: Yang, Qiming <[email protected]>
Cc: Jiang, JunyuX <[email protected]>; [email protected]; Chas Williams <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH] net/bonding: fix segfault using invalid port

On 10/28, Yang, Qiming wrote:

Quoted 8 lines
Quoted 5 lines

Hi, Junyu

Review

Quoted 2 lines
(quoted diff) +2 -0
+	dev = &rte_eth_devices[port];
+	internals = dev->data->dev_private;

Have you build success? I think we need to add (struct bond_dev_private *)

for force transfer

dev_private is a void *, an explicit type conversion is not needed here.

OK, I saw the original code used.

Review

Quoted 2 lines
(quoted diff) +0 -2
-	struct bond_dev_private *internals = (struct bond_dev_private *)
-		dev->data->dev_private; 

The original cast is redundant, there is a patchset from Stephen before to cleanup these unnecessary casts.

http://patches.dpdk.org/cover/53858/

Thanks,
Xiaolong

Quoted 30 lines
Quoted 30 lines

Thanks,
Xiaolong

Quoted 26 lines
Quoted 8 lines
drivers/net/bonding/rte_eth_bond_8023ad.c +0 -1
 	if (check_for_bonded_ethdev(dev) != 0)
 		return -1;
@@ -1689,9 +1696,14 @@ int
 rte_eth_bond_8023ad_dedicated_queues_disable(uint16_t port)  {
 	int retval = 0;
-	struct rte_eth_dev *dev = &rte_eth_devices[port];

drivers/net/bonding/rte_eth_bond_8023ad.c int · line 1705

Quoted 10 lines
drivers/net/bonding/rte_eth_bond_8023ad.c +8 -2
-	struct bond_dev_private *internals = (struct bond_dev_private *)
-		dev->data->dev_private;
+	struct rte_eth_dev *dev;
+	struct bond_dev_private *internals;
+
+	if (valid_bonded_port_id(port) != 0)
+		return -EINVAL;
+
+	dev = &rte_eth_devices[port];
+	internals = dev->data->dev_private;

Same as before

Quoted 5 lines
drivers/net/bonding/rte_eth_bond_8023ad.c +0 -1
 	if (check_for_bonded_ethdev(dev) != 0)
 		return -1;
--

2.17.1

#5 lore raw

Thanks for the information, got it.

Qiming

Quoted 72 lines

-----Original Message-----
From: Ye, Xiaolong
Sent: Tuesday, October 29, 2019 2:26 PM
To: Yang, Qiming <[email protected]>
Cc: Jiang, JunyuX <[email protected]>; [email protected]; Chas Williams <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH] net/bonding: fix segfault using invalid port

Quoted 21 lines · Qiming
Quoted 12 lines

-----Original Message-----
From: Ye, Xiaolong
Sent: Tuesday, October 29, 2019 11:04 AM
To: Yang, Qiming <[email protected]>
Cc: Jiang, JunyuX <[email protected]>; [email protected]; Chas Williams <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH] net/bonding: fix segfault using invalid port

Quoted 2 lines · Qiming

Hi, Junyu

Quoted 7 lines
Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	dev = &rte_eth_devices[port];
+	internals = dev->data->dev_private;

Have you build success? I think we need to add (struct bond_dev_private *)

for force transfer

dev_private is a void *, an explicit type conversion is not needed here.

OK, I saw the original code used.

Review

Quoted 2 lines
(quoted diff) +0 -2
-	struct bond_dev_private *internals = (struct bond_dev_private *)
-		dev->data->dev_private;

The original cast is redundant, there is a patchset from Stephen before to cleanup these unnecessary casts.

http://patches.dpdk.org/cover/53858/

Thanks,
Xiaolong

Quoted 30 lines
Quoted 30 lines

Thanks,
Xiaolong

Quoted 26 lines
Quoted 8 lines
drivers/net/bonding/rte_eth_bond_8023ad.c +0 -1
 	if (check_for_bonded_ethdev(dev) != 0)
 		return -1;
@@ -1689,9 +1696,14 @@ int
 rte_eth_bond_8023ad_dedicated_queues_disable(uint16_t port)  {
 	int retval = 0;
-	struct rte_eth_dev *dev = &rte_eth_devices[port];

drivers/net/bonding/rte_eth_bond_8023ad.c int · line 1705

Quoted 10 lines
drivers/net/bonding/rte_eth_bond_8023ad.c +8 -2
-	struct bond_dev_private *internals = (struct bond_dev_private *)
-		dev->data->dev_private;
+	struct rte_eth_dev *dev;
+	struct bond_dev_private *internals;
+
+	if (valid_bonded_port_id(port) != 0)
+		return -EINVAL;
+
+	dev = &rte_eth_devices[port];
+	internals = dev->data->dev_private;

Same as before

Quoted 5 lines
drivers/net/bonding/rte_eth_bond_8023ad.c +0 -1
 	if (check_for_bonded_ethdev(dev) != 0)
 		return -1;
--

2.17.1

#6 lore raw

PATCH v2 1/1 net/bonding: fix segfault using invalid port

In reply to Jiang JunyuX

Port validation should be prior to getting dev data to avoid segmentation fault. This patch fixed the issue.

Fixes 6d72657ce379 ("net/bonding: add other aggregator modes")
Fixes 112891cd27e5 ("net/bonding: add dedicated HW queues for LACP control")
---
 drivers/net/bonding/rte_eth_bond_8023ad.c | 32 ++++++++++++++++-------
 1 file changed, 22 insertions(+), 10 deletions(-)
drivers/net/bonding/rte_eth_bond_8023ad.c +22 -10
index 7d8da2b31..cbab538e6 100644
@@ -1387,11 +1387,12 @@ rte_eth_bond_8023ad_agg_selection_set(uint16_t port_id,
 	struct bond_dev_private *internals;
 	struct mode8023ad_private *mode4;
 
+	if (valid_bonded_port_id(port_id) != 0)
+		return -EINVAL;
+
 	bond_dev = &rte_eth_devices[port_id];
 	internals = bond_dev->data->dev_private;
 
-	if (valid_bonded_port_id(port_id) != 0)
-		return -EINVAL;
 	if (internals->mode != 4)
 		return -EINVAL;
 
@@ -1408,11 +1409,12 @@ int rte_eth_bond_8023ad_agg_selection_get(uint16_t port_id)
 	struct bond_dev_private *internals;
 	struct mode8023ad_private *mode4;
 
+	if (valid_bonded_port_id(port_id) != 0)
+		return -EINVAL;
+
 	bond_dev = &rte_eth_devices[port_id];
 	internals = bond_dev->data->dev_private;
 
-	if (valid_bonded_port_id(port_id) != 0)
-		return -EINVAL;
 	if (internals->mode != 4)
 		return -EINVAL;
 	mode4 = &internals->mode4;
@@ -1665,9 +1667,14 @@ int
 rte_eth_bond_8023ad_dedicated_queues_enable(uint16_t port)
 {
 	int retval = 0;
-	struct rte_eth_dev *dev = &rte_eth_devices[port];
-	struct bond_dev_private *internals = (struct bond_dev_private *)
-		dev->data->dev_private;
+	struct rte_eth_dev *dev;
+	struct bond_dev_private *internals;
+
+	if (valid_bonded_port_id(port) != 0)
+		return -EINVAL;
+
+	dev = &rte_eth_devices[port];
+	internals = (struct bond_dev_private *)dev->data->dev_private;
 
 	if (check_for_bonded_ethdev(dev) != 0)
 		return -1;
@@ -1689,9 +1696,14 @@ int
 rte_eth_bond_8023ad_dedicated_queues_disable(uint16_t port)
 {
 	int retval = 0;
-	struct rte_eth_dev *dev = &rte_eth_devices[port];
-	struct bond_dev_private *internals = (struct bond_dev_private *)
-		dev->data->dev_private;
+	struct rte_eth_dev *dev;
+	struct bond_dev_private *internals;
+
+	if (valid_bonded_port_id(port) != 0)
+		return -EINVAL;
+
+	dev = &rte_eth_devices[port];
+	internals = (struct bond_dev_private *)dev->data->dev_private;
 
 	if (check_for_bonded_ethdev(dev) != 0)
 		return -1;
Signature · 1 line
2.17.1
#7 lore raw

PATCH v3 1/1 net/bonding: fix invalid port using

Port validation should be prior to getting device data to avoid segment fault. This patch fixed the segment fault caused by invalid port using.

Fixes 6d72657ce379 ("net/bonding: add other aggregator modes")
Fixes 112891cd27e5 ("net/bonding: add dedicated HW queues for LACP control")
---
 drivers/net/bonding/rte_eth_bond_8023ad.c | 32 ++++++++++++++++-------
 1 file changed, 22 insertions(+), 10 deletions(-)
drivers/net/bonding/rte_eth_bond_8023ad.c +22 -10
index 7d8da2b31..cbab538e6 100644
@@ -1387,11 +1387,12 @@ rte_eth_bond_8023ad_agg_selection_set(uint16_t port_id,
 	struct bond_dev_private *internals;
 	struct mode8023ad_private *mode4;
 
+	if (valid_bonded_port_id(port_id) != 0)
+		return -EINVAL;
+
 	bond_dev = &rte_eth_devices[port_id];
 	internals = bond_dev->data->dev_private;
 
-	if (valid_bonded_port_id(port_id) != 0)
-		return -EINVAL;
 	if (internals->mode != 4)
 		return -EINVAL;
 
@@ -1408,11 +1409,12 @@ int rte_eth_bond_8023ad_agg_selection_get(uint16_t port_id)
 	struct bond_dev_private *internals;
 	struct mode8023ad_private *mode4;
 
+	if (valid_bonded_port_id(port_id) != 0)
+		return -EINVAL;
+
 	bond_dev = &rte_eth_devices[port_id];
 	internals = bond_dev->data->dev_private;
 
-	if (valid_bonded_port_id(port_id) != 0)
-		return -EINVAL;
 	if (internals->mode != 4)
 		return -EINVAL;
 	mode4 = &internals->mode4;
@@ -1665,9 +1667,14 @@ int
 rte_eth_bond_8023ad_dedicated_queues_enable(uint16_t port)
 {
 	int retval = 0;
-	struct rte_eth_dev *dev = &rte_eth_devices[port];
-	struct bond_dev_private *internals = (struct bond_dev_private *)
-		dev->data->dev_private;
+	struct rte_eth_dev *dev;
+	struct bond_dev_private *internals;
+
+	if (valid_bonded_port_id(port) != 0)
+		return -EINVAL;
+
+	dev = &rte_eth_devices[port];
+	internals = (struct bond_dev_private *)dev->data->dev_private;
 
 	if (check_for_bonded_ethdev(dev) != 0)
 		return -1;
@@ -1689,9 +1696,14 @@ int
 rte_eth_bond_8023ad_dedicated_queues_disable(uint16_t port)
 {
 	int retval = 0;
-	struct rte_eth_dev *dev = &rte_eth_devices[port];
-	struct bond_dev_private *internals = (struct bond_dev_private *)
-		dev->data->dev_private;
+	struct rte_eth_dev *dev;
+	struct bond_dev_private *internals;
+
+	if (valid_bonded_port_id(port) != 0)
+		return -EINVAL;
+
+	dev = &rte_eth_devices[port];
+	internals = (struct bond_dev_private *)dev->data->dev_private;
 
 	if (check_for_bonded_ethdev(dev) != 0)
 		return -1;
Signature · 1 line
2.17.1
#8 lore raw

PATCH v4 1/1 net/bonding: fix invalid port using

Port validation should be prior to getting device data to avoid segment fault. This patch fixed the segment fault caused by invalid port using.

Fixes 6d72657ce379 ("net/bonding: add other aggregator modes")
Fixes 112891cd27e5 ("net/bonding: add dedicated HW queues for LACP control")
---
 drivers/net/bonding/rte_eth_bond_8023ad.c | 32 ++++++++++++++++-------
 1 file changed, 22 insertions(+), 10 deletions(-)
drivers/net/bonding/rte_eth_bond_8023ad.c +22 -10
index 7d8da2b31..682854e39 100644
@@ -1387,11 +1387,12 @@ rte_eth_bond_8023ad_agg_selection_set(uint16_t port_id,
 	struct bond_dev_private *internals;
 	struct mode8023ad_private *mode4;
 
+	if (valid_bonded_port_id(port_id) != 0)
+		return -EINVAL;
+
 	bond_dev = &rte_eth_devices[port_id];
 	internals = bond_dev->data->dev_private;
 
-	if (valid_bonded_port_id(port_id) != 0)
-		return -EINVAL;
 	if (internals->mode != 4)
 		return -EINVAL;
 
@@ -1408,11 +1409,12 @@ int rte_eth_bond_8023ad_agg_selection_get(uint16_t port_id)
 	struct bond_dev_private *internals;
 	struct mode8023ad_private *mode4;
 
+	if (valid_bonded_port_id(port_id) != 0)
+		return -EINVAL;
+
 	bond_dev = &rte_eth_devices[port_id];
 	internals = bond_dev->data->dev_private;
 
-	if (valid_bonded_port_id(port_id) != 0)
-		return -EINVAL;
 	if (internals->mode != 4)
 		return -EINVAL;
 	mode4 = &internals->mode4;
@@ -1665,9 +1667,14 @@ int
 rte_eth_bond_8023ad_dedicated_queues_enable(uint16_t port)
 {
 	int retval = 0;
-	struct rte_eth_dev *dev = &rte_eth_devices[port];
-	struct bond_dev_private *internals = (struct bond_dev_private *)
-		dev->data->dev_private;
+	struct rte_eth_dev *dev;
+	struct bond_dev_private *internals;
+
+	if (valid_bonded_port_id(port) != 0)
+		return -EINVAL;
+
+	dev = &rte_eth_devices[port];
+	internals = dev->data->dev_private;
 
 	if (check_for_bonded_ethdev(dev) != 0)
 		return -1;
@@ -1689,9 +1696,14 @@ int
 rte_eth_bond_8023ad_dedicated_queues_disable(uint16_t port)
 {
 	int retval = 0;
-	struct rte_eth_dev *dev = &rte_eth_devices[port];
-	struct bond_dev_private *internals = (struct bond_dev_private *)
-		dev->data->dev_private;
+	struct rte_eth_dev *dev;
+	struct bond_dev_private *internals;
+
+	if (valid_bonded_port_id(port) != 0)
+		return -EINVAL;
+
+	dev = &rte_eth_devices[port];
+	internals = dev->data->dev_private;
 
 	if (check_for_bonded_ethdev(dev) != 0)
 		return -1;
Signature · 1 line
2.17.1
Acked-by on v4 1/1
#9 lore raw

Re: [dpdk-dev] [PATCH v4] net/bonding: fix invalid port using

Quoted 9 lines · Jiang JunyuX

Port validation should be prior to getting device data to avoid segment fault. This patch fixed the segment fault caused by invalid port using.

Fixes 6d72657ce379 ("net/bonding: add other aggregator modes")
Fixes 112891cd27e5 ("net/bonding: add dedicated HW queues for LACP control")

Patchwork says that there is a build error but it doesn't seem to be related to this change.

Quoted 75 lines
---
  drivers/net/bonding/rte_eth_bond_8023ad.c | 32 ++++++++++++++++-------
  1 file changed, 22 insertions(+), 10 deletions(-)
drivers/net/bonding/rte_eth_bond_8023ad.c +22 -10
index 7d8da2b31..682854e39 100644
@@ -1387,11 +1387,12 @@ rte_eth_bond_8023ad_agg_selection_set(uint16_t port_id,
  	struct bond_dev_private *internals;
  	struct mode8023ad_private *mode4;
 
+	if (valid_bonded_port_id(port_id) != 0)
+		return -EINVAL;
+
  	bond_dev = &rte_eth_devices[port_id];
  	internals = bond_dev->data->dev_private;
 
-	if (valid_bonded_port_id(port_id) != 0)
-		return -EINVAL;
  	if (internals->mode != 4)
  		return -EINVAL;
 
@@ -1408,11 +1409,12 @@ int rte_eth_bond_8023ad_agg_selection_get(uint16_t port_id)
  	struct bond_dev_private *internals;
  	struct mode8023ad_private *mode4;
 
+	if (valid_bonded_port_id(port_id) != 0)
+		return -EINVAL;
+
  	bond_dev = &rte_eth_devices[port_id];
  	internals = bond_dev->data->dev_private;
 
-	if (valid_bonded_port_id(port_id) != 0)
-		return -EINVAL;
  	if (internals->mode != 4)
  		return -EINVAL;
  	mode4 = &internals->mode4;
@@ -1665,9 +1667,14 @@ int
  rte_eth_bond_8023ad_dedicated_queues_enable(uint16_t port)
  {
  	int retval = 0;
-	struct rte_eth_dev *dev = &rte_eth_devices[port];
-	struct bond_dev_private *internals = (struct bond_dev_private *)
-		dev->data->dev_private;
+	struct rte_eth_dev *dev;
+	struct bond_dev_private *internals;
+
+	if (valid_bonded_port_id(port) != 0)
+		return -EINVAL;
+
+	dev = &rte_eth_devices[port];
+	internals = dev->data->dev_private;
 
  	if (check_for_bonded_ethdev(dev) != 0)
  		return -1;
@@ -1689,9 +1696,14 @@ int
  rte_eth_bond_8023ad_dedicated_queues_disable(uint16_t port)
  {
  	int retval = 0;
-	struct rte_eth_dev *dev = &rte_eth_devices[port];
-	struct bond_dev_private *internals = (struct bond_dev_private *)
-		dev->data->dev_private;
+	struct rte_eth_dev *dev;
+	struct bond_dev_private *internals;
+
+	if (valid_bonded_port_id(port) != 0)
+		return -EINVAL;
+
+	dev = &rte_eth_devices[port];
+	internals = dev->data->dev_private;
 
  	if (check_for_bonded_ethdev(dev) != 0)
  		return -1;
Applied
#10 lore raw

Re: [dpdk-dev] [dpdk-stable] [PATCH v4] net/bonding: fix invalid port using

Quoted 5 lines · Chas Williams
Quoted 4 lines · Jiang JunyuX

Port validation should be prior to getting device data to avoid segment fault. This patch fixed the segment fault caused by invalid port using.

Quoted 7 lines
Quoted 5 lines
Fixes 6d72657ce379 ("net/bonding: add other aggregator modes")
Fixes 112891cd27e5 ("net/bonding: add dedicated HW queues for LACP control")

Applied to dpdk-next-net/master, thanks.

Reviewed-by on v4 1/1
#11 lore raw

Re: [dpdk-dev] [PATCH v4] net/bonding: fix invalid port using

In reply to Jiang JunyuX
Quoted 94 lines

-----Original Message-----
From: Jiang, JunyuX
Sent: Tuesday, October 29, 2019 10:24 AM
To: [email protected]
Cc: Chas Williams <[email protected]>; Yang, Qiming <[email protected]>; Jiang, JunyuX <[email protected]>; [email protected]
Subject: [PATCH v4] net/bonding: fix invalid port using

Port validation should be prior to getting device data to avoid segment fault. This patch fixed the segment fault caused by invalid port using.

Fixes 6d72657ce379 ("net/bonding: add other aggregator modes")
Fixes 112891cd27e5 ("net/bonding: add dedicated HW queues for LACP

control")
Cc: [email protected]

---
 drivers/net/bonding/rte_eth_bond_8023ad.c | 32 ++++++++++++++++-------
 1 file changed, 22 insertions(+), 10 deletions(-)
drivers/net/bonding/rte_eth_bond_8023ad.c +6 -4
index 7d8da2b31..682854e39 100644
@@ -1387,11 +1387,12 @@
 rte_eth_bond_8023ad_agg_selection_set(uint16_t port_id,
 	struct bond_dev_private *internals;
 	struct mode8023ad_private *mode4;
 
+	if (valid_bonded_port_id(port_id) != 0)
+		return -EINVAL;
+
 	bond_dev = &rte_eth_devices[port_id];
 	internals = bond_dev->data->dev_private;
 
-	if (valid_bonded_port_id(port_id) != 0)
-		return -EINVAL;
 	if (internals->mode != 4)
 		return -EINVAL;
@@ -1408,11 +1409,12 @@ int
 rte_eth_bond_8023ad_agg_selection_get(uint16_t port_id)
 	struct bond_dev_private *internals;
 	struct mode8023ad_private *mode4;
 
+	if (valid_bonded_port_id(port_id) != 0)
+		return -EINVAL;
+
 	bond_dev = &rte_eth_devices[port_id];
 	internals = bond_dev->data->dev_private;
 
-	if (valid_bonded_port_id(port_id) != 0)
-		return -EINVAL;
 	if (internals->mode != 4)
 		return -EINVAL;
drivers/net/bonding/rte_eth_bond_8023ad.c +16 -7
 	mode4 = &internals->mode4;
@@ -1665,9 +1667,14 @@ int
 rte_eth_bond_8023ad_dedicated_queues_enable(uint16_t port)  {
 	int retval = 0;
-	struct rte_eth_dev *dev = &rte_eth_devices[port];
-	struct bond_dev_private *internals = (struct bond_dev_private *)
-		dev->data->dev_private;
+	struct rte_eth_dev *dev;
+	struct bond_dev_private *internals;
+
+	if (valid_bonded_port_id(port) != 0)
+		return -EINVAL;
+
+	dev = &rte_eth_devices[port];
+	internals = dev->data->dev_private;
 
 	if (check_for_bonded_ethdev(dev) != 0)
 		return -1;
@@ -1689,9 +1696,14 @@ int
 rte_eth_bond_8023ad_dedicated_queues_disable(uint16_t port)  {
 	int retval = 0;
-	struct rte_eth_dev *dev = &rte_eth_devices[port];
-	struct bond_dev_private *internals = (struct bond_dev_private *)
-		dev->data->dev_private;
+	struct rte_eth_dev *dev;
+	struct bond_dev_private *internals;
+
+	if (valid_bonded_port_id(port) != 0)
+		return -EINVAL;
+
+	dev = &rte_eth_devices[port];
+	internals = dev->data->dev_private;
 
 	if (check_for_bonded_ethdev(dev) != 0)
 		return -1;
--
Quoted 1 line

2.17.1