public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Johannes Weiner <hannes@cmpxchg.org>
To: Ravi Singh <ravi.singh1@samsung.com>
Cc: mingo@redhat.com, peterz@infradead.org,
	linux-kernel@vger.kernel.org, a.sahrawat@samsung.com,
	v.narang@samsung.com, vishal.goel@samsung.com,
	Suren Baghdasaryan <surenb@google.com>
Subject: Re: [PATCH] psi: fix integer overflow on unsigned int multiply on 32 bit systems
Date: Wed, 8 Sep 2021 07:32:29 -0400	[thread overview]
Message-ID: <YTifTWj6xsLZSjLA@cmpxchg.org> (raw)
In-Reply-To: <1630931124-27197-1-git-send-email-ravi.singh1@samsung.com>

CC Suren

On Mon, Sep 06, 2021 at 05:55:24PM +0530, Ravi Singh wrote:
> psi accepts window sizes upto WINDOW_MAX_US(10000000). In the case
> where window_us is larger than 4294967, the result of an
> multiplication overflows an unsigned int/long(4 bytes on 32 bit
> system).
> 
> For example, this can happen when the window_us is 5000000 so 5000000
> * 1000 (NSEC_PER_USEC) will result in 5000000000 which is greater than
> UINT_MAX(4294967295). Due to this overflow, 705032704 is stored in
> t->win.size instead of 5000000000. Now psi will be monitoring the
> window size of 705 msecs instead of 5 secs as expected by user.
> 
> Fix this by type casting the first term of the mutiply to a u64.
> 
> Issue doesnot occur on 64 bit systems because NSEC_PER_USEC is of type
> long which is 8 bytes on 64 bit systems.
> 
> Signed-off-by: Ravi Singh <ravi.singh1@samsung.com>
> Signed-off-by: Vishal Goel <vishal.goel@samsung.com>

Acked-by: Johannes Weiner <hannes@cmpxchg.org>

> ---
>  kernel/sched/psi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
> index 1652f2bb5..a2cc33dc2 100644
> --- a/kernel/sched/psi.c
> +++ b/kernel/sched/psi.c
> @@ -1145,7 +1145,7 @@ struct psi_trigger *psi_trigger_create(struct psi_group *group,
>  	t->group = group;
>  	t->state = state;
>  	t->threshold = threshold_us * NSEC_PER_USEC;
> -	t->win.size = window_us * NSEC_PER_USEC;
> +	t->win.size = (u64)window_us * NSEC_PER_USEC;
>  	window_reset(&t->win, 0, 0, 0);
>  
>  	t->event = 0;
> -- 
> 2.17.1
> 

  reply	other threads:[~2021-09-08 11:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20210906122653epcas5p19c46576f0be4d4a101f851a751addde8@epcas5p1.samsung.com>
2021-09-06 12:25 ` [PATCH] psi: fix integer overflow on unsigned int multiply on 32 bit systems Ravi Singh
2021-09-08 11:32   ` Johannes Weiner [this message]
2021-09-10 15:33   ` Peter Zijlstra
     [not found] <CGME20210913085226epcas5p2b516f0f591926c927faa9c60d211bf44@epcas5p2.samsung.com>
2021-09-13  8:51 ` Ravi Singh
2021-11-04 16:55   ` Johannes Weiner
2021-11-04 23:11     ` Suren Baghdasaryan

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=YTifTWj6xsLZSjLA@cmpxchg.org \
    --to=hannes@cmpxchg.org \
    --cc=a.sahrawat@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=ravi.singh1@samsung.com \
    --cc=surenb@google.com \
    --cc=v.narang@samsung.com \
    --cc=vishal.goel@samsung.com \
    /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