Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 20dcda8

Browse files
johnstultz-workgregkh
authored andcommitted
ntp: Fixup adjtimex freq validation on 32-bit systems
commit 29183a7 upstream. Additional validation of adjtimex freq values to avoid potential multiplication overflows were added in commit 5e5aeb4 (time: adjtimex: Validate the ADJ_FREQUENCY values) Unfortunately the patch used LONG_MAX/MIN instead of LLONG_MAX/MIN, which was fine on 64-bit systems, but being much smaller on 32-bit 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 32-bit systems since LLONG_MAX/PPM_SCALE is always larger then the 32-bit long freq value, so multiplication overflows aren't possible there. Reported-by: Josh Boyer <[email protected]> Reported-by: George Joseph <[email protected]> Tested-by: George Joseph <[email protected]> Signed-off-by: John Stultz <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Sasha Levin <[email protected]> Link: http://lkml.kernel.org/r/[email protected] [ Prettified the changelog and the comments a bit. ] Signed-off-by: Ingo Molnar <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ab66a1f commit 20dcda8

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

kernel/time/ntp.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,10 +633,14 @@ int ntp_validate_timex(struct timex *txc)
633633
if ((txc->modes & ADJ_SETOFFSET) && (!capable(CAP_SYS_TIME)))
634634
return -EPERM;
635635

636-
if (txc->modes & ADJ_FREQUENCY) {
637-
if (LONG_MIN / PPM_SCALE > txc->freq)
636+
/*
637+
* Check for potential multiplication overflows that can
638+
* only happen on 64-bit systems:
639+
*/
640+
if ((txc->modes & ADJ_FREQUENCY) && (BITS_PER_LONG == 64)) {
641+
if (LLONG_MIN / PPM_SCALE > txc->freq)
638642
return -EINVAL;
639-
if (LONG_MAX / PPM_SCALE < txc->freq)
643+
if (LLONG_MAX / PPM_SCALE < txc->freq)
640644
return -EINVAL;
641645
}
642646

0 commit comments

Comments
 (0)