Re: [RFC PATCH] ntp: Avoid undefined behaviour in second_overflow()

From: Miroslav Lichvar
Date: Wed Mar 06 2019 - 04:54:47 EST


On Tue, Mar 05, 2019 at 05:42:25PM -0800, John Stultz wrote:
> > --- a/kernel/time/ntp.c
> > +++ b/kernel/time/ntp.c
> > @@ -677,6 +677,8 @@ static inline void process_adjtimex_modes(const struct timex *txc, s32 *time_tai
> >
> > if (txc->modes & ADJ_MAXERROR)
> > time_maxerror = txc->maxerror;
> > + if (time_maxerror > NTP_PHASE_LIMIT)
> > + time_maxerror = NTP_PHASE_LIMIT;
>
> This looks sane to me.
> Acked-by: John Stultz <john.stultz@xxxxxxxxxx>
>
> Though it makes me wonder a bit more about the sanity checking on the
> other parameters passed via adjtimex(), tick_usec for instance looks
> like it could be similarly problematic.

The tick length is checked earlier in timekeeping_validate_timex(), so
that should be ok.

What I'd like to see clamped is the system time itself. ktime_t
overflows on Apr 11 2262. clock_settime() and adjtimex(ADJ_SETOFFSET)
can set the time close to the overflow and let everything break.

Boot a VM and try this:

# date -s 'Apr 11 23:47:15 UTC 2262'

There was a patch submitted couple years ago that prevented overflows
in 32-bit time_t and ktime_t.

http://lkml.iu.edu/hypermail/linux/kernel/1510.0/04719.html

--
Miroslav Lichvar