mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ravi Singh <ravi.singh1@samsung.com>
To: hannes@cmpxchg.org, mingo@redhat.com, peterz@infradead.org,
	linux-kernel@vger.kernel.org
Cc: a.sahrawat@samsung.com, v.narang@samsung.com,
	vishal.goel@samsung.com, Ravi Singh <ravi.singh1@samsung.com>
Subject: [PATCH] psi: fix integer overflow on unsigned int multiply on 32 bit systems
Date: Mon, 13 Sep 2021 14:21:35 +0530	[thread overview]
Message-ID: <1631523095-8672-1-git-send-email-ravi.singh1@samsung.com> (raw)
In-Reply-To: <CGME20210913085226epcas5p2b516f0f591926c927faa9c60d211bf44@epcas5p2.samsung.com>

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>
---
 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-13  9:44 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 ` Ravi Singh [this message]
2021-11-04 16:55   ` Johannes Weiner
2021-11-04 23:11     ` Suren Baghdasaryan
     [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=1631523095-8672-1-git-send-email-ravi.singh1@samsung.com \
    --to=ravi.singh1@samsung.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=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

all inboxes | Powered by JetHome®