media: uvcvideo: Avoid invalid memory access
Subsystems (2)
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
--- drivers/media/usb/uvc/uvc_ctrl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/uvc/uvc_ctrl.c +1 -1
@@ -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
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.
--- drivers/media/usb/uvc/uvc_ctrl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/uvc/uvc_ctrl.c +1 -1
@@ -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
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->idif not needed).Fix:
kasan: GPF could be caused by NULL-ptr deref or user memory accessgeneral protection fault: 0000 [#1] PREEMPT SMP KASAN NOPTIFixes 6350d6a4ed487 ("media: uvcvideo: Set error_idx during ctrl_commit errors")Signed-off-by Ricardo Ribalda <[email protected]>
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@@ -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