[v4,36/42] net/tap: use rte strerror

Message ID 20241023082852.2780488-37-huangdengdui@huawei.com (mailing list archive)
State Changes Requested, archived
Delegated to: Thomas Monjalon
Headers
Series replace strerror |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

huangdengdui Oct. 23, 2024, 8:28 a.m. UTC
The function strerror() is insecure in a multi-thread environment.
This patch uses rte_strerror() to replace it.

Cc: stable@dpdk.org

Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
---
 drivers/net/tap/rte_eth_tap.c | 28 ++++++++++++++--------------
 drivers/net/tap/tap_flow.c    | 14 +++++++-------
 drivers/net/tap/tap_netlink.c |  5 +++--
 drivers/net/tap/tap_tcmsgs.c  |  6 ++++--
 4 files changed, 28 insertions(+), 25 deletions(-)
  

Patch

diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index 36b06b3ac5..629f577f7b 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -198,7 +198,7 @@  tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent)
 	/* Set the TUN/TAP configuration and set the name if needed */
 	if (ioctl(fd, TUNSETIFF, (void *)&ifr) < 0) {
 		TAP_LOG(WARNING, "Unable to set TUNSETIFF for %s: %s",
-			ifr.ifr_name, strerror(errno));
+			ifr.ifr_name, rte_strerror(errno));
 		goto error;
 	}
 
@@ -206,7 +206,7 @@  tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent)
 	if (persistent && ioctl(fd, TUNSETPERSIST, 1) < 0) {
 		TAP_LOG(WARNING,
 			"Unable to set persist %s: %s",
-			ifr.ifr_name, strerror(errno));
+			ifr.ifr_name, rte_strerror(errno));
 		goto error;
 	}
 
@@ -226,7 +226,7 @@  tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent)
 		if (ioctl(fd, TUNSETQUEUE, (void *)&ifr) < 0) {
 			TAP_LOG(WARNING,
 				"Unable to detach keep-alive queue for %s: %s",
-				ifr.ifr_name, strerror(errno));
+				ifr.ifr_name, rte_strerror(errno));
 			goto error;
 		}
 	}
@@ -234,7 +234,7 @@  tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent)
 	flags = fcntl(fd, F_GETFL);
 	if (flags == -1) {
 		TAP_LOG(WARNING, "Unable to get %s current flags: %s",
-			ifr.ifr_name, strerror(errno));
+			ifr.ifr_name, rte_strerror(errno));
 		goto error;
 	}
 
@@ -243,7 +243,7 @@  tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent)
 	if (fcntl(fd, F_SETFL, flags) < 0) {
 		TAP_LOG(WARNING,
 			"Unable to set %s to nonblocking: %s",
-			ifr.ifr_name, strerror(errno));
+			ifr.ifr_name, rte_strerror(errno));
 		goto error;
 	}
 
@@ -296,18 +296,18 @@  tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent)
 		/* Enable signal on file descriptor */
 		if (fcntl(fd, F_SETSIG, signo) < 0) {
 			TAP_LOG(WARNING, "Unable to set signo %d for fd %d: %s",
-				signo, fd, strerror(errno));
+				signo, fd, rte_strerror(errno));
 			goto error;
 		}
 		if (fcntl(fd, F_SETFL, flags | O_ASYNC) < 0) {
 			TAP_LOG(WARNING, "Unable to set fcntl flags: %s",
-				strerror(errno));
+				rte_strerror(errno));
 			goto error;
 		}
 
 		if (fcntl(fd, F_SETOWN, getpid()) < 0) {
 			TAP_LOG(WARNING, "Unable to set fcntl owner: %s",
-				strerror(errno));
+				rte_strerror(errno));
 			goto error;
 		}
 	}
@@ -822,7 +822,7 @@  tap_ioctl(struct pmd_internals *pmd, unsigned long request,
 
 error:
 	TAP_LOG(DEBUG, "%s(%s) failed: %s(%d)", ifr->ifr_name,
-		tap_ioctl_req2str(request), strerror(errno), errno);
+		tap_ioctl_req2str(request), rte_strerror(errno), errno);
 	return -errno;
 }
 
