time/ntp fix
Linus,
Please pull the latest timers-urgent-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git timers-urgent-for-linus
# HEAD: 29183a70b0b828500816bd794b3fe192fce89f73 ntp: Fixup adjtimex freq validation on 32-bit systems
An adjtimex interface regression fix for 32-bit systems.
Thanks,
Ingo
------------------>
John Stultz (1):
ntp: Fixup adjtimex freq validation on 32-bit systems
kernel/time/ntp.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
kernel/time/ntp.c +7 -3
@@ -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 multiplication overflows that can +* only happen on 64-bit 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 ; }
Quoted 27 lines · Ingo Molnar
Linus,
Please pull the latest timers-urgent-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.gittimers-urgent-for-linus# HEAD:
29183a70b0b828500816bd794b3fe192fce89f73ntp: Fixup adjtimex freq validation on 32-bit systemsAn adjtimex interface regression fix for 32-bit systems.
Thanks,
Ingo
------------------>
John Stultz (1):
ntp: Fixup adjtimex freq validation on 32-bit systemskernel/time/ntp.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)kernel/time/ntp.c +0
-0
kernel/time/ntp.c int ntp_validate_timex(struct timex *txc) · line 638
Quoted 8 lines
kernel/time/ntp.c +3
-2@@ -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 multiplication overflows that can +* only happen on 64-bit systems:
Typo ?
Quoted 14 lines
kernel/time/ntp.c +4
-2+*/ +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 ; } --To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 3 lines · Ingo Molnar
John Stultz (1):
ntp: Fixup adjtimex freq validation on 32-bit systems
This is confusing. 32-bit?
kernel/time/ntp.c int ntp_validate_timex(struct timex *txc) · line 638
Quoted 3 lines
kernel/time/ntp.c +3
-0+/* +* Check for potential multiplication overflows that can +* only happen on 64-bit systems:
64-bit?
Quoted 1 line
+ if ((
txc->modes&ADJ_FREQUENCY) && (BITS_PER_LONG== 64)) {
Hmm. The code clearly says "&& (BITS_PER_LONG == 64)"
But:
kernel/time/ntp.c int ntp_validate_timex(struct timex *txc) · line 644
Quoted 5 lines
kernel/time/ntp.c +2
-1+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 ;
The difference between LONG_MAX and LLONG_MAX only matters if BITS_PER_LONG would be 32.
So the changes are confusing to begin with and the commit log description doesn't match them anyway.
I'm not pulling this without clarifications.
Linus
Quoted 6 lines · Linus Torvalds
Quoted 3 lines · Ingo Molnar
John Stultz (1):
ntp: Fixup adjtimex freq validation on 32-bit systemsThis is confusing. 32-bit?
Right, so the check that was added in a previous commit is really only a concern for 64bit systems, but was applied to both 32 and 64bit systems, which results in breaking 32bit systems.
Thus the "fix" here is to make the check only apply to 64bit systems.
Quoted 12 lines
kernel/time/ntp.c int ntp_validate_timex(struct timex *txc) · line 638
Quoted 3 lines
kernel/time/ntp.c +3
-0+/* +* Check for potential multiplication overflows that can +* only happen on 64-bit systems: 64-bit?
Quoted 1 line
+ if ((
txc->modes&ADJ_FREQUENCY) && (BITS_PER_LONG== 64)) {Hmm. The code clearly says "&& (
BITS_PER_LONG== 64)"But:
Quoted 8 lines
kernel/time/ntp.c int ntp_validate_timex(struct timex *txc) · line 644
Quoted 5 lines
kernel/time/ntp.c +2
-1+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 ;The difference between
LONG_MAXandLLONG_MAXonly matters ifBITS_PER_LONGwould be 32.
Right. So v1 of this fix just changed the LONG_MIX/MAX to be LLONG_MIN/MAX. This resolves the issue, but with some compiler checks we get warnings since LLONG_MIN/MAX is always smaller/larger then a 32bit value. Thus the extra BITS_PER_LONG check (which I think is a bit ugly, but I didn't get any better suggestions) was added to avoid the build warnings as well.
So the fix is somewhat redundant, but I do think the LLONG specifier is more exact.
Quoted 4 lines
So the changes are confusing to begin with and the commit log description doesn't match them anyway.
I'm not pulling this without clarifications.
Is the above clarification sufficient? Or would you like me to reword the commit message as well?
thanks
-john
Quoted 3 lines · John Stultz
Is the above clarification sufficient? Or would you like me to reword the commit message as well?
It's ok. And I'll add it to the merge message so that it's mentioned somewhere at least.
Thanks,
Linus
Quoted 9 lines · John Stultz
Quoted 6 lines · Linus Torvalds
Quoted 3 lines · Ingo Molnar
John Stultz (1):
ntp: Fixup adjtimex freq validation on 32-bit systemsThis is confusing. 32-bit?
Quoted 7 lines
Right, so the check that was added in a previous commit is really only a concern for 64bit systems, but was applied to both 32 and 64bit systems, which results in breaking 32bit systems.
Thus the "fix" here is to make the check only apply to 64bit systems.
Yeah, perhaps a better commit title would have been to write:
time/ntp: Fix adjtimex freq validation code build warning on 32-bit systems
To make it clear that the problem fixed is a 32-bit warning, and that the fix for that is to only check on 64-bit systems.
I agreed with your BITS_PER_LONG check when I reviewed your patch, people usually do an ugly #ifdef, I think this in line check form is nicer.
Thanks,
Ingo
Hi Ingo,
Quoted 24 lines · Ingo Molnar
Quoted 9 lines · John Stultz
Quoted 6 lines · Linus Torvalds
Quoted 3 lines · Ingo Molnar
John Stultz (1):
ntp: Fixup adjtimex freq validation on 32-bit systemsThis is confusing. 32-bit?
Quoted 7 lines
Right, so the check that was added in a previous commit is really only a concern for 64bit systems, but was applied to both 32 and 64bit systems, which results in breaking 32bit systems.
Thus the "fix" here is to make the check only apply to 64bit systems.
Yeah, perhaps a better commit title would have been to write:
time/ntp: Fix adjtimex freq validation code build warning on 32-bit systems
Quoted 7 lines
To make it clear that the problem fixed is a 32-bit warning, and that the fix for that is to only check on 64-bit systems.
I agreed with your
BITS_PER_LONGcheck when I reviewed your patch, people usually do an ugly #ifdef, I think this in line check form is nicer.
Unfortunately it doesn't help with all compiler versions. With gcc 4.1.2 for m68k:
kernel/time/ntp.c: In function ‘ntp_validate_timex’:kernel/time/ntp.c:641: warning: comparison is always false due to limited range of data typekernel/time/ntp.c:643: warning: comparison is always false due to limited range of data type
Gcc 4.6.3 and 4.9.0 are OK (for m68k).
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds