Skip to contentSkip to conversation

net/virtio-user: fix leak when initialisation fails

PATCH Applied David Marchand 3 participants 4 messages Apr 13, 2023 – Jun 1, 2023 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/virtio-user: fix leak when initialisation fails

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")
---
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/virtio/virtio_user/virtio_user_dev.c +2 -5
index f46a131b5c..744f3c30d2 100644
@@ -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:
Signature · 1 line
2.39.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 30 lines · David Marchand

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")
---
  drivers/net/virtio/virtio_user/virtio_user_dev.c | 7 ++-----
  1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/virtio/virtio_user/virtio_user_dev.c +1 -5
index f46a131b5c..744f3c30d2 100644
@@ -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);

drivers/net/virtio/virtio_user/virtio_user_dev.c virtio_user_dev_init(struct virtio_user_dev *dev, char *path, uint16_t queues, · line 796

Quoted 7 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +1 -0
@@ -794,6 +790,7 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, uint16_t queues,
  		}
  	}
 
+	*ifname = NULL;
  	return 0;
 
  notify_uninit:

Thanks,
Maxime

#3 lore raw
In reply to David Marchand
Quoted 30 lines · David Marchand

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")
---
  drivers/net/virtio/virtio_user/virtio_user_dev.c | 7 ++-----
  1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/virtio/virtio_user/virtio_user_dev.c +1 -5
index f46a131b5c..744f3c30d2 100644
@@ -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);

drivers/net/virtio/virtio_user/virtio_user_dev.c virtio_user_dev_init(struct virtio_user_dev *dev, char *path, uint16_t queues, · line 796

Quoted 7 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +1 -0
@@ -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