vdpa: Fix memory leak in error unwinding path
PATCH 1/1 vdpa: Fix memory leak in error unwinding path
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.
--- drivers/vdpa/vdpa.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/vdpa/vdpa.c +5 -3
@@ -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;
Signature · 6 lines
2.26.2 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 27 lines · Parav Pandit
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 <[email protected]>---
drivers/vdpa/vdpa.c| 8 +++++---1 file changed, 5 insertions(+), 3 deletions(-)drivers/vdpa/vdpa.c +2
-2@@ -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 ;
drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_doit(struct sk_buff *skb, struct genl_info *info) · line 558
Quoted 10 lines
drivers/vdpa/vdpa.c +3
-1+ 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
Quoted 11 lines
drivers/vdpa/vdpa.c +0
-0if (err)nlmsg_free (msg);return err;Signature · 6 lines
2.26.2 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 49 lines
From: Stefano Garzarella <[email protected]>
Sent: Monday, February 15, 2021 5:16 PMdrivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_doit(struct
Quoted 15 lines · Parav Pandit
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 <[email protected]>---
drivers/vdpa/vdpa.c| 8 +++++---1 file changed, 5 insertions(+), 3 deletions(-)drivers/vdpa/vdpa.c index renamed from drivers/vdpa/vdpa.c +0
-0
3d997b389345..e3f1bfdf8d6f100644drivers/vdpa/vdpa.c +0
-0@@ -540,20 +540,22 @@ static int vdpa_nl_cmd_dev_get_doit(struct
sk_buff*skb, structgenl_info*info)Quoted 6 lines
drivers/vdpa/vdpa.c +2
-1if (!dev) {mutex_unlock (&vdpa_dev_mutex);NL_SET_ERR_MSG_MOD (info->extack,"device not found" ); -return -ENODEV ; + err = -ENODEV ; + goto err;drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_doit(struct sk_buff *skb, struct genl_info *info)
Quoted 10 lines
drivers/vdpa/vdpa.c +2
-1} 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);drivers/vdpa/vdpa.c static int vdpa_nl_cmd_dev_get_doit(struct sk_buff *skb, struct genl_info *info) · line 558
Quoted 6 lines
drivers/vdpa/vdpa.c +1
-1if (!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.
Quoted 3 lines
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
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization