[7/9] net/virtio: fix segment fault when parse devargs
Checks
Commit Message
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
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
@@ -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
@@ -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