From: wangyunjian <wangyunjian@huawei.com>
To: <dev@dpdk.org>, <ferruh.yigit@intel.com>
Cc: <keith.wiles@intel.com>, <jerry.lilijun@huawei.com>,
<xudingke@huawei.com>, Yunjian Wang <wangyunjian@huawei.com>,
<stable@dpdk.org>
Subject: [dpdk-dev] [PATCH v5 5/5] net/tap: fix leak of fds on failure
Date: Thu, 16 Apr 2020 11:04:56 +0800 [thread overview]
Message-ID: <1587006296-9332-1-git-send-email-wangyunjian@huawei.com> (raw)
From: Yunjian Wang <wangyunjian@huawei.com>
When eth_dev_tap_create() is failed, nlsk_fd and ka_fd won't be closed
thus leading fds leak. Zero is a valid fd. Ultimately leads to a valid
fd was closed by mistake.
Fixes: bf7b7f437b49 ("net/tap: create netdevice during probing")
Fixes: cb7e68da630a ("net/tap: fix cleanup on allocation failure")
CC: stable@dpdk.org
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
drivers/net/tap/rte_eth_tap.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index eab1fb771..618ec1c0b 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -1824,6 +1824,8 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
pmd->dev = dev;
strlcpy(pmd->name, tap_name, sizeof(pmd->name));
pmd->type = type;
+ pmd->ka_fd = -1;
+ pmd->nlsk_fd = -1;
pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
if (pmd->ioctl_sock == -1) {
@@ -1854,7 +1856,6 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
dev->intr_handle = &pmd->intr_handle;
/* Presetup the fds to -1 as being not valid */
- pmd->ka_fd = -1;
for (i = 0; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
process_private->rxq_fds[i] = -1;
process_private->txq_fds[i] = -1;
@@ -1994,7 +1995,11 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
tap_flow_implicit_flush(pmd, NULL);
error_exit:
- if (pmd->ioctl_sock > 0)
+ if (pmd->nlsk_fd != -1)
+ close(pmd->nlsk_fd);
+ if (pmd->ka_fd != -1)
+ close(pmd->ka_fd);
+ if (pmd->ioctl_sock != -1)
close(pmd->ioctl_sock);
/* mac_addrs must not be freed alone because part of dev_private */
dev->data->mac_addrs = NULL;
--
2.19.1
reply other threads:[~2020-04-16 3:05 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1587006296-9332-1-git-send-email-wangyunjian@huawei.com \
--to=wangyunjian@huawei.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@intel.com \
--cc=jerry.lilijun@huawei.com \
--cc=keith.wiles@intel.com \
--cc=stable@dpdk.org \
--cc=xudingke@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).