linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Stultz <john.stultz@linaro.org>
To: lkml <linux-kernel@vger.kernel.org>
Cc: John Stultz <john.stultz@linaro.org>,
	Sasha Levin <sasha.levin@oracle.com>,
	Richard Cochran <richardcochran@gmail.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Prarit Bhargava <prarit@redhat.com>,
	Harald Hoyer <harald@redhat.com>, Kay Sievers <kay@vrfy.org>,
	David Herrmann <dh.herrmann@gmail.com>
Subject: [PATCH 1/2] ntp: Fix ADJ_SETOFFSET being used w/ ADJ_NANO
Date: Thu, 21 Jan 2016 15:03:34 -0800	[thread overview]
Message-ID: <1453417415-19110-2-git-send-email-john.stultz@linaro.org> (raw)
In-Reply-To: <1453417415-19110-1-git-send-email-john.stultz@linaro.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 <sasha.levin@oracle.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Harald Hoyer <harald@redhat.com>
Cc: Kay Sievers <kay@vrfy.org>
Cc: David Herrmann <dh.herrmann@gmail.com>
Reported-by: Harald Hoyer <harald@redhat.com>
Reported-by: Kay Sievers <kay@vrfy.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 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

  reply	other threads:[~2016-01-21 23:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-21 23:03 [PATCH 0/2] Fix for ADJ_SETOFFSET w/ ADJ_NANO John Stultz
2016-01-21 23:03 ` John Stultz [this message]
2016-01-22 11:06   ` [PATCH 1/2] ntp: Fix ADJ_SETOFFSET being used " David Herrmann
2016-01-22 11:06   ` [tip:timers/urgent] " tip-bot for John Stultz
2016-01-21 23:03 ` [PATCH 2/2] kselftests: timers: Add adjtimex SETOFFSET validity tests John Stultz
2016-01-26 15:39   ` [tip:timers/urgent] " tip-bot for John Stultz
2016-01-21 23:16 ` [PATCH 0/2] Fix for ADJ_SETOFFSET w/ ADJ_NANO Shuah Khan
2016-01-22  7:54   ` Thomas Gleixner
2016-01-22 14:56     ` Shuah Khan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1453417415-19110-2-git-send-email-john.stultz@linaro.org \
    --to=john.stultz@linaro.org \
    --cc=dh.herrmann@gmail.com \
    --cc=harald@redhat.com \
    --cc=kay@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=prarit@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=sasha.levin@oracle.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).