All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: comedi: dt2811: fix integer overflow in multiply
@ 2019-02-02 21:59 ` Colin King
  0 siblings, 0 replies; 6+ messages in thread
From: Colin King @ 2019-02-02 21:59 UTC (permalink / raw)
  To: Ian Abbott, H Hartley Sweeten, Greg Kroah-Hartman, devel
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Multiplying two unsigned ints leads to an unsigned int result. The
intention is that the result is a unsigned long long, so to fix the
overflow cast the div to an unsigned long long to ensure that the
multiplication is on unsigned long longs to avoid overflow.

Detected by CoverityScan, CID#1357597 ("Unintentioal integer overflow")

Fixes: f2975a9b2ab9 ("staging: comedi: dt2811: add async command support for AI subdevice")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/staging/comedi/drivers/dt2811.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/comedi/drivers/dt2811.c b/drivers/staging/comedi/drivers/dt2811.c
index 05207a519755..820e75f850ff 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -323,7 +323,8 @@ static unsigned int dt2811_ns_to_timer(unsigned int *nanosec,
 		for (_mult = 0; _mult <= 7; _mult++) {
 			unsigned int div = dt2811_clk_dividers[_div];
 			unsigned int mult = dt2811_clk_multipliers[_mult];
-			unsigned long long divider = div * mult;
+			unsigned long long divider =
+				(unsigned long long)div * mult;
 			unsigned int divisor = DT2811_TMRCTR_MANTISSA(_div) |
 					       DT2811_TMRCTR_EXPONENT(_mult);
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] staging: comedi: dt2811: fix integer overflow in multiply
@ 2019-02-02 21:59 ` Colin King
  0 siblings, 0 replies; 6+ messages in thread
From: Colin King @ 2019-02-02 21:59 UTC (permalink / raw)
  To: Ian Abbott, H Hartley Sweeten, Greg Kroah-Hartman, devel
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Multiplying two unsigned ints leads to an unsigned int result. The
intention is that the result is a unsigned long long, so to fix the
overflow cast the div to an unsigned long long to ensure that the
multiplication is on unsigned long longs to avoid overflow.

Detected by CoverityScan, CID#1357597 ("Unintentioal integer overflow")

