[7/9] net/virtio: fix segment fault when parse devargs

Message ID 20230302075012.32423-8-fengchengwen@huawei.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series fix kvargs callback prototype not clearly defined |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

fengchengwen March 2, 2023, 7:50 a.m. UTC
  The rte_kvargs_process() was used to parse KV pairs, it also supports
to parse 'only keys' (e.g. socket_id) type. And the callback function
parameter 'value' is NULL when parsed 'only keys'.

This patch fixes segment fault when parse input args with 'only keys'
(e.g. vectorized,vdpa).

Fixes: 4710e16a4a7b ("net/virtio: add parameter to enable vectorized path")
Fixes: 44d7b2e87b69 ("net/virtio: refactor devargs parsing")
Fixes: 440f03c25378 ("net/virtio: skip device probe in vDPA mode")
Cc: stable@dpdk.org

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
 drivers/net/virtio/virtio_ethdev.c     | 3 +++
 drivers/net/virtio/virtio_pci_ethdev.c | 3 +++
 2 files changed, 6 insertions(+)
  

Comments

Maxime Coquelin March 9, 2023, 3:21 p.m. UTC | #1
On 3/2/23 08:50, Chengwen Feng wrote:
> The rte_kvargs_process() was used to parse KV pairs, it also supports
> to parse 'only keys' (e.g. socket_id) type. And the callback function
> parameter 'value' is NULL when parsed 'only keys'.
> 
> This patch fixes segment fault when parse input args with 'only keys'
> (e.g. vectorized,vdpa).
> 
> Fixes: 4710e16a4a7b ("net/virtio: add parameter to enable vectorized path")
> Fixes: 44d7b2e87b69 ("net/virtio: refactor devargs parsing")
> Fixes: 440f03c25378 ("net/virtio: skip device probe in vDPA mode")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
> ---
>   drivers/net/virtio/virtio_ethdev.c     | 3 +++
>   drivers/net/virtio/virtio_pci_ethdev.c | 3 +++
>   2 files changed, 6 insertions(+)
> 
> diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
> index 0103d95920..d10f42bba2 100644
> --- a/drivers/net/virtio/virtio_ethdev.c
> +++ b/drivers/net/virtio/virtio_ethdev.c
> @@ -2054,6 +2054,9 @@ virtio_dev_speed_capa_get(uint32_t speed)
>   static int vectorized_check_handler(__rte_unused const char *key,
>   		const char *value, void *ret_val)
>   {
> +	if (value == NULL || ret_val == NULL)
> +		return -EINVAL;
> +
>   	if (strcmp(value, "1") == 0)
>   		*(int *)ret_val = 1;
>   	else
> diff --git a/drivers/net/virtio/virtio_pci_ethdev.c b/drivers/net/virtio/virtio_pci_ethdev.c
> index abc63b0935..9b4b846f8a 100644
> --- a/drivers/net/virtio/virtio_pci_ethdev.c
> +++ b/drivers/net/virtio/virtio_pci_ethdev.c
> @@ -148,6 +148,9 @@ eth_virtio_pci_uninit(struct rte_eth_dev *eth_dev)
>   static int vdpa_check_handler(__rte_unused const char *key,
>   		const char *value, void *ret_val)
>   {
> +	if (value == NULL || ret_val == NULL)
> +		return -EINVAL;
> +
>   	if (strcmp(value, "1") == 0)
>   		*(int *)ret_val = 1;
>   	else

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
  

Patch

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 0103d95920..d10f42bba2 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -2054,6 +2054,9 @@  virtio_dev_speed_capa_get(uint32_t speed)
 static int vectorized_check_handler(__rte_unused const char *key,
 		const char *value, void *ret_val)
 {
+	if (value == NULL || ret_val == NULL)
+		return -EINVAL;
+
 	if (strcmp(value, "1") == 0)
 		*(int *)ret_val = 1;
 	else
diff --git a/drivers/net/virtio/virtio_pci_ethdev.c b/drivers/net/virtio/virtio_pci_ethdev.c
index abc63b0935..9b4b846f8a 100644
--- a/drivers/net/virtio/virtio_pci_ethdev.c
+++ b/drivers/net/virtio/virtio_pci_ethdev.c
@@ -148,6 +148,9 @@  eth_virtio_pci_uninit(struct rte_eth_dev *eth_dev)
 static int vdpa_check_handler(__rte_unused const char *key,
 		const char *value, void *ret_val)
 {
+	if (value == NULL || ret_val == NULL)
+		return -EINVAL;
+
 	if (strcmp(value, "1") == 0)
 		*(int *)ret_val = 1;
 	else