mlx5: fix miss NULL check in devargs parsing
cover mlx5: fix miss NULL check in devargs parsing
The MLX5 PMD parses the devargs in several places.
It gets structure called "devargs" as a member of EAL device containing all needed information.
When "devargs" structure is invalid, the PMD avoids parsing it. However, when it valid but its field "args" is invalid, the PMD tries to parse it and dereference to NULL pointer.
Those patches add checks to avoid these NULL dereferencing.
Michael Baum (2):
common/mlx5: fix miss null check in devargs parsing net/mlx5: fix miss null check in ETH devargs parsing
drivers/common/mlx5/mlx5_common.c | 8 +++++--- drivers/net/mlx5/linux/mlx5_os.c | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/2 common/mlx5: fix miss null check in devargs parsing
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.
--- drivers/common/mlx5/mlx5_common.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/common/mlx5/mlx5_common.c +5 -3
@@ -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 ) {
Signature · 1 line
2.25.1
PATCH 2/2 net/mlx5: fix miss null check in ETH devargs parsing
In reply to Michael BaumThe "mlx5_os_parse_eth_devargs()" function parses the ETH devargs into a specific structure called "eth_da".
It gets structure called "devargs" as a member of EAL device containing the relevant 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.
--- drivers/net/mlx5/linux/mlx5_os.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mlx5/linux/mlx5_os.c +1 -1
@@ -2411,7 +2411,7 @@ mlx5_os_parse_eth_devargs(struct rte_device *dev, dev->devargs->cls_str);return -rte_errno; } -if (eth_da->type ==RTE_ETH_REPRESENTOR_NONE ) { +if (eth_da->type ==RTE_ETH_REPRESENTOR_NONE && dev->devargs->args) {/* Parse legacy device argument */ ret =rte_eth_devargs_parse (dev->devargs->args, eth_da);if (ret) {
Signature · 1 line
2.25.1
Hi,
Quoted 23 lines
-----Original Message-----
From: Michael Baum <[email protected]>
Sent: Monday, October 24, 2022 3:34 PM
To: [email protected]
Cc: Matan Azrad <[email protected]>; Raslan Darawsheh <[email protected]>; Slava Ovsiienko <[email protected]>
Subject: [PATCH 0/2] mlx5: fix miss NULL check in devargs parsingThe MLX5 PMD parses the devargs in several places.
It gets structure called "devargs" as a member of EAL device containing all needed information.When "devargs" structure is invalid, the PMD avoids parsing it. However, when it valid but its field "args" is invalid, the PMD tries to parse it and dereference to NULL pointer.
Those patches add checks to avoid these NULL dereferencing.
Michael Baum (2):
common/mlx5: fix miss null check in devargs parsing net/mlx5: fix miss null check in ETH devargs parsing
Quoted 6 lines
drivers/common/mlx5/mlx5_common.c | 8 +++++--- drivers/net/mlx5/linux/mlx5_os.c | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-)--
2.25.1
Series applied to next-net-mlx,
Kindest regards,
Raslan Darawsheh