Fixes: f2975a9b2ab9 ("staging: comedi: dt2811: add async command support for AI subdevice")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/staging/comedi/drivers/dt2811.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/comedi/drivers/dt2811.c b/drivers/staging/comedi/drivers/dt2811.c
index 05207a519755..820e75f850ff 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -323,7 +323,8 @@ static unsigned int dt2811_ns_to_timer(unsigned int *nanosec,
 		for (_mult = 0; _mult <= 7; _mult++) {
 			unsigned int div = dt2811_clk_dividers[_div];
 			unsigned int mult = dt2811_clk_multipliers[_mult];
-			unsigned long long divider = div * mult;
+			unsigned long long divider +				(unsigned long long)div * mult;
 			unsigned int divisor = DT2811_TMRCTR_MANTISSA(_div) |
 					       DT2811_TMRCTR_EXPONENT(_mult);
 
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] staging: comedi: dt2811: fix integer overflow in multiply
  2019-02-02 21:59 ` Colin King
@ 2019-02-03 11:29   ` Dan Carpenter
  -1 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2019-02-03 11:29 UTC (permalink / raw)
  To: Colin King
  Cc: Ian Abbott, H Hartley Sweeten, Greg Kroah-Hartman, devel,
	kernel-janitors, linux-kernel

On Sat, Feb 02, 2019 at 09:59:16PM +0000, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Multiplying two unsigned ints leads to an unsigned int result. The
> intention is that the result is a unsigned long long, so to fix the
> overflow cast the div to an unsigned long long to ensure that the
> multiplication is on unsigned long longs to avoid overflow.
> 
> Detected by CoverityScan, CID#1357597 ("Unintentioal integer overflow")
> 
> Fixes: f2975a9b2ab9 ("staging: comedi: dt2811: add async command support for AI subdevice")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/staging/comedi/drivers/dt2811.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/comedi/drivers/dt2811.c b/drivers/staging/comedi/drivers/dt2811.c
> index 05207a519755..820e75f850ff 100644
> --- a/drivers/staging/comedi/drivers/dt2811.c
> +++ b/drivers/staging/comedi/drivers/dt2811.c
> @@ -323,7 +323,8 @@ static unsigned int dt2811_ns_to_timer(unsigned int *nanosec,
>  		for (_mult = 0; _mult <= 7; _mult++) {
>  			unsigned int div = dt2811_clk_dividers[_div];
>  			unsigned int mult = dt2811_clk_multipliers[_mult];
> -			unsigned long long divider = div * mult;
> +			unsigned long long divider =
> +				(unsigned long long)div * mult;

The max "div" can be is 12.  The max "mult" can be is 10,000,000.  So
this is a false positive because there is no overflow.  The code is not
complicated.  Unfortunately, Smatch has the exact same problem...

We should fix the checker instead of the code.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] staging: comedi: dt2811: fix integer overflow in multiply
@ 2019-02-03 11:29   ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2019-02-03 11:29 UTC (permalink / raw)
  To: Colin King
  Cc: Ian Abbott, H Hartley Sweeten, Greg Kroah-Hartman, devel,
	kernel-janitors, linux-kernel

On Sat, Feb 02, 2019 at 09:59:16PM +0000, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Multiplying two unsigned ints leads to an unsigned int result. The
> intention is that the result is a unsigned long long, so to fix the
> overflow cast the div to an unsigned long long to ensure that the
> multiplication is on unsigned long longs to avoid overflow.
> 
> Detected by CoverityScan, CID#1357597 ("Unintentioal integer overflow")
> 
> Fixes: f2975a9b2ab9 ("staging: comedi: dt2811: add async command support for AI subdevice")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/staging/comedi/drivers/dt2811.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/comedi/drivers/dt2811.c b/drivers/staging/comedi/drivers/dt2811.c
> index 05207a519755..820e75f850ff 100644
> --- a/drivers/staging/comedi/drivers/dt2811.c
> +++ b/drivers/staging/comedi/drivers/dt2811.c
> @@ -323,7 +323,8 @@ static unsigned int dt2811_ns_to_timer(unsigned int *nanosec,
>  		for (_mult = 0; _mult <= 7; _mult++) {
>  			unsigned int div = dt2811_clk_dividers[_div];
>  			unsigned int mult = dt2811_clk_multipliers[_mult];
> -			unsigned long long divider = div * mult;
> +			unsigned long long divider > +				(unsigned long long)div * mult;

The max "div" can be is 12.  The max "mult" can be is 10,000,000.  So
this is a false positive because there is no overflow.  The code is not
complicated.  Unfortunately, Smatch has the exact same problem...

We should fix the checker instead of the code.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] staging: comedi: dt2811: fix integer overflow in multiply
  2019-02-03 11:29   ` Dan Carpenter
@ 2019-02-04  7:48     ` Dan Carpenter
  -1 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2019-02-04  7:48 UTC (permalink / raw)
  To: Colin King
  Cc: Ian Abbott, H Hartley Sweeten, Greg Kroah-Hartman, devel,
	kernel-janitors, linux-kernel

On Sun, Feb 03, 2019 at 02:29:04PM +0300, Dan Carpenter wrote:
> > diff --git a/drivers/staging/comedi/drivers/dt2811.c b/drivers/staging/comedi/drivers/dt2811.c
> > index 05207a519755..820e75f850ff 100644
> > --- a/drivers/staging/comedi/drivers/dt2811.c
> > +++ b/drivers/staging/comedi/drivers/dt2811.c
> > @@ -323,7 +323,8 @@ static unsigned int dt2811_ns_to_timer(unsigned int *nanosec,
> >  		for (_mult = 0; _mult <= 7; _mult++) {
> >  			unsigned int div = dt2811_clk_dividers[_div];
> >  			unsigned int mult = dt2811_clk_multipliers[_mult];
> > -			unsigned long long divider = div * mult;
> > +			unsigned long long divider =
> > +				(unsigned long long)div * mult;
> 
> The max "div" can be is 12.  The max "mult" can be is 10,000,000.  So
> this is a false positive because there is no overflow.  The code is not
> complicated.  Unfortunately, Smatch has the exact same problem...

Smatch actually parses this correctly, but I had a power failure over
the weekend that messed up my results.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] staging: comedi: dt2811: fix integer overflow in multiply
@ 2019-02-04  7:48     ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2019-02-04  7:48 UTC (permalink / raw)
  To: Colin King
  Cc: Ian Abbott, H Hartley Sweeten, Greg Kroah-Hartman, devel,
	kernel-janitors, linux-kernel

On Sun, Feb 03, 2019 at 02:29:04PM +0300, Dan Carpenter wrote:
> > diff --git a/drivers/staging/comedi/drivers/dt2811.c b/drivers/staging/comedi/drivers/dt2811.c
> > index 05207a519755..820e75f850ff 100644
> > --- a/drivers/staging/comedi/drivers/dt2811.c
> > +++ b/drivers/staging/comedi/drivers/dt2811.c
> > @@ -323,7 +323,8 @@ static unsigned int dt2811_ns_to_timer(unsigned int *nanosec,
> >  		for (_mult = 0; _mult <= 7; _mult++) {
> >  			unsigned int div = dt2811_clk_dividers[_div];
> >  			unsigned int mult = dt2811_clk_multipliers[_mult];
> > -			unsigned long long divider = div * mult;
> > +			unsigned long long divider > > +				(unsigned long long)div * mult;
> 
> The max "div" can be is 12.  The max "mult" can be is 10,000,000.  So
> this is a false positive because there is no overflow.  The code is not
> complicated.  Unfortunately, Smatch has the exact same problem...

Smatch actually parses this correctly, but I had a power failure over
the weekend that messed up my results.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-02-04  7:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-02 21:59 [PATCH] staging: comedi: dt2811: fix integer overflow in multiply Colin King
2019-02-02 21:59 ` Colin King
2019-02-03 11:29 ` Dan Carpenter
2019-02-03 11:29   ` Dan Carpenter
2019-02-04  7:48   ` Dan Carpenter
2019-02-04  7:48     ` Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.