From: Sasha Levin <sasha.levin@oracle.com>
To: john.stultz@linaro.org, tglx@linutronix.de
Cc: linux-kernel@vger.kernel.org, Sasha Levin <sasha.levin@oracle.com>
Subject: [PATCH] ntp: verify offset doesn't overflow in ntp_update_offset
Date: Thu, 3 Dec 2015 15:46:48 -0500 [thread overview]
Message-ID: <1449175608-1146-1-git-send-email-sasha.levin@oracle.com> (raw)
We need to make sure that the offset is valid before manipulating it,
otherwise it might overflow on the multiplication.
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
---
kernel/time/ntp.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 149cc80..36616c3 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -297,6 +297,9 @@ static void ntp_update_offset(long offset)
if (!(time_status & STA_PLL))
return;
+ /* Make sure the multiplication below won't overflow */
+ offset = clamp(offset, -MAXPHASE, MAXPHASE);
+
if (!(time_status & STA_NANO))
offset *= NSEC_PER_USEC;
@@ -304,8 +307,7 @@ static void ntp_update_offset(long offset)
* Scale the phase adjustment and
* clamp to the operating range.
*/
- offset = min(offset, MAXPHASE);
- offset = max(offset, -MAXPHASE);
+ offset = clamp(offset, -MAXPHASE, MAXPHASE);
/*
* Select how the frequency is to be controlled
--
1.7.10.4
next reply other threads:[~2015-12-03 20:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-03 20:46 Sasha Levin [this message]
2015-12-04 20:26 ` [PATCH] ntp: verify offset doesn't overflow in ntp_update_offset John Stultz
2015-12-08 0:02 ` John Stultz
2015-12-08 0:22 ` Sasha Levin
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=1449175608-1146-1-git-send-email-sasha.levin@oracle.com \
--to=sasha.levin@oracle.com \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
/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).