@@ -1946,7 +1946,7 @@  eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	if (pmd->ioctl_sock == -1) {
 		TAP_LOG(ERR,
 			"%s Unable to get a socket for management: %s",
-			tuntap_name, strerror(errno));
+			tuntap_name, rte_strerror(errno));
 		goto error_exit;
 	}
 
@@ -2109,7 +2109,7 @@  eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 
 disable_rte_flow:
 	TAP_LOG(ERR, " Disabling rte flow support: %s(%d)",
-		strerror(errno), errno);
+		rte_strerror(errno), errno);
 	if (strlen(remote_iface)) {
 		TAP_LOG(ERR, "Remote feature requires flow support.");
 		goto error_exit;
@@ -2120,7 +2120,7 @@  eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 #ifdef HAVE_TCA_FLOWER
 error_remote:
 	TAP_LOG(ERR, " Can't set up remote feature: %s(%d)",
-		strerror(errno), errno);
+		rte_strerror(errno), errno);
 	tap_flow_implicit_flush(pmd, NULL);
 #endif
 
@@ -2454,7 +2454,7 @@  rte_pmd_tap_probe(struct rte_vdev_device *dev)
 			ret = rte_mp_action_register(TAP_MP_REQ_START_RXTX, tap_mp_req_start_rxtx);
 			if (ret < 0 && rte_errno != ENOTSUP) {
 				TAP_LOG(ERR, "tap: Failed to register IPC callback: %s",
-					strerror(rte_errno));
+					rte_strerror(rte_errno));
 				return -1;
 			}
 		}
@@ -2514,7 +2514,7 @@  rte_pmd_tap_probe(struct rte_vdev_device *dev)
 		ret = rte_mp_action_register(TAP_MP_KEY, tap_mp_sync_queues);
 		if (ret < 0 && rte_errno != ENOTSUP) {
 			TAP_LOG(ERR, "tap: Failed to register IPC callback: %s",
-				strerror(rte_errno));
+				rte_strerror(rte_errno));
 			goto leave;
 		}
 	}
