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: 8a3d58c189fd ("event/cnxk: add option to control timer adapters")
Fixes: 8bdbae66b299 ("event/cnxk: add external clock support for timer")
Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
---
drivers/event/cnxk/cnxk_eventdev.c | 11 +++++++----
drivers/event/cnxk/cnxk_tim_evdev.c | 12 +++++++-----
2 files changed, 14 insertions(+), 9 deletions(-)
@@ -2,6 +2,7 @@
* Copyright(C) 2021 Marvell.
*/
+#include <rte_os_shim.h>
#include "roc_npa.h"
#include "cnxk_eventdev.h"
@@ -482,7 +483,8 @@ parse_queue_param(char *value, void *opaque)
struct cnxk_sso_qos queue_qos = {0};
uint16_t *val = (uint16_t *)&queue_qos;
struct cnxk_sso_evdev *dev = opaque;
- char *tok = strtok(value, "-");
+ char *sp = NULL;
+ char *tok = strtok_r(value, "-", &sp);
struct cnxk_sso_qos *old_ptr;
if (!strlen(value))
@@ -490,7 +492,7 @@ parse_queue_param(char *value, void *opaque)
while (tok != NULL) {
*val = atoi(tok);
- tok = strtok(NULL, "-");
+ tok = strtok_r(NULL, "-", &sp);
val++;
}
@@ -518,7 +520,8 @@ parse_stash_param(char *value, void *opaque)
struct cnxk_sso_stash queue_stash = {0};
struct cnxk_sso_evdev *dev = opaque;
struct cnxk_sso_stash *old_ptr;
- char *tok = strtok(value, "|");
+ char *sp = NULL;
+ char *tok = strtok_r(value, "|", &sp);
uint16_t *val;
if (!strlen(value))
@@ -527,7 +530,7 @@ parse_stash_param(char *value, void *opaque)
val = (uint16_t *)&queue_stash;
while (tok != NULL) {
*val = atoi(tok);
- tok = strtok(NULL, "|");
+ tok = strtok_r(NULL, "|", &sp);
val++;
}
@@ -3,6 +3,7 @@
*/
#include <math.h>
+#include <rte_os_shim.h>
#include "roc_npa.h"
@@ -420,7 +421,8 @@ cnxk_tim_parse_ring_param(char *value, void *opaque)
{
struct cnxk_tim_evdev *dev = opaque;
struct cnxk_tim_ctl ring_ctl = {0};
- char *tok = strtok(value, "-");
+ char *sp = NULL;
+ char *tok = strtok_r(value, "-", &sp);
struct cnxk_tim_ctl *old_ptr;
uint16_t *val;
@@ -431,7 +433,7 @@ cnxk_tim_parse_ring_param(char *value, void *opaque)
while (tok != NULL) {
*val = atoi(tok);
- tok = strtok(NULL, "-");
+ tok = strtok_r(NULL, "-", &sp);
val++;
}
@@ -507,16 +509,16 @@ cnxk_tim_parse_clk_list(const char *value, void *opaque)
ROC_TIM_CLK_SRC_INVALID};
struct cnxk_tim_evdev *dev = opaque;
char *str = strdup(value);
- char *tok;
+ char *tok, *sp = NULL;
int i = 0;
if (str == NULL || !strlen(str))
goto free;
- tok = strtok(str, "-");
+ tok = strtok_r(str, "-", &sp);
while (tok != NULL && src[i] != ROC_TIM_CLK_SRC_INVALID) {
dev->ext_clk_freq[src[i]] = strtoull(tok, NULL, 10);
- tok = strtok(NULL, "-");
+ tok = strtok_r(NULL, "-", &sp);
i++;
}