Skip to contentSkip to conversation

media: uvcvideo: fix possible memory leak issue

PATCH In review Ameer Hamza 2 participants 2 messages Dec 8, 2021 – Dec 9, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: uvcvideo: fix possible memory leak issue

In uvc_ioctl_ctrl_map() implementation, there is a possibility of memory leak if control id name is not listed and kmemdup() is failed somehow. This is a rare scenario but possible.

Addresses-Coverity: 1494069 (Resource leak)

---
 drivers/media/usb/uvc/uvc_v4l2.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/media/usb/uvc/uvc_v4l2.c +4 -2
index f4e4aff8ddf7..711556d13d03 100644
@@ -44,8 +44,10 @@ static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain,
 	if (v4l2_ctrl_get_name(map->id) == NULL) {
 		map->name = kmemdup(xmap->name, sizeof(xmap->name),
 				    GFP_KERNEL);
-		if (!map->name)
-			return -ENOMEM;
+		if (!map->name) {
+			ret = -ENOMEM;
+			goto free_map;
+		}
 	}
 	memcpy(map->entity, xmap->entity, sizeof(map->entity));
 	map->selector = xmap->selector;
Signature · 1 line
2.25.1
#1 lore raw

Hi Ameer

Thanks for the patch.

It is already covered by
https://lore.kernel.org/lkml/[email protected]/
which is in the staging branch of the media tree.

Thanks!

Quoted 31 lines · Ameer Hamza

In uvc_ioctl_ctrl_map() implementation, there is a possibility of memory leak if control id name is not listed and kmemdup() is failed somehow. This is a rare scenario but possible.

Addresses-Coverity: 1494069 (Resource leak)

---
 drivers/media/usb/uvc/uvc_v4l2.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/media/usb/uvc/uvc_v4l2.c +4 -3
index f4e4aff8ddf7..711556d13d03 100644
@@ -44,8 +44,10 @@ static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain,
        if (v4l2_ctrl_get_name(map->id) == NULL) {
                map->name = kmemdup(xmap->name, sizeof(xmap->name),
                                    GFP_KERNEL);
-               if (!map->name)
-                       return -ENOMEM;
+               if (!map->name) {
+                       ret = -ENOMEM;
+                       goto free_map;
+               }
        }
        memcpy(map->entity, xmap->entity, sizeof(map->entity));
        map->selector = xmap->selector;
--

2.25.1

Signature · 1 line
Ricardo Ribalda