aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSasha Levin <sasha.levin@oracle.com>2015-12-03 15:46:48 -0500
committerJohn Stultz <john.stultz@linaro.org>2015-12-11 01:41:05 -0500
commit52d189f1b38810b1b483d5bac2e4fa90b9afd372 (patch)
tree756d5bcadf6596e5256b4b9a40c4c7a259934740
parent3b44edaaa1fffccea7edc018dd807581c97a6aea (diff)
ntp: Verify offset doesn't overflow in ntp_update_offset
We need to make sure that the offset is valid before manipulating it, otherwise it might overflow on the multiplication. Cc: Sasha Levin <sasha.levin@oracle.com> Cc: Richard Cochran <richardcochran@gmail.com> Cc: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Sasha Levin <sasha.levin@oracle.com> [jstultz: Reworked one of the checks so it makes more sense] Signed-off-by: John Stultz <john.stultz@linaro.org>
-rw-r--r--kernel/time/ntp.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 149cc8086aea..125fc0342355 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -297,15 +297,17 @@ static void ntp_update_offset(long offset)
297 if (!(time_status & STA_PLL)) 297 if (!(time_status & STA_PLL))
298 return; 298 return;
299 299
300 if (!(time_status & STA_NANO)) 300 if (!(time_status & STA_NANO)) {
301 /* Make sure the multiplication below won't overflow */
302 offset = clamp(offset, -USEC_PER_SEC, USEC_PER_SEC);
301 offset *= NSEC_PER_USEC; 303 offset *= NSEC_PER_USEC;
304 }
302 305
303 /* 306 /*
304 * Scale the phase adjustment and 307 * Scale the phase adjustment and
305 * clamp to the operating range. 308 * clamp to the operating range.
306 */ 309 */
307 offset = min(offset, MAXPHASE); 310 offset = clamp(offset, -MAXPHASE, MAXPHASE);
308 offset = max(offset, -MAXPHASE);
309 311
310 /* 312 /*
311 * Select how the frequency is to be controlled 313 * Select how the frequency is to be controlled