linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Suren Baghdasaryan <surenb@google.com>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: Ravi Singh <ravi.singh1@samsung.com>,
	mingo@redhat.com, peterz@infradead.org,
	linux-kernel@vger.kernel.org, a.sahrawat@samsung.com,
	v.narang@samsung.com, vishal.goel@samsung.com
Subject: Re: [PATCH] psi: fix integer overflow on unsigned int multiply on 32 bit systems
Date: Thu, 4 Nov 2021 16:11:37 -0700	[thread overview]
Message-ID: <CAJuCfpFUSBJ6fRf5vRwycdXx5vHdM9vj36+iqh8jN2wVvDtuCw@mail.gmail.com> (raw)
In-Reply-To: <YYQQdI8rjvN4ZEOd@cmpxchg.org>

On Thu, Nov 4, 2021 at 9:55 AM Johannes Weiner <hannes@cmpxchg.org> wrote:
>
> CC Suren

Thanks!

>
> Sorry, this fell through the cracks.
>
> On Mon, Sep 13, 2021 at 02:21:35PM +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.

Looks reasonable to me.

> >
> > 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>
>
> Fixes: 0e94682b73bf psi: introduce psi monitor
> Acked-by: Johannes Weiner <hannes@cmpxchg.org>

Reviewed-by: Suren Baghdasaryan <surenb@google.com>

>
> Peter would you mind taking this through -tip?
>
> > ---
> >  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-11-04 23:11 UTC|newest]

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

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=CAJuCfpFUSBJ6fRf5vRwycdXx5vHdM9vj36+iqh8jN2wVvDtuCw@mail.gmail.com \
    --to=surenb@google.com \
    --cc=a.sahrawat@samsung.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=ravi.singh1@samsung.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;
as well as URLs for NNTP newsgroup(s).