diff --git a/drivers/net/tap/tap_flow.c b/drivers/net/tap/tap_flow.c
index 51ec07eb5a..0c9a643492 100644
--- a/drivers/net/tap/tap_flow.c
+++ b/drivers/net/tap/tap_flow.c
@@ -1317,7 +1317,7 @@  tap_flow_create(struct rte_eth_dev *dev,
 	if (err < 0) {
 		TAP_LOG(ERR,
 			"Kernel refused TC filter rule creation (%d): %s",
-			errno, strerror(errno));
+			errno, rte_strerror(errno));
 		rte_flow_error_set(error, EEXIST, RTE_FLOW_ERROR_TYPE_HANDLE,
 				   NULL,
 				   "overlapping rules or Kernel too old for flower support");
@@ -1362,7 +1362,7 @@  tap_flow_create(struct rte_eth_dev *dev,
 		if (err < 0) {
 			TAP_LOG(ERR,
 				"Kernel refused TC filter rule creation (%d): %s",
-				errno, strerror(errno));
+				errno, rte_strerror(errno));
 			rte_flow_error_set(
 				error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
 				NULL,
@@ -1416,7 +1416,7 @@  tap_flow_destroy_pmd(struct pmd_internals *pmd,
 	if (ret < 0) {
 		TAP_LOG(ERR,
 			"Kernel refused TC filter rule deletion (%d): %s",
-			errno, strerror(errno));
+			errno, rte_strerror(errno));
 		rte_flow_error_set(
 			error, ENOTSUP, RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
 			"couldn't receive kernel ack to our request");
@@ -1440,7 +1440,7 @@  tap_flow_destroy_pmd(struct pmd_internals *pmd,
 		if (ret < 0) {
 			TAP_LOG(ERR,
 				"Kernel refused TC filter rule deletion (%d): %s",
-				errno, strerror(errno));
+				errno, rte_strerror(errno));
 			rte_flow_error_set(
 				error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
 				NULL, "Failure trying to receive nl ack");
@@ -1664,7 +1664,7 @@  int tap_flow_implicit_create(struct pmd_internals *pmd,
 			goto success;
 		TAP_LOG(ERR,
 			"Kernel refused TC filter rule creation (%d): %s",
-			errno, strerror(errno));
+			errno, rte_strerror(errno));
 		goto fail;
 	}
 	LIST_INSERT_HEAD(&pmd->implicit_flows, remote_flow, next);
@@ -1754,7 +1754,7 @@  static int rss_enable(struct pmd_internals *pmd, struct rte_flow_error *error)
 	/* Load the BPF program (defined in tap_bpf.h from skeleton) */
 	pmd->rss = tap_rss__open_and_load();
 	if (pmd->rss == NULL) {
-		TAP_LOG(ERR, "Failed to load BPF object: %s", strerror(errno));
+		TAP_LOG(ERR, "Failed to load BPF object: %s", rte_strerror(errno));
 		rte_flow_error_set(error, errno, RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
 			"BPF object could not be loaded");
 		return -errno;
@@ -1885,7 +1885,7 @@  static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd,
 	if (err) {
 		TAP_LOG(ERR,
 			"Failed to update BPF map entry %#x (%d): %s",
-			handle,  errno, strerror(errno));
+			handle,  errno, rte_strerror(errno));
 		rte_flow_error_set(
 			error, ENOTSUP, RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
 			"Kernel too old or not configured "
diff --git a/drivers/net/tap/tap_netlink.c b/drivers/net/tap/tap_netlink.c
index 35c491ac37..6011f6c61d 100644
--- a/drivers/net/tap/tap_netlink.c
+++ b/drivers/net/tap/tap_netlink.c
@@ -14,6 +14,7 @@ 
 #include <rte_malloc.h>
 #include <tap_netlink.h>
 #include <rte_random.h>
+#include <rte_errno.h>
 
 #include "tap_log.h"
 
@@ -98,7 +99,7 @@  tap_nl_final(int nlsk_fd)
 {
 	if (close(nlsk_fd)) {
 		TAP_LOG(ERR, "Failed to close netlink socket: %s (%d)",
-			strerror(errno), errno);
+			rte_strerror(errno), errno);
 		return -1;
 	}
 	return 0;
@@ -130,7 +131,7 @@  tap_nl_send(int nlsk_fd, struct nlmsghdr *nh)
 			goto retry;
 
 		TAP_LOG(ERR, "Failed to send netlink message: %s (%d)",
-			strerror(errno), errno);
+			rte_strerror(errno), errno);
 		return -1;
 	}
 	return send_bytes;
diff --git a/drivers/net/tap/tap_tcmsgs.c b/drivers/net/tap/tap_tcmsgs.c
index a3aae3c814..28d4809360 100644
--- a/drivers/net/tap/tap_tcmsgs.c
+++ b/drivers/net/tap/tap_tcmsgs.c
@@ -8,6 +8,8 @@ 
 #include <net/if.h>
 #include <string.h>
 
+#include <rte_errno.h>
+
 #include <rte_log.h>
 #include <tap_tcmsgs.h>
 #include "tap_log.h"
@@ -263,7 +265,7 @@  qdisc_create_multiq(int nlsk_fd, unsigned int ifindex)
 	err = qdisc_add_multiq(nlsk_fd, ifindex);
 	if (err < 0 && errno != -EEXIST) {
 		TAP_LOG(ERR, "Could not add multiq qdisc (%d): %s",
-			errno, strerror(errno));
+			errno, rte_strerror(errno));
 		return -1;
 	}
 	return 0;
@@ -289,7 +291,7 @@  qdisc_create_ingress(int nlsk_fd, unsigned int ifindex)
 	err = qdisc_add_ingress(nlsk_fd, ifindex);
 	if (err < 0 && errno != -EEXIST) {
 		TAP_LOG(ERR, "Could not add ingress qdisc (%d): %s",
-			errno, strerror(errno));
+			errno, rte_strerror(errno));
 		return -1;
 	}
 	return 0;