app/testpmd: fix invalid memory access

Message ID 20211012073624.399404-1-skori@marvell.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series app/testpmd: fix invalid memory access |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/github-robot: build success github build: passed
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS

Commit Message

Sunil Kumar Kori Oct. 12, 2021, 7:36 a.m. UTC
  From: Sunil Kumar Kori <skori@marvell.com>

During parsing of DSCP entries, memory is allocated and assgined
to *dscp_table. Later on, same memory is accessed using
*dscp_table[i++].

Due to higher precedence for array subscript, dscp_table[i++] will
be executed first which actually does not point to the same memory
which was allocated previously for DSCP table entries.

Cc: stable@dpdk.org

Fixes: e63b50162aa3 ("app/testpmd: clean metering and policing commands")

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
 app/test-pmd/cmdline_mtr.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Comments

Li, Xiaoyun Oct. 12, 2021, 7:50 a.m. UTC | #1
Hi

> -----Original Message-----
> From: skori@marvell.com <skori@marvell.com>
> Sent: Tuesday, October 12, 2021 15:36
> To: Li, Xiaoyun <xiaoyun.li@intel.com>
> Cc: dev@dpdk.org; Sunil Kumar Kori <skori@marvell.com>; stable@dpdk.org
> Subject: [PATCH] app/testpmd: fix invalid memory access
> 
> From: Sunil Kumar Kori <skori@marvell.com>
> 
> During parsing of DSCP entries, memory is allocated and assgined to *dscp_table.
> Later on, same memory is accessed using *dscp_table[i++].
> 
> Due to higher precedence for array subscript, dscp_table[i++] will be executed
> first which actually does not point to the same memory which was allocated
> previously for DSCP table entries.
> 
> Cc: stable@dpdk.org
> 
> Fixes: e63b50162aa3 ("app/testpmd: clean metering and policing commands")

I think the fix should be for patch 459463ae6c26 ("app/testpmd: fix memory allocation for DSCP table")
Also, added metering maintainer.

BRs
Xiaoyun

