From: John Stultz Date: Thu, 14 Apr 2016 16:25:14 +0000 (-0600) Subject: ntp: Fix ADJ_SETOFFSET being used w/ ADJ_NANO X-Git-Tag: firefly_0821_release~176^2~4^2~31^2~87 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=1db396648ca33eb92dd0ed5cc2ea2f58816eeb9a;p=firefly-linux-kernel-4.4.55.git ntp: Fix ADJ_SETOFFSET being used w/ ADJ_NANO [ Upstream commit dd4e17ab704269bce71402285f5e8b9ac24b1eff ] Recently, in commit 37cf4dc3370f I forgot to check if the timeval being passed was actually a timespec (as is signaled with ADJ_NANO). This resulted in that patch breaking ADJ_SETOFFSET users who set ADJ_NANO, by rejecting valid timespecs that were compared with valid timeval ranges. This patch addresses this by checking for the ADJ_NANO flag and using the timepsec check instead in that case. Reported-by: Harald Hoyer Reported-by: Kay Sievers Fixes: 37cf4dc3370f "time: Verify time values in adjtimex ADJ_SETOFFSET to avoid overflow" Signed-off-by: John Stultz Cc: Sasha Levin Cc: Richard Cochran Cc: Prarit Bhargava Cc: David Herrmann Link: http://lkml.kernel.org/r/1453417415-19110-2-git-send-email-john.stultz@linaro.org Signed-off-by: Thomas Gleixner Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index d7654e2f902c..ab861771e37f 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -679,8 +679,18 @@ int ntp_validate_timex(struct timex *txc) if (!capable(CAP_SYS_TIME)) return -EPERM; - if (!timeval_inject_offset_valid(&txc->time)) - return -EINVAL; + if (txc->modes & ADJ_NANO) { + struct timespec ts; + + ts.tv_sec = txc->time.tv_sec; + ts.tv_nsec = txc->time.tv_usec; + if (!timespec_inject_offset_valid(&ts)) + return -EINVAL; + + } else { + if (!timeval_inject_offset_valid(&txc->time)) + return -EINVAL; + } } /*