app/testeventdev: fix buffer overflow
PATCH 1/1 app/testeventdev: fix buffer overflow
Tainted and unvalidated integer 'idx' used as an index, which may lead to buffer overflow.
This patch fixed it.
Fixes 89e5eb118017 ("app/testeventdev: add string parsing helpers")
Signed-off-by Min Hu (Connor) <[email protected]>
--- app/test-eventdev/evt_options.c | 4 ++-- app/test-eventdev/parser.c | 6 ++++-- app/test-eventdev/parser.h | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-)
app/test-eventdev/evt_options.c +2 -2
@@ -221,7 +221,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" );
@@ -233,7 +233,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" );
app/test-eventdev/parser.c +4 -2
@@ -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;
@@ -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 ;
@@ -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 ;
app/test-eventdev/parser.h +1 -1
@@ -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
Signature · 1 line
2.7.4
Quoted 9 lines
Tainted and unvalidated integer 'idx' used as an index, which may lead to buffer overflow.
This patch fixed it.
Fixes 89e5eb118017 ("app/testeventdev: add string parsing helpers")Signed-off-by Min Hu (Connor) <[email protected]>
Acked-by Pavan Nikhilesh <[email protected]>
Quoted 83 lines
---
app/test-eventdev/evt_options.c | 4 ++-- app/test-eventdev/parser.c | 6 ++++-- app/test-eventdev/parser.h | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-)app/test- renamed from app/test-eventdev/evt_options.c +0
-0
eventdev/evt_options.c
index 0d55405..061b63e 100644app/test-eventdev/evt_options.c +1
-1@@ -221,7 +221,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");app/test-eventdev/evt_options.c +1
-1@@ -233,7 +233,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");app/test-eventdev/parser.c +0
-0@@ -310,7 +310,7 @@ parse_hex_string(char *src, uint8_t *dst, uint32_t *size) }int
app/test-eventdev/parser.c +1
-1-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;app/test-eventdev/parser.c +2
-0@@ -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;app/test-eventdev/parser.c +1
-1@@ -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;app/test-eventdev/parser.h +0
-0@@ -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);app/test-eventdev/parser.h +1
-1-int parse_lcores_list (bool lcores[],const char *corelist); +int parse_lcores_list(bool lcores[], int lcores_num, const char*corelist);
#endif
--
2.7.4
Jerin Jacob
AppliedQuoted 4 lines · Pavan Nikhilesh Bhagavatula
Quoted 4 lines
Tainted and unvalidated integer 'idx' used as an index, which may lead to buffer overflow.
Quoted 8 lines
Quoted 6 lines
This patch fixed it.
Fixes 89e5eb118017 ("app/testeventdev: add string parsing helpers")Signed-off-by Min Hu (Connor) <[email protected]>Acked-by Pavan Nikhilesh <[email protected]>
Applied to dpdk-next-net-eventdev/for-main. Thanks
Quoted 85 lines
Quoted 84 lines
---
app/test-eventdev/evt_options.c | 4 ++-- app/test-eventdev/parser.c | 6 ++++-- app/test-eventdev/parser.h | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-)app/test- renamed from app/test-eventdev/evt_options.c +0
-0
eventdev/evt_options.c
index 0d55405..061b63e 100644app/test-eventdev/evt_options.c +1
-1@@ -221,7 +221,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");app/test-eventdev/evt_options.c +1
-1@@ -233,7 +233,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");app/test-eventdev/parser.c +0
-0@@ -310,7 +310,7 @@ parse_hex_string(char *src, uint8_t *dst, uint32_t *size) }int
app/test-eventdev/parser.c +1
-1-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;app/test-eventdev/parser.c +2
-0@@ -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;app/test-eventdev/parser.c +1
-1@@ -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;app/test-eventdev/parser.h +0
-0@@ -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);app/test-eventdev/parser.h +1
-1-int parse_lcores_list (bool lcores[],const char *corelist); +int parse_lcores_list(bool lcores[], int lcores_num, const char*corelist);
#endif
--
2.7.4