[1/2] common/mlx5: fix miss null check in devargs parsing

Message ID 20221024123335.3163331-2-michaelba@nvidia.com (mailing list archive)
State Accepted, archived
Delegated to: Raslan Darawsheh
Headers
Series mlx5: fix miss NULL check in devargs parsing |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Michael Baum Oct. 24, 2022, 12:33 p.m. UTC
  The common MLX5 probe function parses first the devargs and save them in
a dictionary.
It gets structure called "devargs" as a member of EAL device containing
all needed information.

When "devargs" structure is invalid, the function avoids parsing it.
However, when it valid but its field "args" is invalid, the function
tries to parse it and dereference to NULL pointer.

This patch adds check to avoid this NULL dereferencing.

Fixes: a729d2f093e9 ("common/mlx5: refactor devargs management")
Cc: michaelba@nvidia.com
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 | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
  

Patch

diff --git a/drivers/common/mlx5/mlx5_common.c b/drivers/common/mlx5/mlx5_common.c
index 4dcc8cc49c..bf22c0694d 100644
--- a/drivers/common/mlx5/mlx5_common.c
+++ b/drivers/common/mlx5/mlx5_common.c
@@ -164,8 +164,9 @@  mlx5_kvargs_prepare(struct mlx5_kvargs_ctrl *mkvlist,
 	struct rte_kvargs *kvlist;
 	uint32_t i;
 
-	if (devargs == NULL)
+	if (mkvlist == NULL)
 		return 0;
+	MLX5_ASSERT(devargs != NULL && devargs->args != NULL);
 	kvlist = rte_kvargs_parse(devargs->args, NULL);
 	if (kvlist == NULL) {
 		rte_errno = EINVAL;
@@ -400,8 +401,9 @@  parse_class_options(const struct rte_devargs *devargs,
 {
 	int ret = 0;
 
-	if (devargs == NULL)
+	if (mkvlist == NULL)
 		return 0;
+	MLX5_ASSERT(devargs != NULL);
 	if (devargs->cls != NULL && devargs->cls->name != NULL)
 		/* Global syntax, only one class type. */
 		return class_name_to_value(devargs->cls->name);
@@ -965,7 +967,7 @@  mlx5_common_dev_probe(struct rte_device *eal_dev)
 	int ret;
 
 	DRV_LOG(INFO, "probe device \"%s\".", eal_dev->name);
-	if (eal_dev->devargs != NULL)
+	if (eal_dev->devargs != NULL && eal_dev->devargs->args != NULL)
 		mkvlist_p = &mkvlist;
 	ret = mlx5_kvargs_prepare(mkvlist_p, eal_dev->devargs);
 	if (ret < 0) {