Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Karan Sanghavi <karansanghvi98@gmail.com>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Shuah Khan <skhan@linuxfoundation.org>,
	Anup <anupnewsmail@gmail.com>
Subject: Re: [PATCH] iio: invensense: fix integer overflow while multiplication
Date: Sun, 3 Nov 2024 11:18:27 +0000	[thread overview]
Message-ID: <20241103111827.0894a40a@jic23-huawei> (raw)
In-Reply-To: <20241103-coverity1586045integeroverflow-v1-1-43ea37a3f3cd@gmail.com>

On Sun, 03 Nov 2024 08:43:14 +0000
Karan Sanghavi <karansanghvi98@gmail.com> wrote:

Hi Karan,

> Typecast a variable to int64_t for 64-bit arithmetic multiplication

The path to actually triggering this is non obvious as these
inputs are the result of rather complex code paths and per chip
constraints.  Have you identified a particular combination that overflows
or is this just based on the type?  I have no problem with applying this
as hardening against future uses but unless we have a path to trigger
it today it isn't a fix.

If you do have a path, this description should state what it is.

> 
> Signed-off-by: Karan Sanghavi <karansanghvi98@gmail.com>
If it's a real bug, needs a Fixes tag so we know how far to backport it.

> ---
>  drivers/iio/common/inv_sensors/inv_sensors_timestamp.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c b/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c
> index f44458c380d9..d1d11d0b2458 100644
> --- a/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c
> +++ b/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c
> @@ -105,8 +105,8 @@ static bool inv_update_chip_period(struct inv_sensors_timestamp *ts,
>  
>  static void inv_align_timestamp_it(struct inv_sensors_timestamp *ts)
>  {
> -	const int64_t period_min = ts->min_period * ts->mult;
> -	const int64_t period_max = ts->max_period * ts->mult;
> +	const int64_t period_min = (int64_t)ts->min_period * ts->mult;
> +	const int64_t period_max = (int64_t)ts->max_period * ts->mult;
>  	int64_t add_max, sub_max;
>  	int64_t delta, jitter;
>  	int64_t adjust;
> 
> ---
> base-commit: 81983758430957d9a5cb3333fe324fd70cf63e7e
> change-id: 20241102-coverity1586045integeroverflow-cbbf357475d9
> 
> Best regards,


  reply	other threads:[~2024-11-03 11:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-03  8:43 [PATCH] iio: invensense: fix integer overflow while multiplication Karan Sanghavi
2024-11-03 11:18 ` Jonathan Cameron [this message]
2024-11-04 16:26   ` Karan Sanghavi
2024-11-09 15:28     ` Jonathan Cameron
2024-11-05 17:39   ` Karan Sanghavi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241103111827.0894a40a@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=anupnewsmail@gmail.com \
    --cc=karansanghvi98@gmail.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox