From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752331AbcAUXD4 (ORCPT ); Thu, 21 Jan 2016 18:03:56 -0500 Received: from mail-pa0-f47.google.com ([209.85.220.47]:34484 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751919AbcAUXDl (ORCPT ); Thu, 21 Jan 2016 18:03:41 -0500 From: John Stultz To: lkml Cc: John Stultz , Sasha Levin , Richard Cochran , Thomas Gleixner , Prarit Bhargava , Harald Hoyer , Kay Sievers , David Herrmann Subject: [PATCH 1/2] ntp: Fix ADJ_SETOFFSET being used w/ ADJ_NANO Date: Thu, 21 Jan 2016 15:03:34 -0800 Message-Id: <1453417415-19110-2-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1453417415-19110-1-git-send-email-john.stultz@linaro.org> References: <1453417415-19110-1-git-send-email-john.stultz@linaro.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Recently, in commit 37cf4dc3370f ("time: Verify time values in adjtimex ADJ_SETOFFSET to avoid overflow") 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. Cc: Sasha Levin Cc: Richard Cochran Cc: Thomas Gleixner Cc: Prarit Bhargava Cc: Harald Hoyer Cc: Kay Sievers Cc: David Herrmann Reported-by: Harald Hoyer Reported-by: Kay Sievers Signed-off-by: John Stultz --- kernel/time/ntp.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 36f2ca0..6df8927 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -685,8 +685,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; + } } /* -- 1.9.1