Skip to content

Commit

Permalink
app/eventdev: fix overflow in lcore list parsing
Browse files Browse the repository at this point in the history
[ upstream commit 32d7dbf ]

Tainted and unvalidated integer 'idx' used as an index, which may
lead to buffer overflow.

This patch fixed it.

Fixes: 89e5eb1 ("app/testeventdev: add string parsing helpers")

Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
Acked-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
  • Loading branch information
hushenggitcount authored and steevenlee committed Jun 8, 2021
1 parent 8ad8d12 commit d173cc8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/test-eventdev/evt_options.c
Expand Up @@ -218,7 +218,7 @@ evt_parse_plcores(struct evt_options *opt, const char *corelist)
{
int ret;

ret = parse_lcores_list(opt->plcores, corelist);
ret = parse_lcores_list(opt->plcores, RTE_MAX_LCORE, corelist);
if (ret == -E2BIG)
evt_err("duplicate lcores in plcores");

Expand All @@ -230,7 +230,7 @@ evt_parse_work_lcores(struct evt_options *opt, const char *corelist)
{
int ret;

ret = parse_lcores_list(opt->wlcores, corelist);
ret = parse_lcores_list(opt->wlcores, RTE_MAX_LCORE, corelist);
if (ret == -E2BIG)
evt_err("duplicate lcores in wlcores");

Expand Down
6 changes: 4 additions & 2 deletions app/test-eventdev/parser.c
Expand Up @@ -310,7 +310,7 @@ parse_hex_string(char *src, uint8_t *dst, uint32_t *size)
}

int
parse_lcores_list(bool lcores[], const char *corelist)
parse_lcores_list(bool lcores[], int lcores_num, const char *corelist)
{
int i, idx = 0;
int min, max;
Expand All @@ -332,6 +332,8 @@ parse_lcores_list(bool lcores[], const char *corelist)
if (*corelist == '\0')
return -1;
idx = strtoul(corelist, &end, 10);
if (idx < 0 || idx > lcores_num)
return -1;

if (end == NULL)
return -1;
Expand All @@ -343,7 +345,7 @@ parse_lcores_list(bool lcores[], const char *corelist)
max = idx;
if (min == RTE_MAX_LCORE)
min = idx;
for (idx = min; idx <= max; idx++) {
for (idx = min; idx < max; idx++) {
if (lcores[idx] == 1)
return -E2BIG;
lcores[idx] = 1;
Expand Down
2 changes: 1 addition & 1 deletion app/test-eventdev/parser.h
Expand Up @@ -46,5 +46,5 @@ int parse_hex_string(char *src, uint8_t *dst, uint32_t *size);

int parse_tokenize_string(char *string, char *tokens[], uint32_t *n_tokens);

int parse_lcores_list(bool lcores[], const char *corelist);
int parse_lcores_list(bool lcores[], int lcores_num, const char *corelist);
#endif

0 comments on commit d173cc8

Please sign in to comment.