Skip to contentSkip to conversation

comedi: drivers: ni_tio: Fix arithmetic expression overflow

PATCH Superseded Denis Arefev 4 participants 4 messages Jan 18, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 comedi: drivers: ni_tio: Fix arithmetic expression overflow

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.

Fixes 3e90b1c7ebe9 ("staging: comedi: ni_tio: tidy up ni_tio_set_clock_src() and helpers")
Cc <[email protected]> # v5.15+
---
 drivers/comedi/drivers/ni_tio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/comedi/drivers/ni_tio.c +1 -1
index da6826d77e60..acc914903c70 100644
@@ -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;
 }
Signature · 1 line
2.25.1
#1 lore raw
Quoted 32 lines · Denis Arefev

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.

Fixes 3e90b1c7ebe9 ("staging: comedi: ni_tio: tidy up ni_tio_set_clock_src() and helpers")
Cc <[email protected]> # v5.15+
---
 drivers/comedi/drivers/ni_tio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/comedi/drivers/ni_tio.c +1 -1
index da6826d77e60..acc914903c70 100644
@@ -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;
 }
Signature · 1 line
2.25.1

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree.

You are receiving this message because of the following common error(s) as indicated below:

- This looks like a new version of a previously submitted patch, but you did not list below the --- line any changes from the previous version. Please read the section entitled "The canonical patch format" in the kernel file, Documentation/process/submitting-patches.rst for what needs to be done here to properly describe this.

If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers.

thanks,

greg k-h's patch email bot

#2 lore raw
Quoted 26 lines

-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: 18 January 2024 14:14
To: Denis Arefev <[email protected]>
Cc: Ian Abbott <[email protected]>; H Hartley Sweeten <[email protected]>; linux- [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] comedi: drivers: ni_tio: Fix arithmetic expression overflow

Quoted 15 lines · Denis Arefev

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.

Fixes 3e90b1c7ebe9 ("staging: comedi: ni_tio: tidy up ni_tio_set_clock_src() and helpers")
Cc <[email protected]> # v5.15+
---
 drivers/comedi/drivers/ni_tio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 10 lines

drivers/comedi/drivers/ni_tio.c static int ni_tio_set_clock_src(struct ni_gpct *counter, · line 803

Quoted 10 lines
drivers/comedi/drivers/ni_tio.c +1 -1
index da6826d77e60..acc914903c70 100644
@@ -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;

What about 32bit systems...

Quoted 27 lines
Quoted 7 lines
drivers/comedi/drivers/ni_tio.c +0 -1
 	ni_tio_set_sync_mode(counter);
 	return 0;
 }
--

2.25.1

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree.

You are receiving this message because of the following common error(s) as indicated below:

- This looks like a new version of a previously submitted patch, but you did not list below the --- line any changes from the previous version. Please read the section entitled "The canonical patch format" in the kernel file, Documentation/process/submitting-patches.rst for what needs to be done here to properly describe this.

Quoted 8 lines

If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers.

thanks,

greg k-h's patch email bot

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

maintainer
#3 lore raw
Quoted 24 lines · David Laight
Quoted 24 lines

-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: 18 January 2024 14:14
To: Denis Arefev <[email protected]>
Cc: Ian Abbott <[email protected]>; H Hartley Sweeten <[email protected]>; linux- [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] comedi: drivers: ni_tio: Fix arithmetic expression overflow

Quoted 15 lines · Denis Arefev

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.

Fixes 3e90b1c7ebe9 ("staging: comedi: ni_tio: tidy up ni_tio_set_clock_src() and helpers")
Cc <[email protected]> # v5.15+
---
  drivers/comedi/drivers/ni_tio.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines
Quoted 10 lines

drivers/comedi/drivers/ni_tio.c static int ni_tio_set_clock_src(struct ni_gpct *counter, · line 803

Quoted 10 lines
drivers/comedi/drivers/ni_tio.c +1 -1
index da6826d77e60..acc914903c70 100644
@@ -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;

What about 32bit systems...

Oh, good point. It should be 1000ULL.

Signature · 4 lines
-=( Ian Abbott <[email protected]> || MEV Ltd. is a company  )=-
-=( registered in England & Wales.  Regd. number: 02862268.  )=-
-=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=-
-=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-