Skip to content

Commit 06c03c8

Browse files
JustinStittKAGA-KOKO
authored andcommitted
ntp: Safeguard against time_constant overflow
Using syzkaller with the recently reintroduced signed integer overflow sanitizer produces this UBSAN report: UBSAN: signed-integer-overflow in ../kernel/time/ntp.c:738:18 9223372036854775806 + 4 cannot be represented in type 'long' Call Trace: handle_overflow+0x171/0x1b0 __do_adjtimex+0x1236/0x1440 do_adjtimex+0x2be/0x740 The user supplied time_constant value is incremented by four and then clamped to the operating range. Before commit eea83d8 ("ntp: NTP4 user space bits update") the user supplied value was sanity checked to be in the operating range. That change removed the sanity check and relied on clamping after incrementing which does not work correctly when the user supplied value is in the overflow zone of the '+ 4' operation. The operation requires CAP_SYS_TIME and the side effect of the overflow is NTP getting out of sync. Similar to the fixups for time_maxerror and time_esterror, clamp the user space supplied value to the operating range. [ tglx: Switch to clamping ] Fixes: eea83d8 ("ntp: NTP4 user space bits update") Signed-off-by: Justin Stitt <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: Miroslav Lichvar <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/all/[email protected] Closes: KSPP/linux#352
1 parent 87d571d commit 06c03c8

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

kernel/time/ntp.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -733,11 +733,10 @@ static inline void process_adjtimex_modes(const struct __kernel_timex *txc,
733733
time_esterror = clamp(txc->esterror, 0, NTP_PHASE_LIMIT);
734734

735735
if (txc->modes & ADJ_TIMECONST) {
736-
time_constant = txc->constant;
736+
time_constant = clamp(txc->constant, 0, MAXTC);
737737
if (!(time_status & STA_NANO))
738738
time_constant += 4;
739-
time_constant = min(time_constant, (long)MAXTC);
740-
time_constant = max(time_constant, 0l);
739+
time_constant = clamp(time_constant, 0, MAXTC);
741740
}
742741

743742
if (txc->modes & ADJ_TAI &&

0 commit comments

Comments
 (0)