Skip to contentSkip to conversation

media: uvcvideo: Avoid invalid memory access

PATCH In review Ricardo Ribalda 2 participants 3 messages Dec 1, 2021

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

PATCH v2 1/2 media: uvcvideo: Avoid invalid memory access

If mappings points to an invalid memory, we will be invalid accessing it.
Solve it by initializing the value of the variable mapping and by changing the order in the conditional statement (to avoid accessing mapping->id if not needed).

Fix:
kasan: GPF could be caused by NULL-ptr deref or user memory access

general protection fault: 0000 [#1] PREEMPT SMP KASAN NOPTI
Fixes 6350d6a4ed487 ("media: uvcvideo: Set error_idx during ctrl_commit errors")
---
 drivers/media/usb/uvc/uvc_ctrl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/uvc/uvc_ctrl.c +1 -1
index 30bfe9069a1f..9a25d6029255 100644
@@ -1638,7 +1638,7 @@ static int uvc_ctrl_find_ctrl_idx(struct uvc_entity *entity,
 				  struct v4l2_ext_controls *ctrls,
 				  struct uvc_control *uvc_control)
 {
-	struct uvc_control_mapping *mapping;
+	struct uvc_control_mapping *mapping = NULL;
 	struct uvc_control *ctrl_found;
 	unsigned int i;
 
Signature · 1 line
2.34.0.rc2.393.gf8c9666880-goog
#1 lore raw

PATCH v2 2/2 media: uvcvideo: Avoid returning invalid controls

If the memory where ctrl_found is placed has the value of uvc_ctrl and __uvc_find_control does not find the control we will return an invalid index.

Fixes 6350d6a4ed487 ("media: uvcvideo: Set error_idx during ctrl_commit errors")
---
 drivers/media/usb/uvc/uvc_ctrl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/uvc/uvc_ctrl.c +1 -1
index 9a25d6029255..b4f6edf968bc 100644
@@ -1639,7 +1639,7 @@ static int uvc_ctrl_find_ctrl_idx(struct uvc_entity *entity,
 				  struct uvc_control *uvc_control)
 {
 	struct uvc_control_mapping *mapping = NULL;
-	struct uvc_control *ctrl_found;
+	struct uvc_control *ctrl_found = NULL;
 	unsigned int i;
 
 	if (!entity)
Signature · 1 line
2.34.0.rc2.393.gf8c9666880-goog
maintainer Reviewed-by on v2 1/2
#2 lore raw
In reply to Ricardo Ribalda

Hi Ricardo,

Thank you for the patch.

Quoted 2 lines · Ricardo Ribalda

If mappings points to an invalid memory, we will be invalid accessing it.

I'll reflow the commit message.

Quoted 10 lines

Solve it by initializing the value of the variable mapping and by changing the order in the conditional statement (to avoid accessing mapping->id if not needed).

Fix:
kasan: GPF could be caused by NULL-ptr deref or user memory access

general protection fault: 0000 [#1] PREEMPT SMP KASAN NOPTI
Fixes 6350d6a4ed487 ("media: uvcvideo: Set error_idx during ctrl_commit errors")
Quoted 17 lines
---
 drivers/media/usb/uvc/uvc_ctrl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/uvc/uvc_ctrl.c +1 -1
index 30bfe9069a1f..9a25d6029255 100644
@@ -1638,7 +1638,7 @@ static int uvc_ctrl_find_ctrl_idx(struct uvc_entity *entity,
 				  struct v4l2_ext_controls *ctrls,
 				  struct uvc_control *uvc_control)
 {
-	struct uvc_control_mapping *mapping;
+	struct uvc_control_mapping *mapping = NULL;
 	struct uvc_control *ctrl_found;
 	unsigned int i;
 
Signature · 3 lines
Regards,

Laurent Pinchart