[PATCH v5 15/25] bus/fslmc: replace strtok with reentrant version
Jie Hai
haijie1 at huawei.com
Fri Nov 8 12:03:54 CET 2024
Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.
The strtok() is non-reentrant, it is better to replace it with a
reentrant version.
Fixes: 9ccb76b24c1d ("bus/fslmc: enable portal interrupt handling")
Fixes: 828d51d8fc3e ("bus/fslmc: refactor scan and probe functions")
Cc: stable at dpdk.org
Signed-off-by: Jie Hai <haijie1 at huawei.com>
Acked-by: Chengwen Feng <fengchengwen at huawei.com>
Acked-by: Sachin Saxena <sachin.saxena at nxp.com>
Acked-by: Morten Brørup <mb at smartsharesystems.com>
---
drivers/bus/fslmc/fslmc_bus.c | 6 ++++--
drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 5 +++--
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c
index 097d6dca08b5..fe7eb26940cb 100644
--- a/drivers/bus/fslmc/fslmc_bus.c
+++ b/drivers/bus/fslmc/fslmc_bus.c
@@ -16,6 +16,7 @@
#include <rte_memcpy.h>
#include <ethdev_driver.h>
#include <rte_mbuf_dyn.h>
+#include <rte_os_shim.h>
#include "private.h"
#include <fslmc_vfio.h>
@@ -132,6 +133,7 @@ scan_one_fslmc_device(char *dev_name)
{
char *dup_dev_name, *t_ptr;
struct rte_dpaa2_device *dev = NULL;
+ char *sp = NULL;
int ret = -1;
if (!dev_name)
@@ -169,7 +171,7 @@ scan_one_fslmc_device(char *dev_name)
}
/* Parse the device name and ID */
- t_ptr = strtok(dup_dev_name, ".");
+ t_ptr = strtok_r(dup_dev_name, ".", &sp);
if (!t_ptr) {
DPAA2_BUS_ERR("Invalid device found: (%s)", dup_dev_name);
ret = -EINVAL;
@@ -200,7 +202,7 @@ scan_one_fslmc_device(char *dev_name)
else
dev->dev_type = DPAA2_UNKNOWN;
- t_ptr = strtok(NULL, ".");
+ t_ptr = strtok_r(NULL, ".", &sp);
if (!t_ptr) {
DPAA2_BUS_ERR("Skipping invalid device (%s)", dup_dev_name);
ret = 0;
diff --git a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
index d8a98326d9de..8b863af010da 100644
--- a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
+++ b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
@@ -31,6 +31,7 @@
#include <rte_cycles.h>
#include <rte_kvargs.h>
#include <dev_driver.h>
+#include <rte_os_shim.h>
#include <fslmc_logs.h>
#include <bus_fslmc_driver.h>
@@ -128,7 +129,7 @@ dpaa2_affine_dpio_intr_to_respective_core(int32_t dpio_id, int cpu_id)
#define AFFINITY_LEN 128
uint32_t cpu_mask = 1;
size_t len = 0;
- char *temp = NULL, *token = NULL;
+ char *temp = NULL, *token = NULL, *sp = NULL;
char string[STRING_LEN];
char smp_affinity[AFFINITY_LEN];
FILE *file;
@@ -141,7 +142,7 @@ dpaa2_affine_dpio_intr_to_respective_core(int32_t dpio_id, int cpu_id)
}
while (getline(&temp, &len, file) != -1) {
if ((strstr(temp, string)) != NULL) {
- token = strtok(temp, ":");
+ token = strtok_r(temp, ":", &sp);
break;
}
}
--
2.22.0
More information about the dev
mailing list