Commit 29183a70 authored by John Stultz's avatar John Stultz Committed by Ingo Molnar
Browse files

ntp: Fixup adjtimex freq validation on 32-bit systems

Additional validation of adjtimex freq values to avoid
potential multiplication overflows were added in commit
5e5aeb43 (time: adjtimex: Validate the ADJ_FREQUENCY values)

Unfortunately the patch used LONG_MAX/MIN instead of
LLONG_MAX/MIN, which was fine on 64-bit systems, but being
much smaller on 32-bit systems caused false positives
resulting in most direct frequency adjustments to fail w/

ntpd only does direct frequency adjustments at startup, so
the issue was not as easily observed there, but other time
sync applications like ptpd and chrony were more effected by
the bug.

See bugs:

This patch changes the checks to use LLONG_MAX for
clarity, and additionally the checks are disabled
on 32-bit systems since LLONG_MAX/PPM_SCALE is always
larger then the 32-bit long freq value, so multiplication
overflows aren't possible there.
Reported-by: default avatarJosh Boyer <>
Reported-by: default avatarGeorge Joseph <>
Tested-by: default avatarGeorge Joseph <>
Signed-off-by: default avatarJohn Stultz <>
Signed-off-by: default avatarPeter Zijlstra (Intel) <>
Cc: <> # v3.19+
Cc: Linus Torvalds <>
Cc: Sasha Levin <>

[ Prettified the changelog and the comments a bit. ]
Signed-off-by: default avatarIngo Molnar <>
parent e07e0d4c
......@@ -633,10 +633,14 @@ int ntp_validate_timex(struct timex *txc)
if ((txc->modes & ADJ_SETOFFSET) && (!capable(CAP_SYS_TIME)))
return -EPERM;
if (txc->modes & ADJ_FREQUENCY) {
if (LONG_MIN / PPM_SCALE > txc->freq)
* Check for potential multiplication overflows that can
* only happen on 64-bit systems:
if ((txc->modes & ADJ_FREQUENCY) && (BITS_PER_LONG == 64)) {
if (LLONG_MIN / PPM_SCALE > txc->freq)
return -EINVAL;
if (LONG_MAX / PPM_SCALE < txc->freq)
if (LLONG_MAX / PPM_SCALE < txc->freq)
return -EINVAL;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment