net/virtio-user: fix leak when initialisation fails

Message ID 20230413101041.1638478-1-david.marchand@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Maxime Coquelin
Headers
Series net/virtio-user: fix leak when initialisation fails |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-mellanox-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-unit-testing success Testing PASS

Commit Message

David Marchand April 13, 2023, 10:10 a.m. UTC
  Caught with ASan.
If initialising a virtio_user port fails, we may leak the ifname passed
via a devargs.

Fixes: 4214a1b493f2 ("net/virtio-user: support changing tap interface name")
Cc: stable@dpdk.org

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
  

Comments

Maxime Coquelin April 17, 2023, 6:43 a.m. UTC | #1
On 4/13/23 12:10, David Marchand wrote:
> Caught with ASan.
> If initialising a virtio_user port fails, we may leak the ifname passed
> via a devargs.
> 
> Fixes: 4214a1b493f2 ("net/virtio-user: support changing tap interface name")
> Cc: stable@dpdk.org
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
>   drivers/net/virtio/virtio_user/virtio_user_dev.c | 7 ++-----
>   1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> index f46a131b5c..744f3c30d2 100644
> --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
> +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> @@ -696,11 +696,7 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, uint16_t queues,
>   	dev->frontend_features = 0;
>   	dev->unsupported_features = 0;
>   	dev->backend_type = backend_type;
> -
> -	if (*ifname) {
> -		dev->ifname = *ifname;
> -		*ifname = NULL;
> -	}
> +	dev->ifname = *ifname;
>   
>   	if (virtio_user_dev_setup(dev) < 0) {
>   		PMD_INIT_LOG(ERR, "(%s) backend set up fails", dev->path);
> @@ -794,6 +790,7 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, uint16_t queues,
>   		}
>   	}
>   
> +	*ifname = NULL;
>   	return 0;
>   
>   notify_uninit:

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

Thanks,
Maxime
  
Tyler Retzlaff April 18, 2023, 6:15 p.m. UTC | #2
On Thu, Apr 13, 2023 at 12:10:41PM +0200, David Marchand wrote:
> Caught with ASan.
> If initialising a virtio_user port fails, we may leak the ifname passed
> via a devargs.
> 
> Fixes: 4214a1b493f2 ("net/virtio-user: support changing tap interface name")
> Cc: stable@dpdk.org
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
  
Maxime Coquelin June 1, 2023, 8 p.m. UTC | #3
On 4/13/23 12:10, David Marchand wrote:
> Caught with ASan.
> If initialising a virtio_user port fails, we may leak the ifname passed
> via a devargs.
> 
> Fixes: 4214a1b493f2 ("net/virtio-user: support changing tap interface name")
> Cc: stable@dpdk.org
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
>   drivers/net/virtio/virtio_user/virtio_user_dev.c | 7 ++-----
>   1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> index f46a131b5c..744f3c30d2 100644
> --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
> +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> @@ -696,11 +696,7 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, uint16_t queues,
>   	dev->frontend_features = 0;
>   	dev->unsupported_features = 0;
>   	dev->backend_type = backend_type;
> -
> -	if (*ifname) {
> -		dev->ifname = *ifname;
> -		*ifname = NULL;
> -	}
> +	dev->ifname = *ifname;
>   
>   	if (virtio_user_dev_setup(dev) < 0) {
>   		PMD_INIT_LOG(ERR, "(%s) backend set up fails", dev->path);
> @@ -794,6 +790,7 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, uint16_t queues,
>   		}
>   	}
>   
> +	*ifname = NULL;
>   	return 0;
>   
>   notify_uninit:


Applied to dpdk-next-virtio/main.

Thanks,
Maxime
  

Patch

diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index f46a131b5c..744f3c30d2 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -696,11 +696,7 @@  virtio_user_dev_init(struct virtio_user_dev *dev, char *path, uint16_t queues,
 	dev->frontend_features = 0;
 	dev->unsupported_features = 0;
 	dev->backend_type = backend_type;
-
-	if (*ifname) {
-		dev->ifname = *ifname;
-		*ifname = NULL;
-	}
+	dev->ifname = *ifname;
 
 	if (virtio_user_dev_setup(dev) < 0) {
 		PMD_INIT_LOG(ERR, "(%s) backend set up fails", dev->path);
@@ -794,6 +790,7 @@  virtio_user_dev_init(struct virtio_user_dev *dev, char *path, uint16_t queues,
 		}
 	}
 
+	*ifname = NULL;
 	return 0;
 
 notify_uninit: