[v2] app/dma-perf: fix lcores array out of bounds access

Message ID 20231026095313.3053665-1-mingjinx.ye@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v2] app/dma-perf: fix lcores array out of bounds access |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/github-robot: build success github build: passed
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-sample-apps-testing success Testing PASS

Commit Message

Mingjin Ye Oct. 26, 2023, 9:53 a.m. UTC
  The default size of the lcores array in the lcore dma map
is MAX_WORKER_NB. However, when parsing configuration
parameters, MAX_LCORE_NB is used as a constraint.
Since MAX_LCORE_NB is greater than MAX_WORKER_NB, this
causes array access to go out of bounds when the value
of the `lcore_dma/lcore` configuration item in the
parameter file is greater than MAX_WORKER_NB.

This patch fixes the issue by removing the MAX_LCORE_NB
macro and using MAX_WORKER_NB consistently.

Fixes: 623dc9364dc6 ("app/dma-perf: introduce DMA performance test")

Signed-off-by: Mingjin Ye <mingjinx.ye@intel.com>
---
v2:A better solution.
---
 app/test-dma-perf/main.c | 4 ++--
 app/test-dma-perf/main.h | 1 -
 2 files changed, 2 insertions(+), 3 deletions(-)
  

Comments

Gowrishankar Muthukrishnan Oct. 27, 2023, 2:27 p.m. UTC | #1
Looks good to me.
Acked-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
  
Thomas Monjalon Nov. 14, 2023, 2:37 p.m. UTC | #2
26/10/2023 11:53, Mingjin Ye:
> The default size of the lcores array in the lcore dma map
> is MAX_WORKER_NB. However, when parsing configuration
> parameters, MAX_LCORE_NB is used as a constraint.
> Since MAX_LCORE_NB is greater than MAX_WORKER_NB, this
> causes array access to go out of bounds when the value
> of the `lcore_dma/lcore` configuration item in the
> parameter file is greater than MAX_WORKER_NB.
> 
> This patch fixes the issue by removing the MAX_LCORE_NB
> macro and using MAX_WORKER_NB consistently.
> 
> Fixes: 623dc9364dc6 ("app/dma-perf: introduce DMA performance test")
> 
> Signed-off-by: Mingjin Ye <mingjinx.ye@intel.com>

Applied, thanks.
  

Patch

diff --git a/app/test-dma-perf/main.c b/app/test-dma-perf/main.c
index e5bccc27da..5f8bab8f45 100644
--- a/app/test-dma-perf/main.c
+++ b/app/test-dma-perf/main.c
@@ -177,7 +177,7 @@  parse_lcore(struct test_configure *test_case, const char *value)
 
 	char *token = strtok(input, ", ");
 	while (token != NULL) {
-		if (lcore_dma_map->cnt >= MAX_LCORE_NB) {
+		if (lcore_dma_map->cnt >= MAX_WORKER_NB) {
 			free(input);
 			return -1;
 		}
@@ -248,7 +248,7 @@  parse_lcore_dma(struct test_configure *test_case, const char *value)
 		}
 
 		lcore_dma_map = &test_case->lcore_dma_map;
-		if (lcore_dma_map->cnt >= MAX_LCORE_NB) {
+		if (lcore_dma_map->cnt >= MAX_WORKER_NB) {
 			fprintf(stderr, "lcores count error\n");
 			ret = -1;
 			break;
diff --git a/app/test-dma-perf/main.h b/app/test-dma-perf/main.h
index f65e264378..62085e6e8f 100644
--- a/app/test-dma-perf/main.h
+++ b/app/test-dma-perf/main.h
@@ -14,7 +14,6 @@ 
 #define MAX_OUTPUT_STR_LEN 512
 
 #define MAX_DMA_NB 128
-#define MAX_LCORE_NB 256
 
 extern char output_str[MAX_WORKER_NB + 1][MAX_OUTPUT_STR_LEN];