Re: kernel/time/ntp.c: Possible off-by-one error in TAI range check?
From: Thomas Gleixner
Date: Tue Apr 16 2019 - 15:59:54 EST
On Mon, 15 Apr 2019, Miroslav Lichvar wrote:
> On Mon, Apr 15, 2019 at 10:09:43AM +0200, Thomas Gleixner wrote:
> > > On Mon, Apr 8, 2019 at 10:47 AM Ondrej Mosnacek <omosnace@xxxxxxxxxx> wrote:
> > > > Commit 153b5d054ac2 ("ntp: support for TAI") added a possibility to
> > > > change the TAI offset from userspace via adjtimex(2). The code checks
> > > > if the input value (txc->constant) is greater than 0 and if it is not,
> > > > then it doesn't modify the value. Ignoring the fact that this check
> > > > should probably be in timekeeping_validate_timex() and cause -EINVAL
> > > > to be returned when false, I find it strange that the check doesn't
> > > > allow to set the value to 0, which seems to be the default value...
> > > >
> > > > Was this behavior intended or should the code actually check for
> > > > txc->constant >= 0 instead of txc->constant > 0?
>
> I guess zero here means "unknown" and maybe the intention was to not
> allow setting the offset to an unknown value once it has been set to a
> valid value. The trouble is that after inserting a leap second the
> offset may change from zero to one.
>
> I think it should be changed to allow setting the offset to zero.
Can someone please send a patch with a coherent changelog?
Thanks,
tglx