common/mlx5: fix missing validation in devargs parsing

Message ID 20211216184040.819861-1-michaelba@nvidia.com (mailing list archive)
State Accepted, archived
Delegated to: Raslan Darawsheh
Headers
Series common/mlx5: fix missing validation in devargs parsing |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS

Commit Message

Michael Baum Dec. 16, 2021, 6:40 p.m. UTC
  From: Michael Baum <michaelba@nvidia.com>

The rte_kvargs_parse function parses the arguments
"key=value,key=value,..." string and return an allocated structure that
contains a key/value list.
It enables also to send a key without value and updates the values in
the following ways:
 - "key=value,key,..." - value is updated as NULL.
 - "key=value,key=,..." - value is updated as "" (empty string).

Mlx5 PMDs use this function to parse, but they don't support key without
value. They send the value as an argument to strtol function.
When strtol gets NULL as a parameter it cause a crash, when it gets ""
(empty string) it returns 0.

Adds a check that will prevent an argument in these formats, and returns
an error for it.

Fixes: 85209924039c4 ("common/mlx5: share memory related devargs")
Cc: stable@dpdk.org

Signed-off-by: Michael Baum <michaelba@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
---
 drivers/common/mlx5/mlx5_common.c | 5 +++++
 1 file changed, 5 insertions(+)
  

Comments

Raslan Darawsheh Jan. 6, 2022, 9:06 a.m. UTC | #1
Hi,

> -----Original Message-----
> From: Michael Baum <michaelba@nvidia.com>
> Sent: Thursday, December 16, 2021 8:41 PM
> To: dev@dpdk.org
> Cc: Matan Azrad <matan@nvidia.com>; Raslan Darawsheh
> <rasland@nvidia.com>; Slava Ovsiienko <viacheslavo@nvidia.com>; Michael
> Baum <michaelba@nvidia.com>; stable@dpdk.org
> Subject: [PATCH] common/mlx5: fix missing validation in devargs parsing
> 
> From: Michael Baum <michaelba@nvidia.com>
> 
> The rte_kvargs_parse function parses the arguments
> "key=value,key=value,..." string and return an allocated structure that
> contains a key/value list.
> It enables also to send a key without value and updates the values in the
> following ways:
>  - "key=value,key,..." - value is updated as NULL.
>  - "key=value,key=,..." - value is updated as "" (empty string).
> 
> Mlx5 PMDs use this function to parse, but they don't support key without
> value. They send the value as an argument to strtol function.
> When strtol gets NULL as a parameter it cause a crash, when it gets ""
> (empty string) it returns 0.
> 
> Adds a check that will prevent an argument in these formats, and returns an
> error for it.
> 
> Fixes: 85209924039c4 ("common/mlx5: share memory related devargs")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Michael Baum <michaelba@nvidia.com>
> Acked-by: Matan Azrad <matan@nvidia.com>

Patch applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh
  

Patch

diff --git a/drivers/common/mlx5/mlx5_common.c b/drivers/common/mlx5/mlx5_common.c
index f1650f94c6..76cfeafef8 100644
--- a/drivers/common/mlx5/mlx5_common.c
+++ b/drivers/common/mlx5/mlx5_common.c
@@ -111,6 +111,11 @@  mlx5_common_args_check_handler(const char *key, const char *val, void *opaque)
 	struct mlx5_common_dev_config *config = opaque;
 	signed long tmp;
 
+	if (val == NULL || *val == '\0') {
+		DRV_LOG(ERR, "Key %s is missing value.", key);
+		rte_errno = EINVAL;
+		return -rte_errno;
+	}
 	errno = 0;
 	tmp = strtol(val, NULL, 0);
 	if (errno) {