comedi: drivers: ni_tio: Fix arithmetic expression overflow

Message ID 20240117124229.37455-1-arefev@swemel.ru
State New
Headers
Series comedi: drivers: ni_tio: Fix arithmetic expression overflow |

Commit Message

Denis Arefev Jan. 17, 2024, 12:42 p.m. UTC
  The value of an arithmetic expression period_ns * 1000 is subject
to overflow due to a failure to cast operands to a larger data
type before performing arithmetic

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

Signed-off-by: Denis Arefev <arefev@swemel.ru>
---
 drivers/comedi/drivers/ni_tio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Ian Abbott Jan. 17, 2024, 1:52 p.m. UTC | #1
On 17/01/2024 12:42, Denis Arefev wrote:
> The value of an arithmetic expression period_ns * 1000 is subject
> to overflow due to a failure to cast operands to a larger data
> type before performing arithmetic
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Signed-off-by: Denis Arefev <arefev@swemel.ru>
> ---
>   drivers/comedi/drivers/ni_tio.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/comedi/drivers/ni_tio.c b/drivers/comedi/drivers/ni_tio.c
> index da6826d77e60..acc914903c70 100644
> --- a/drivers/comedi/drivers/ni_tio.c
> +++ b/drivers/comedi/drivers/ni_tio.c
> @@ -800,7 +800,7 @@ static int ni_tio_set_clock_src(struct ni_gpct *counter,
>   				GI_PRESCALE_X2(counter_dev->variant) |
>   				GI_PRESCALE_X8(counter_dev->variant), bits);
>   	}
> -	counter->clock_period_ps = period_ns * 1000;
> +	counter->clock_period_ps = period_ns * 1000UL;
>   	ni_tio_set_sync_mode(counter);
>   	return 0;
>   }

Looks good, thanks!

Reviewed-by: Ian Abbott <abbotti@mev.co.uk>

Could you resend it and Cc Greg Kroah-Hartman 
<gregkh@linuxfoundation.org> ?  It's more likely to get applied that way 
because I don't maintain my own kernel tree for comedi.  Feel free to 
add my Reviewed-by line.
  

Patch

diff --git a/drivers/comedi/drivers/ni_tio.c b/drivers/comedi/drivers/ni_tio.c
index da6826d77e60..acc914903c70 100644
--- a/drivers/comedi/drivers/ni_tio.c
+++ b/drivers/comedi/drivers/ni_tio.c
@@ -800,7 +800,7 @@  static int ni_tio_set_clock_src(struct ni_gpct *counter,
 				GI_PRESCALE_X2(counter_dev->variant) |
 				GI_PRESCALE_X8(counter_dev->variant), bits);
 	}
-	counter->clock_period_ps = period_ns * 1000;
+	counter->clock_period_ps = period_ns * 1000UL;
 	ni_tio_set_sync_mode(counter);
 	return 0;
 }