Commit dca97d28 authored by Miroslav Lichvar's avatar Miroslav Lichvar Committed by Stefan Bader

ntp: Limit TAI-UTC offset

BugLink: https://bugs.launchpad.net/bugs/1840081

[ Upstream commit d897a4ab ]

Don't allow the TAI-UTC offset of the system clock to be set by adjtimex()
to a value larger than 100000 seconds.

This prevents an overflow in the conversion to int, prevents the CLOCK_TAI
clock from getting too far ahead of the CLOCK_REALTIME clock, and it is
still large enough to allow leap seconds to be inserted at the maximum rate
currently supported by the kernel (once per day) for the next ~270 years,
however unlikely it is that someone can survive a catastrophic event which
slowed down the rotation of the Earth so much.
Reported-by: default avatarWeikang shi <swkhack@gmail.com>
Signed-off-by: default avatarMiroslav Lichvar <mlichvar@redhat.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Stephen Boyd <sboyd@kernel.org>
Link: https://lkml.kernel.org/r/20190618154713.20929-1-mlichvar@redhat.comSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarConnor Kuehl <connor.kuehl@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent a9aa3e52
...@@ -39,6 +39,7 @@ static u64 tick_length_base; ...@@ -39,6 +39,7 @@ static u64 tick_length_base;
#define MAX_TICKADJ 500LL /* usecs */ #define MAX_TICKADJ 500LL /* usecs */
#define MAX_TICKADJ_SCALED \ #define MAX_TICKADJ_SCALED \
(((MAX_TICKADJ * NSEC_PER_USEC) << NTP_SCALE_SHIFT) / NTP_INTERVAL_FREQ) (((MAX_TICKADJ * NSEC_PER_USEC) << NTP_SCALE_SHIFT) / NTP_INTERVAL_FREQ)
#define MAX_TAI_OFFSET 100000
/* /*
* phase-lock loop variables * phase-lock loop variables
...@@ -633,7 +634,8 @@ static inline void process_adjtimex_modes(struct timex *txc, ...@@ -633,7 +634,8 @@ static inline void process_adjtimex_modes(struct timex *txc,
time_constant = max(time_constant, 0l); time_constant = max(time_constant, 0l);
} }
if (txc->modes & ADJ_TAI && txc->constant >= 0) if (txc->modes & ADJ_TAI &&
txc->constant >= 0 && txc->constant <= MAX_TAI_OFFSET)
*time_tai = txc->constant; *time_tai = txc->constant;
if (txc->modes & ADJ_OFFSET) if (txc->modes & ADJ_OFFSET)
......
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