V4L/DVB (13661): rj54n1cb0c: possible integer overflow fix

Message ID 20240917140454.7880-1-a.burakov@rosalinux.ru (mailing list archive)
State New
Headers
Series V4L/DVB (13661): rj54n1cb0c: possible integer overflow fix |

Checks

Context Check Description
media-ci/HTML_report success Link
media-ci/report success Link
media-ci/bisect success Link
media-ci/doc success Link
media-ci/build success Link
media-ci/static-upstream success Link
media-ci/abi success Link
media-ci/media-patchstyle fail Link
media-ci/checkpatch success Link

Commit Message

Aleksandr Burakov Sept. 17, 2024, 2:04 p.m. UTC
  An integer overflow may occur due to arithmetic operation
(multiplication) between value '314572800' and variable 'resize',
where the value comes from '12 * RJ54N1_MAX_WIDTH * (1 << 14)' 
and when 'resize' is equal to 16319.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: a6b5f2008a3d ("V4L/DVB (13661): rj54n1cb0c: Add cropping, auto white balance, restrict sizes, add platform data")
Signed-off-by: Aleksandr Burakov <a.burakov@rosalinux.ru>
---
 drivers/media/i2c/rj54n1cb0c.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Sergey Shtylyov Sept. 18, 2024, 9:05 a.m. UTC | #1
On 9/17/24 17:04, Aleksandr Burakov wrote:

> An integer overflow may occur due to arithmetic operation
> (multiplication) between value '314572800' and variable 'resize',
> where the value comes from '12 * RJ54N1_MAX_WIDTH * (1 << 14)' 
> and when 'resize' is equal to 16319.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: a6b5f2008a3d ("V4L/DVB (13661): rj54n1cb0c: Add cropping, auto white balance, restrict sizes, add platform data")
> Signed-off-by: Aleksandr Burakov <a.burakov@rosalinux.ru>
> ---
>  drivers/media/i2c/rj54n1cb0c.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/i2c/rj54n1cb0c.c b/drivers/media/i2c/rj54n1cb0c.c
> index a59db10153cd..a612ec1e7157 100644
> --- a/drivers/media/i2c/rj54n1cb0c.c
> +++ b/drivers/media/i2c/rj54n1cb0c.c
> @@ -776,8 +776,8 @@ static int rj54n1_sensor_scale(struct v4l2_subdev *sd, s32 *in_w, s32 *in_h,
>  	}
>  
>  	/* Antiflicker */
> -	peak = 12 * RJ54N1_MAX_WIDTH * (1 << 14) * resize / rj54n1->tgclk_mhz /
> -		10000;
> +	peak = 12 * RJ54N1_MAX_WIDTH * resize / rj54n1->tgclk_mhz / 10000;
> +	peak = peak * (1 << 14);

	peak *= 1 << 14;

[...]

MBR, Sergey
  

Patch

diff --git a/drivers/media/i2c/rj54n1cb0c.c b/drivers/media/i2c/rj54n1cb0c.c
index a59db10153cd..a612ec1e7157 100644
--- a/drivers/media/i2c/rj54n1cb0c.c
+++ b/drivers/media/i2c/rj54n1cb0c.c
@@ -776,8 +776,8 @@  static int rj54n1_sensor_scale(struct v4l2_subdev *sd, s32 *in_w, s32 *in_h,
 	}
 
 	/* Antiflicker */
-	peak = 12 * RJ54N1_MAX_WIDTH * (1 << 14) * resize / rj54n1->tgclk_mhz /
-		10000;
+	peak = 12 * RJ54N1_MAX_WIDTH * resize / rj54n1->tgclk_mhz / 10000;
+	peak = peak * (1 << 14);
 	peak_50 = peak / 6;
 	peak_60 = peak / 5;