stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ntp: Fixup adjtimex freq validation on 32bit systems
@ 2015-02-03 18:57 John Stultz
  2015-02-03 19:45 ` Richard Cochran
  0 siblings, 1 reply; 3+ messages in thread
From: John Stultz @ 2015-02-03 18:57 UTC (permalink / raw)
  To: lkml; +Cc: John Stultz, Thomas Gleixner, Ingo Molnar, Sasha Levin, stable

For tip/timers/urgent.

Additional validation of adjtimex freq values to avoid
potential multiplication overflows were added in commit
5e5aeb4367b (time: adjtimex: Validate the ADJ_FREQUENCY values)

Unfortunately the patch used LONG_MAX/MIN instead of
LLONG_MAX/MIN, which was fine on 64bit systems, but being
much smaller on 32bit systems caused false positives
resulting in most direct frequency adjustments to fail w/
EINVAL.

ntpd only does direct frequency adjustments at startup, so
the issue was not as easily observed there, but other time
sync applications like ptpd and chrony were more effected by
the bug.

See bugs:
https://bugzilla.kernel.org/show_bug.cgi?id=92481
https://bugzilla.redhat.com/show_bug.cgi?id=1188074

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Sasha Levin <sasha.levin@oracle.com>
Cc: stable@vger.kernel.org
Reported-by: Josh Boyer <jwboyer@fedoraproject.org>
Reported-by: George Joseph <george.joseph@fairview5.com>
Tested-by: George Joseph <george.joseph@fairview5.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
One note:
0day kbuild bot complains about
>> kernel/time/ntp.c:637: warning: comparison is always false due to limited range of data type
>> kernel/time/ntp.c:639: warning: comparison is always false due to limited range of data type

We could fix this via adding an extra (BITS_PER_LONG == 64)
case before we check these to avoid it, but that seemed a
bit too ugly to me. Thoughts?

 kernel/time/ntp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 28bf91c..242774d 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -634,9 +634,9 @@ int ntp_validate_timex(struct timex *txc)
 		return -EPERM;
 
 	if (txc->modes & ADJ_FREQUENCY) {
-		if (LONG_MIN / PPM_SCALE > txc->freq)
+		if (LLONG_MIN / PPM_SCALE > txc->freq)
 			return -EINVAL;
-		if (LONG_MAX / PPM_SCALE < txc->freq)
+		if (LLONG_MAX / PPM_SCALE < txc->freq)
 			return -EINVAL;
 	}
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ntp: Fixup adjtimex freq validation on 32bit systems
  2015-02-03 18:57 [PATCH] ntp: Fixup adjtimex freq validation on 32bit systems John Stultz
@ 2015-02-03 19:45 ` Richard Cochran
  2015-02-04  0:38   ` [PATCH v2] " John Stultz
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Cochran @ 2015-02-03 19:45 UTC (permalink / raw)
  To: John Stultz; +Cc: lkml, Thomas Gleixner, Ingo Molnar, Sasha Levin, stable

On Tue, Feb 03, 2015 at 10:57:38AM -0800, John Stultz wrote:
> Unfortunately the patch used LONG_MAX/MIN instead of
> LLONG_MAX/MIN, which was fine on 64bit systems, but being
> much smaller on 32bit systems caused false positives
> resulting in most direct frequency adjustments to fail w/
> EINVAL.

...

> One note:
> 0day kbuild bot complains about
> >> kernel/time/ntp.c:637: warning: comparison is always false due to limited range of data type
> >> kernel/time/ntp.c:639: warning: comparison is always false due to limited range of data type
> 
> We could fix this via adding an extra (BITS_PER_LONG == 64)
> case before we check these to avoid it, but that seemed a
> bit too ugly to me. Thoughts?

So the check is 64 bit only?  Might as well mark it like that
explicitly to avoid needless head scratching of 32 bit people.

Thanks,
Richard

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2] ntp: Fixup adjtimex freq validation on 32bit systems
  2015-02-03 19:45 ` Richard Cochran
@ 2015-02-04  0:38   ` John Stultz
  0 siblings, 0 replies; 3+ messages in thread
From: John Stultz @ 2015-02-04  0:38 UTC (permalink / raw)
  To: lkml
  Cc: John Stultz, Thomas Gleixner, Ingo Molnar, Sasha Levin,
	Richard Cochran, stable

For tip/timers/urgent.

Additional validation of adjtimex freq values to avoid
potential multiplication overflows were added in commit
5e5aeb4367b (time: adjtimex: Validate the ADJ_FREQUENCY values)

Unfortunately the patch used LONG_MAX/MIN instead of
LLONG_MAX/MIN, which was fine on 64bit systems, but being
much smaller on 32bit systems caused false positives
resulting in most direct frequency adjustments to fail w/
EINVAL.

ntpd only does direct frequency adjustments at startup, so
the issue was not as easily observed there, but other time
sync applications like ptpd and chrony were more effected by
the bug.

See bugs:
https://bugzilla.kernel.org/show_bug.cgi?id=92481
https://bugzilla.redhat.com/show_bug.cgi?id=1188074

This patch changes the checks to use LLONG_MAX for
clarity, and additionally the checks are disabled
on 32bit systems since LLONG_MAX/PPM_SCALE is always
larger then the 32bit long freq value, so mult
overflows aren't possible there.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Sasha Levin <sasha.levin@oracle.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: stable@vger.kernel.org
Reported-by: Josh Boyer <jwboyer@fedoraproject.org>
Reported-by: George Joseph <george.joseph@fairview5.com>
Tested-by: George Joseph <george.joseph@fairview5.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
v2: Included the BITS_PER_LONG check to disable
the check on 32bit systems, since it generates
build warnings in some settings.

 kernel/time/ntp.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 28bf91c..6824ef9 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -633,10 +633,14 @@ 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)
+	/*
+	 * Check for potential mult overflows that can
+	 * only happen on 64bit systems.
+	 */
+	if ((txc->modes & ADJ_FREQUENCY) && (BITS_PER_LONG == 64)) {
+		if (LLONG_MIN / PPM_SCALE > txc->freq)
 			return -EINVAL;
-		if (LONG_MAX / PPM_SCALE < txc->freq)
+		if (LLONG_MAX / PPM_SCALE < txc->freq)
 			return -EINVAL;
 	}
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-02-04  0:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-03 18:57 [PATCH] ntp: Fixup adjtimex freq validation on 32bit systems John Stultz
2015-02-03 19:45 ` Richard Cochran
2015-02-04  0:38   ` [PATCH v2] " John Stultz

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).