> 
> Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
> ---
>  app/test-pmd/cmdline_mtr.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/app/test-pmd/cmdline_mtr.c b/app/test-pmd/cmdline_mtr.c index
> b5dcfdadcf..ad7ef6ad98 100644
> --- a/app/test-pmd/cmdline_mtr.c
> +++ b/app/test-pmd/cmdline_mtr.c
> @@ -101,13 +101,13 @@ parse_dscp_table_entries(char *str, enum rte_color
> **dscp_table)
>  	while (1) {
>  		if (strcmp(token, "G") == 0 ||
>  			strcmp(token, "g") == 0)
> -			*dscp_table[i++] = RTE_COLOR_GREEN;
> +			(*dscp_table)[i++] = RTE_COLOR_GREEN;
>  		else if (strcmp(token, "Y") == 0 ||
>  			strcmp(token, "y") == 0)
> -			*dscp_table[i++] = RTE_COLOR_YELLOW;
> +			(*dscp_table)[i++] = RTE_COLOR_YELLOW;
>  		else if (strcmp(token, "R") == 0 ||
>  			strcmp(token, "r") == 0)
> -			*dscp_table[i++] = RTE_COLOR_RED;
> +			(*dscp_table)[i++] = RTE_COLOR_RED;
>  		else {
>  			free(*dscp_table);
>  			return -1;
> --
> 2.25.1
  
Sunil Kumar Kori Oct. 12, 2021, 8:21 a.m. UTC | #2
Regards
Sunil Kumar Kori

>-----Original Message-----
>From: Li, Xiaoyun <xiaoyun.li@intel.com>
>Sent: Tuesday, October 12, 2021 1:21 PM
>To: Sunil Kumar Kori <skori@marvell.com>
>Cc: dev@dpdk.org; stable@dpdk.org; Dumitrescu, Cristian
><cristian.dumitrescu@intel.com>
>Subject: [EXT] RE: [PATCH] app/testpmd: fix invalid memory access
>
>External Email
>
>----------------------------------------------------------------------
>Hi
>
>> -----Original Message-----
>> From: skori@marvell.com <skori@marvell.com>
>> Sent: Tuesday, October 12, 2021 15:36
>> To: Li, Xiaoyun <xiaoyun.li@intel.com>
>> Cc: dev@dpdk.org; Sunil Kumar Kori <skori@marvell.com>;
>> stable@dpdk.org
>> Subject: [PATCH] app/testpmd: fix invalid memory access
>>
>> From: Sunil Kumar Kori <skori@marvell.com>
>>
>> During parsing of DSCP entries, memory is allocated and assgined to
>*dscp_table.
>> Later on, same memory is accessed using *dscp_table[i++].
>>
>> Due to higher precedence for array subscript, dscp_table[i++] will be
>> executed first which actually does not point to the same memory which
>> was allocated previously for DSCP table entries.
>>
>> Cc: stable@dpdk.org
>>
>> Fixes: e63b50162aa3 ("app/testpmd: clean metering and policing
>> commands")
>
>I think the fix should be for patch 459463ae6c26 ("app/testpmd: fix memory
>allocation for DSCP table") Also, added metering maintainer.
>
Ack. I will update and share v2.
>BRs
>Xiaoyun
>
>>
>> Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
>> ---
>>  app/test-pmd/cmdline_mtr.c | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/app/test-pmd/cmdline_mtr.c b/app/test-pmd/cmdline_mtr.c
>> index
>> b5dcfdadcf..ad7ef6ad98 100644
>> --- a/app/test-pmd/cmdline_mtr.c
>> +++ b/app/test-pmd/cmdline_mtr.c
>> @@ -101,13 +101,13 @@ parse_dscp_table_entries(char *str, enum
>> rte_color
>> **dscp_table)
>>  	while (1) {
>>  		if (strcmp(token, "G") == 0 ||
>>  			strcmp(token, "g") == 0)
>> -			*dscp_table[i++] = RTE_COLOR_GREEN;
>> +			(*dscp_table)[i++] = RTE_COLOR_GREEN;
>>  		else if (strcmp(token, "Y") == 0 ||
>>  			strcmp(token, "y") == 0)
>> -			*dscp_table[i++] = RTE_COLOR_YELLOW;
>> +			(*dscp_table)[i++] = RTE_COLOR_YELLOW;
>>  		else if (strcmp(token, "R") == 0 ||
>>  			strcmp(token, "r") == 0)
>> -			*dscp_table[i++] = RTE_COLOR_RED;
>> +			(*dscp_table)[i++] = RTE_COLOR_RED;
>>  		else {
>>  			free(*dscp_table);
>>  			return -1;
>> --
>> 2.25.1
  

Patch

diff --git a/app/test-pmd/cmdline_mtr.c b/app/test-pmd/cmdline_mtr.c
index b5dcfdadcf..ad7ef6ad98 100644
--- a/app/test-pmd/cmdline_mtr.c
+++ b/app/test-pmd/cmdline_mtr.c
@@ -101,13 +101,13 @@  parse_dscp_table_entries(char *str, enum rte_color **dscp_table)
 	while (1) {
 		if (strcmp(token, "G") == 0 ||
 			strcmp(token, "g") == 0)
-			*dscp_table[i++] = RTE_COLOR_GREEN;
+			(*dscp_table)[i++] = RTE_COLOR_GREEN;
 		else if (strcmp(token, "Y") == 0 ||
 			strcmp(token, "y") == 0)
-			*dscp_table[i++] = RTE_COLOR_YELLOW;
+			(*dscp_table)[i++] = RTE_COLOR_YELLOW;
 		else if (strcmp(token, "R") == 0 ||
 			strcmp(token, "r") == 0)
-			*dscp_table[i++] = RTE_COLOR_RED;
+			(*dscp_table)[i++] = RTE_COLOR_RED;
 		else {
 			free(*dscp_table);
 			return -1;