From b9663f60359296bcb6f0be8a3d6a2a838c77ee30 Mon Sep 17 00:00:00 2001 From: Yunjian Wang Date: Mon, 27 Apr 2020 18:44:19 +0800 Subject: [PATCH] net/failsafe: fix fd leak 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 Signed-off-by: Gaetan Rivet Tested-by: Ali Alnubani --- drivers/net/failsafe/failsafe.c | 1 + drivers/net/failsafe/failsafe_intr.c | 2 +- drivers/net/failsafe/failsafe_ops.c | 2 +- drivers/net/failsafe/failsafe_private.h | 8 ++++++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/net/failsafe/failsafe.c b/drivers/net/failsafe/failsafe.c index 8af31d71b3..72362f35de 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_intr.c b/drivers/net/failsafe/failsafe_intr.c index d8728fe7e3..602c04033c 100644 --- a/drivers/net/failsafe/failsafe_intr.c +++ b/drivers/net/failsafe/failsafe_intr.c @@ -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; } diff --git a/drivers/net/failsafe/failsafe_ops.c b/drivers/net/failsafe/failsafe_ops.c index 50f2aca4e7..e1d08e46c8 100644 --- a/drivers/net/failsafe/failsafe_ops.c +++ b/drivers/net/failsafe/failsafe_ops.c @@ -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 && diff --git a/drivers/net/failsafe/failsafe_private.h b/drivers/net/failsafe/failsafe_private.h index 8e9706aef0..651578a128 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; -- 2.20.1