net/failsafe: fix fd leak
authorYunjian Wang <wangyunjian@huawei.com>
Mon, 27 Apr 2020 10:44:19 +0000 (18:44 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Mon, 11 May 2020 20:27:39 +0000 (22:27 +0200)
Zero is a valid fd. The fd won't be closed thus leading fd leak,
when it is zero.

Also 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: f234e5bd996d ("net/failsafe: register slaves Rx interrupts")
Fixes: 9e0360aebf23 ("net/failsafe: register as Rx interrupt mode")
Cc: stable@dpdk.org
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Signed-off-by: Gaetan Rivet <grive@u256.net>
Tested-by: Ali Alnubani <alialnu@mellanox.com>
drivers/net/failsafe/failsafe.c
drivers/net/failsafe/failsafe_intr.c
drivers/net/failsafe/failsafe_ops.c
drivers/net/failsafe/failsafe_private.h

index 8af31d7..72362f3 100644 (file)
@@ -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;
index d8728fe..602c040 100644 (file)
@@ -393,7 +393,7 @@ fs_rx_event_proxy_uninstall(struct fs_priv *priv)
                free(priv->rxp.evec);
                priv->rxp.evec = NULL;
        }
-       if (priv->rxp.efd > 0) {
+       if (priv->rxp.efd >= 0) {
                close(priv->rxp.efd);
                priv->rxp.efd = -1;
        }
index 50f2aca..e1d08e4 100644 (file)
@@ -380,7 +380,7 @@ fs_rx_queue_release(void *queue)
        rxq = queue;
        dev = &rte_eth_devices[rxq->priv->data->port_id];
        fs_lock(dev, 0);
-       if (rxq->event_fd > 0)
+       if (rxq->event_fd >= 0)
                close(rxq->event_fd);
        FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
                if (ETH(sdev)->data->rx_queues != NULL &&
index 8e9706a..651578a 100644 (file)
@@ -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;