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: Sasha Levin <sasha.levin@oracle.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@kernel.org>, stable <stable@vger.kernel.org>,
	Andy Lutomirski <luto@amacapital.net>,
	John Stultz <john.stultz@linaro.org>
Subject: [PATCH 2/2] time: adjtimex: Validate the ADJ_FREQUENCY values
Date: Wed,  7 Jan 2015 10:12:20 -0800	[thread overview]
Message-ID: <1420654340-3009-3-git-send-email-john.stultz@linaro.org> (raw)
In-Reply-To: <1420654340-3009-1-git-send-email-john.stultz@linaro.org>

From: Sasha Levin <sasha.levin@oracle.com>

Verify that the frequency value from userspace is valid and makes sense.

Unverified values can cause overflows later on.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: stable <stable@vger.kernel.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
[jstultz: Fix up bug for negative values and drop redunent cap check]
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 kernel/time/ntp.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 87a346f..28bf91c 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -633,6 +633,13 @@ 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)
+			return -EINVAL;
+		if (LONG_MAX / PPM_SCALE < txc->freq)
+			return -EINVAL;
+	}
+
 	return 0;
 }
 
-- 
1.9.1


  parent reply	other threads:[~2015-01-07 18:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-07 18:12 [PATCH v2 0/2] time: tip/timers/urgent: Validate potential mult overflows John Stultz
2015-01-07 18:12 ` [PATCH 1/2] time: settimeofday: Validate the values of tv from user John Stultz
2015-01-07 18:28   ` Greg KH
2015-01-07 19:02     ` John Stultz
2015-01-07 19:04       ` Sasha Levin
2015-01-07 19:09       ` Greg KH
2015-01-07 18:12 ` John Stultz [this message]
2015-01-07 18:28   ` [PATCH 2/2] time: adjtimex: Validate the ADJ_FREQUENCY values Greg KH
2015-01-14 18:33 ` [PATCH v2 0/2] time: tip/timers/urgent: Validate potential mult overflows John Stultz
2015-01-22 11:27   ` Thomas Gleixner
  -- strict thread matches above, loose matches on Subject: below --
2015-01-02 19:51 [PATCH " John Stultz
2015-01-02 19:51 ` [PATCH 2/2] time: adjtimex: Validate the ADJ_FREQUENCY values John Stultz

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=1420654340-3009-3-git-send-email-john.stultz@linaro.org \
    --to=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mingo@kernel.org \
    --cc=sasha.levin@oracle.com \
    --cc=stable@vger.kernel.org \
    --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).