Skip to contentSkip to conversation

media: uvcvideo: fix a crash in uvc_ctrl_init_ctrl()

PATCH In review Dan Carpenter 2 participants 3 messages Jul 19, 2022 – Jul 20, 2022

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

PATCH 1/1 media: uvcvideo: fix a crash in uvc_ctrl_init_ctrl()

There is a path where "mapping" is NULL when we try to process the common mappings so it will crash.

Fixes 86f7ef773156 ("media: uvcvideo: Add support for per-device control mapping overrides")

---
This bug was previously reported by the kbuild bot and fixed in later versions of the patchset. The git log doesn't have a link to lore.kernel.org but I suspect an earlier version got merged?

 drivers/media/usb/uvc/uvc_ctrl.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/media/usb/uvc/uvc_ctrl.c +5 -5
index e4826a846861..00ea894e79fd 100644
@@ -2413,9 +2413,9 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,
 {
 	const struct uvc_control_info *info = uvc_ctrls;
 	const struct uvc_control_info *iend = info + ARRAY_SIZE(uvc_ctrls);
-	const struct uvc_control_mapping *mapping = uvc_ctrl_mappings;
-	const struct uvc_control_mapping *mend =
-		mapping + ARRAY_SIZE(uvc_ctrl_mappings);
+	const struct uvc_control_mapping *mapping;
+	const struct uvc_control_mapping *mend;
+	unsigned int i;
 
 	/*
 	 * XU controls initialization requires querying the device for control
@@ -2453,7 +2453,6 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,
 	 */
 	if (chain->dev->info->mappings) {
 		bool custom = false;
-		unsigned int i;
 
 		for (i = 0; (mapping = chain->dev->info->mappings[i]); ++i) {
 			if (uvc_entity_match_guid(ctrl->entity, mapping->entity) &&
@@ -2468,7 +2467,8 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,
 	}
 
 	/* Process common mappings next. */
-	for (; mapping < mend; ++mapping) {
+	for (i = 0; i < ARRAY_SIZE(uvc_ctrl_mappings); i++) {
+		mapping = &uvc_ctrl_mappings[i];
 		if (uvc_entity_match_guid(ctrl->entity, mapping->entity) &&
 		    ctrl->info.selector == mapping->selector)
 			__uvc_ctrl_add_mapping(chain, ctrl, mapping);
Signature · 1 line
2.35.1
maintainer
#1 lore raw

Hi Dan,

Thank you for the patch.

Quoted 5 lines · Dan Carpenter

There is a path where "mapping" is NULL when we try to process the common mappings so it will crash.

Fixes 86f7ef773156 ("media: uvcvideo: Add support for per-device control mapping overrides")

I've submitted [1] to fix this issue, and [2] to replace all the error-prone loops in this function.

[1] https://lore.kernel.org/linux-media/[email protected]/
[2] https://lore.kernel.org/linux-media/[email protected]/T/#u

Quoted 46 lines

---
This bug was previously reported by the kbuild bot and fixed in later versions of the patchset. The git log doesn't have a link to lore.kernel.org but I suspect an earlier version got merged?

 drivers/media/usb/uvc/uvc_ctrl.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/media/usb/uvc/uvc_ctrl.c +5 -5
index e4826a846861..00ea894e79fd 100644
@@ -2413,9 +2413,9 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,
 {
 	const struct uvc_control_info *info = uvc_ctrls;
 	const struct uvc_control_info *iend = info + ARRAY_SIZE(uvc_ctrls);
-	const struct uvc_control_mapping *mapping = uvc_ctrl_mappings;
-	const struct uvc_control_mapping *mend =
-		mapping + ARRAY_SIZE(uvc_ctrl_mappings);
+	const struct uvc_control_mapping *mapping;
+	const struct uvc_control_mapping *mend;
+	unsigned int i;
 
 	/*
 	 * XU controls initialization requires querying the device for control
@@ -2453,7 +2453,6 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,
 	 */
 	if (chain->dev->info->mappings) {
 		bool custom = false;
-		unsigned int i;
 
 		for (i = 0; (mapping = chain->dev->info->mappings[i]); ++i) {
 			if (uvc_entity_match_guid(ctrl->entity, mapping->entity) &&
@@ -2468,7 +2467,8 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,
 	}
 
 	/* Process common mappings next. */
-	for (; mapping < mend; ++mapping) {
+	for (i = 0; i < ARRAY_SIZE(uvc_ctrl_mappings); i++) {
+		mapping = &uvc_ctrl_mappings[i];
 		if (uvc_entity_match_guid(ctrl->entity, mapping->entity) &&
 		    ctrl->info.selector == mapping->selector)
 			__uvc_ctrl_add_mapping(chain, ctrl, mapping);
Signature · 1 line
2.35.1
Signature · 3 lines
Regards,

Laurent Pinchart
#2 lore raw
Quoted 8 lines · Laurent Pinchart

Hi Dan,

Thank you for the patch.

Quoted 3 lines · Dan Carpenter

There is a path where "mapping" is NULL when we try to process the common mappings so it will crash.

Quoted 9 lines
Quoted 2 lines
Fixes 86f7ef773156 ("media: uvcvideo: Add support for per-device control mapping overrides")

I've submitted [1] to fix this issue, and [2] to replace all the error-prone loops in this function.

[1] https://lore.kernel.org/linux-media/[email protected]/
[2] https://lore.kernel.org/linux-media/[email protected]/T/#u

Ah, perfect. Thank you!

regards,
dan carpenter

Quoted 4 lines
Quoted 4 lines

---
This bug was previously reported by the kbuild bot and fixed in later versions of the patchset. The git log doesn't have a link to lore.kernel.org but I suspect an earlier version got merged?