linux/kernel/time
Justin Stitt 3f16bc776b ntp: Safeguard against time_constant overflow
commit 06c03c8edc upstream.

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 eea83d896e ("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: eea83d896e ("ntp: NTP4 user space bits update")
Signed-off-by: Justin Stitt <justinstitt@google.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Miroslav Lichvar <mlichvar@redhat.com>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/20240517-b4-sio-ntp-c-v2-1-f3a80096f36f@google.com
Closes: https://github.com/KSPP/linux/issues/352
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-08-19 05:33:52 +02:00
..
alarmtimer.c alarmtimer: Prevent starvation by small intervals and SIG_IGN 2023-02-25 11:53:26 +01:00
clockevents.c tick: Remove outgoing CPU from broadcast masks 2019-03-23 18:26:43 +01:00
clocksource.c clocksource: Retry clock read if long delays detected 2021-07-14 16:53:18 +02:00
hrtimer.c hrtimer: Report offline hrtimer enqueue 2024-02-23 08:25:08 +01:00
itimer.c time: Prevent undefined behaviour in timespec64_to_ns() 2020-11-18 19:20:15 +01:00
jiffies.c timekeeping: Split jiffies seqlock 2023-05-17 11:35:39 +02:00
Kconfig treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
Makefile timekeeping: Provide a generic update_vsyscall() implementation 2019-06-22 21:21:06 +02:00
ntp_internal.h ntp: Audit NTP parameters adjustment 2019-04-15 18:14:01 -04:00
ntp.c ntp: Safeguard against time_constant overflow 2024-08-19 05:33:52 +02:00
posix-clock.c ptp: fix the race between the release of ptp_clock and cdev 2020-01-04 19:18:48 +01:00
posix-cpu-timers.c Revert "posix-cpu-timers: Force next expiration recalc after itimer reset" 2021-09-16 12:56:13 +02:00
posix-stubs.c timers: Prevent union confusion from unexpected restart_syscall() 2023-03-11 16:43:54 +01:00
posix-timers.c posix-timers: Ensure timer ID search-loop limit is valid 2023-07-27 08:37:42 +02:00
posix-timers.h posix-timers: Use a callback for cancel synchronization on PREEMPT_RT 2019-08-20 22:05:46 +02:00
sched_clock.c time/sched_clock: Expire timer in hardirq context 2020-04-17 10:50:02 +02:00
test_udelay.c time/debug: Remove license boilerplate 2018-11-23 11:51:21 +01:00
tick-broadcast-hrtimer.c tick: broadcast-hrtimer: Fix a race in bc_set_next 2019-09-27 14:45:55 +02:00
tick-broadcast.c tick/broadcast: Move per CPU pointer access into the atomic section 2024-08-19 05:33:51 +02:00
tick-common.c tick/nohz_full: Don't abuse smp_call_function_single() in tick_setup_device() 2024-07-05 09:08:19 +02:00
tick-internal.h tick: Get rid of tick_period 2023-05-17 11:35:40 +02:00
tick-oneshot.c hrtimers/tick/clockevents: Remove sloppy license references 2018-11-23 11:51:21 +01:00
tick-sched.c tick/sched: Preserve number of idle sleeps across CPU hotplug events 2024-02-23 08:24:53 +01:00
tick-sched.h tick/sched: Update tick_sched struct documentation 2019-03-24 20:29:32 +01:00
time.c time: Zero the upper 32-bits in __kernel_timespec on 32-bit 2019-12-13 08:42:18 +01:00
timeconst.bc time: Add SPDX license identifiers 2018-11-23 11:51:20 +01:00
timeconv.c time: Add SPDX license identifiers 2018-11-23 11:51:20 +01:00
timecounter.c time: Remove license boilerplate 2018-11-23 11:51:21 +01:00
timekeeping_debug.c timekeeping/debug: No need to check return value of debugfs_create functions 2019-01-29 20:08:41 +01:00
timekeeping_internal.h
timekeeping.c timekeeping: Fix cross-timestamp interpolation for non-x86 2024-03-26 18:22:14 -04:00
timekeeping.h timekeeping: Split jiffies seqlock 2023-05-17 11:35:39 +02:00
timer_list.c timer_list: Guard procfs specific code 2019-06-23 00:08:52 +02:00
timer.c timers: Rename del_timer_sync() to timer_delete_sync() 2024-04-13 12:51:21 +02:00
vsyscall.c lib/vdso: Update coarse timekeeper unconditionally 2020-03-05 16:43:49 +01:00