[v1,3/3] net/failsafe: fix default service proxy state

Message ID 7286631f479ef296b4c6b3ff41c5ca52504b0834.1588705694.git.grive@u256.net (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series failsafe & ring fixes |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/travis-robot success Travis build: passed
ci/Intel-compilation fail Compilation issues

Commit Message

Gaëtan Rivet May 5, 2020, 7:10 p.m. UTC
  The service proxy is initialized at 0. This is assuming that all of
its fields are invalid at 0. The issue is that a file descriptor at 0 is a
valid one.

The value -1 is used as sentinel during cleanup. Initialize the RX proxy
file descriptor to -1.

Fixes: 366226dd859f ("net/failsafe: fix fd leak")
Signed-off-by: Gaetan Rivet <grive@u256.net>
Cc: wangyunjian@huawei.com
Cc: Ali Alnubani <alialnu@mellanox.com>
---
 drivers/net/failsafe/failsafe.c         | 1 +
 drivers/net/failsafe/failsafe_private.h | 8 ++++++++
 2 files changed, 9 insertions(+)
  

Comments

Ali Alnubani May 6, 2020, 8:58 a.m. UTC | #1
Thanks Gaetan.

> -----Original Message-----
> From: Gaetan Rivet <grive@u256.net>
> Sent: Tuesday, May 5, 2020 10:11 PM
> To: dev@dpdk.org
> Cc: wangyunjian@huawei.com; Ali Alnubani <alialnu@mellanox.com>
> Subject: [PATCH v1 3/3] net/failsafe: fix default service proxy state
> 
> The service proxy is initialized at 0. This is assuming that all of its fields are
> invalid at 0. The issue is that a file descriptor at 0 is a valid one.
> 
> The value -1 is used as sentinel during cleanup. Initialize the RX proxy file
> descriptor to -1.
> 
> Fixes: 366226dd859f ("net/failsafe: fix fd leak")
> Signed-off-by: Gaetan Rivet <grive@u256.net>
> Cc: wangyunjian@huawei.com
> Cc: Ali Alnubani <alialnu@mellanox.com>

Tested-by: Ali Alnubani <alialnu@mellanox.com>
  
Ferruh Yigit May 6, 2020, 5:16 p.m. UTC | #2
On 5/5/2020 8:10 PM, Gaetan Rivet wrote:
> The service proxy is initialized at 0. This is assuming that all of
> its fields are invalid at 0. The issue is that a file descriptor at 0 is a
> valid one.
> 
> The value -1 is used as sentinel during cleanup. Initialize the RX proxy
> file descriptor to -1.
> 
> Fixes: 366226dd859f ("net/failsafe: fix fd leak")
> Signed-off-by: Gaetan Rivet <grive@u256.net>

I have squashed this to the commit in the fixes line, to not leave any commit
that can cause crash, and kept both sign-offs and Ali's test tag.

Squashed into relevant commit in next-net, thanks.
  

Patch

diff --git a/drivers/net/failsafe/failsafe.c b/drivers/net/failsafe/failsafe.c
index 8af31d71b..72362f35d 100644
--- a/drivers/net/failsafe/failsafe.c
+++ b/drivers/net/failsafe/failsafe.c
@@ -190,6 +190,7 @@  fs_eth_dev_create(struct rte_vdev_device *vdev)
 	}
 	priv = PRIV(dev);
 	priv->data = dev->data;
+	priv->rxp = FS_RX_PROXY_INIT;
 	dev->dev_ops = &failsafe_ops;
 	dev->data->mac_addrs = &PRIV(dev)->mac_addrs[0];
 	dev->data->dev_link = eth_link;
diff --git a/drivers/net/failsafe/failsafe_private.h b/drivers/net/failsafe/failsafe_private.h
index 8e9706aef..651578a12 100644
--- a/drivers/net/failsafe/failsafe_private.h
+++ b/drivers/net/failsafe/failsafe_private.h
@@ -58,6 +58,14 @@  struct rx_proxy {
 	enum rxp_service_state sstate;
 };
 
+#define FS_RX_PROXY_INIT (struct rx_proxy){ \
+	.efd = -1, \
+	.evec = NULL, \
+	.sid = 0, \
+	.scid = 0, \
+	.sstate = SS_NO_SERVICE, \
+}
+
 struct rxq {
 	struct fs_priv *priv;
 	uint16_t qid;