Skip to contentSkip to conversation

media: atomisp: prevent integer overflow in sh_css_set_black_frame()

PATCH In review Dan Carpenter 2 participants 2 messages Sep 1, 2022

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

PATCH 1/1 media: atomisp: prevent integer overflow in sh_css_set_black_frame()

The "height" and "width" values come from the user so the "height * width" multiplication can overflow.

Fixes a49d25364dfb ("staging/atomisp: Add support for the Intel IPU v2")
---
 drivers/staging/media/atomisp/pci/sh_css_params.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/media/atomisp/pci/sh_css_params.c +2 -2
index 0e7c38b2bfe3..67915d76a87f 100644
@@ -950,8 +950,8 @@ sh_css_set_black_frame(struct ia_css_stream *stream,
 		params->fpn_config.data = NULL;
 	}
 	if (!params->fpn_config.data) {
-		params->fpn_config.data = kvmalloc(height * width *
-						   sizeof(short), GFP_KERNEL);
+		params->fpn_config.data = kvmalloc(array3_size(height, width, sizeof(short)),
+						   GFP_KERNEL);
 		if (!params->fpn_config.data) {
 			IA_CSS_ERROR("out of memory");
 			IA_CSS_LEAVE_ERR_PRIVATE(-ENOMEM);
Signature · 1 line
2.35.1
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 5 lines · Dan Carpenter

The "height" and "width" values come from the user so the "height * width" multiplication can overflow.

Fixes a49d25364dfb ("staging/atomisp: Add support for the Intel IPU v2")

Thanks, patch looks good to me:

I'll also add this to my set of pending atomisp2 cleanup patches so that the next time I test the atomisp2 with my local tree this will also get tested.

Regards,

Hans

Quoted 19 lines
---
 drivers/staging/media/atomisp/pci/sh_css_params.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/media/atomisp/pci/sh_css_params.c +2 -2
index 0e7c38b2bfe3..67915d76a87f 100644
@@ -950,8 +950,8 @@ sh_css_set_black_frame(struct ia_css_stream *stream,
 		params->fpn_config.data = NULL;
 	}
 	if (!params->fpn_config.data) {
-		params->fpn_config.data = kvmalloc(height * width *
-						   sizeof(short), GFP_KERNEL);
+		params->fpn_config.data = kvmalloc(array3_size(height, width, sizeof(short)),
+						   GFP_KERNEL);
 		if (!params->fpn_config.data) {
 			IA_CSS_ERROR("out of memory");
 			IA_CSS_LEAVE_ERR_PRIVATE(-ENOMEM);