All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vdpa: Fix memory leak in error unwinding path
@ 2021-02-13 18:39 Parav Pandit
  2021-02-15 11:45 ` Stefano Garzarella
  0 siblings, 1 reply; 3+ messages in thread
From: Parav Pandit @ 2021-02-13 18:39 UTC (permalink / raw)
  To: virtualization; +Cc: mst

When device get command fails to find the device or mdev,
it skips to free the skb during error unwinding path.
Fix it by freeing in error unwind path.

Fixes: a12a2f694ce8 ("vdpa: Enable user to query vdpa device info")
Signed-off-by: Parav Pandit <parav@nvidia.com>
---
 drivers/vdpa/vdpa.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c
index 3d997b389345..e3f1bfdf8d6f 100644
--- a/drivers/vdpa/vdpa.c
+++ b/drivers/vdpa/vdpa.c
@@ -540,20 +540,22 @@ static int vdpa_nl_cmd_dev_get_doit(struct sk_buff *skb, struct genl_info *info)
 	if (!dev) {
 		mutex_unlock(&vdpa_dev_mutex);
 		NL_SET_ERR_MSG_MOD(info->extack, "device not found");
-		return -ENODEV;
+		err = -ENODEV;
+		goto err;
 	}
 	vdev = container_of(dev, struct vdpa_device, dev);
 	if (!vdev->mdev) {
 		mutex_unlock(&vdpa_dev_mutex);
 		put_device(dev);
-		return -EINVAL;
+		err = -EINVAL;
+		goto err;
 	}
 	err = vdpa_dev_fill(vdev, msg, info->snd_portid, info->snd_seq, 0, info->extack);
 	if (!err)
 		err = genlmsg_reply(msg, info);
 	put_device(dev);
 	mutex_unlock(&vdpa_dev_mutex);
-
+err:
 	if (err)
 		nlmsg_free(msg);
 	return err;
-- 
2.26.2

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] vdpa: Fix memory leak in error unwinding path
  2021-02-13 18:39 [PATCH] vdpa: Fix memory leak in error unwinding path Parav Pandit
@ 2021-02-15 11:45 ` Stefano Garzarella
  2021-02-15 14:12   ` Parav Pandit
  0 siblings, 1 reply; 3+ messages in thread
From: Stefano Garzarella @ 2021-02-15 11:45 UTC (permalink / raw)
  To: Parav Pandit; +Cc: mst, virtualization

On Sat, Feb 13, 2021 at 08:39:19PM +0200, Parav Pandit wrote:
>When device get command fails to find the device or mdev,
>it skips to free the skb during error unwinding path.
>Fix it by freeing in error unwind path.
>
>Fixes: a12a2f694ce8 ("vdpa: Enable user to query vdpa device info")
>Signed-off-by: Parav Pandit <parav@nvidia.com>
>---
> drivers/vdpa/vdpa.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
>diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c
>index 3d997b389345..e3f1bfdf8d6f 100644
>--- a/drivers/vdpa/vdpa.c
>+++ b/drivers/vdpa/vdpa.c
>@@ -540,20 +540,22 @@ static int vdpa_nl_cmd_dev_get_doit(struct sk_buff *skb, struct genl_info *info)
> 	if (!dev) {
> 		mutex_unlock(&vdpa_dev_mutex);
> 		NL_SET_ERR_MSG_MOD(info->extack, "device not found");
>-		return -ENODEV;
>+		err = -ENODEV;
>+		goto err;
> 	}
> 	vdev = container_of(dev, struct vdpa_device, dev);
> 	if (!vdev->mdev) {
> 		mutex_unlock(&vdpa_dev_mutex);
> 		put_device(dev);
>-		return -EINVAL;
>+		err = -EINVAL;
>+		goto err;
> 	}
> 	err = vdpa_dev_fill(vdev, msg, info->snd_portid, info->snd_seq, 0, info->extack);
> 	if (!err)
> 		err = genlmsg_reply(msg, info);
> 	put_device(dev);
> 	mutex_unlock(&vdpa_dev_mutex);
>-
>+err:

If we put this label before mutex_unlock(), we can remove that call in 
the error paths.

Maybe we can also add another label before put_device() and jump to it 
in the "if (!vdev->mdev)" case.

Thanks,
Stefano

> 	if (err)
> 		nlmsg_free(msg);
> 	return err;
>-- 
>2.26.2
>
>_______________________________________________
>Virtualization mailing list
>Virtualization@lists.linux-foundation.org
>https://lists.linuxfoundation.org/mailman/listinfo/virtualization
>

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH] vdpa: Fix memory leak in error unwinding path
  2021-02-15 11:45 ` Stefano Garzarella
@ 2021-02-15 14:12   ` Parav Pandit
  0 siblings, 0 replies; 3+ messages in thread
From: Parav Pandit @ 2021-02-15 14:12 UTC (permalink / raw)
  To: Stefano Garzarella; +Cc: mst, virtualization



> From: Stefano Garzarella <sgarzare@redhat.com>
> Sent: Monday, February 15, 2021 5:16 PM
> 
> On Sat, Feb 13, 2021 at 08:39:19PM +0200, Parav Pandit wrote:
> >When device get command fails to find the device or mdev, it skips to
> >free the skb during error unwinding path.
> >Fix it by freeing in error unwind path.
> >
> >Fixes: a12a2f694ce8 ("vdpa: Enable user to query vdpa device info")
> >Signed-off-by: Parav Pandit <parav@nvidia.com>
> >---
> > drivers/vdpa/vdpa.c | 8 +++++---
> > 1 file changed, 5 insertions(+), 3 deletions(-)
> >
> >diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index
> >3d997b389345..e3f1bfdf8d6f 100644
> >--- a/drivers/vdpa/vdpa.c
> >+++ b/drivers/vdpa/vdpa.c
> >@@ -540,20 +540,22 @@ static int vdpa_nl_cmd_dev_get_doit(struct
> sk_buff *skb, struct genl_info *info)
> > 	if (!dev) {
> > 		mutex_unlock(&vdpa_dev_mutex);
> > 		NL_SET_ERR_MSG_MOD(info->extack, "device not found");
> >-		return -ENODEV;
> >+		err = -ENODEV;
> >+		goto err;
> > 	}
> > 	vdev = container_of(dev, struct vdpa_device, dev);
> > 	if (!vdev->mdev) {
> > 		mutex_unlock(&vdpa_dev_mutex);
> > 		put_device(dev);
> >-		return -EINVAL;
> >+		err = -EINVAL;
> >+		goto err;
> > 	}
> > 	err = vdpa_dev_fill(vdev, msg, info->snd_portid, info->snd_seq, 0,
> info->extack);
> > 	if (!err)
> > 		err = genlmsg_reply(msg, info);
> > 	put_device(dev);
> > 	mutex_unlock(&vdpa_dev_mutex);
> >-
> >+err:
> 
> If we put this label before mutex_unlock(), we can remove that call in the
> error paths.
> 
> Maybe we can also add another label before put_device() and jump to it in
> the "if (!vdev->mdev)" case.
> 
Yep, I will send v2.
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-02-15 14:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-13 18:39 [PATCH] vdpa: Fix memory leak in error unwinding path Parav Pandit
2021-02-15 11:45 ` Stefano Garzarella
2021-02-15 14:12   ` Parav Pandit

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.