[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.DEB.2.21.1911141457120.2507@nanos.tec.linutronix.de>
Date: Thu, 14 Nov 2019 15:04:51 +0100 (CET)
From: Thomas Gleixner <tglx@...utronix.de>
To: Arnd Bergmann <arnd@...db.de>
cc: y2038 Mailman List <y2038@...ts.linaro.org>,
John Stultz <john.stultz@...aro.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
Stephen Boyd <sboyd@...nel.org>,
David Howells <dhowells@...hat.com>,
Al Viro <viro@...iv.linux.org.uk>,
Deepa Dinamani <deepa.kernel@...il.com>,
Christian Brauner <christian@...uner.io>,
Jens Axboe <axboe@...nel.dk>, Ingo Molnar <mingo@...nel.org>,
Corey Minyard <cminyard@...sta.com>,
zhengbin <zhengbin13@...wei.com>,
Li RongQing <lirongqing@...du.com>,
Linux API <linux-api@...r.kernel.org>
Subject: Re: [PATCH 17/23] y2038: time: avoid timespec usage in
settimeofday()
On Thu, 14 Nov 2019, Arnd Bergmann wrote:
> On Wed, Nov 13, 2019 at 10:53 PM Thomas Gleixner <tglx@...utronix.de> wrote:
> >
> > On Fri, 8 Nov 2019, Arnd Bergmann wrote:
> > > -SYSCALL_DEFINE2(settimeofday, struct timeval __user *, tv,
> > > +SYSCALL_DEFINE2(settimeofday, struct __kernel_old_timeval __user *, tv,
> > > struct timezone __user *, tz)
> > > {
> > > struct timespec64 new_ts;
> > > - struct timeval user_tv;
> > > struct timezone new_tz;
> > >
> > > if (tv) {
> > > - if (copy_from_user(&user_tv, tv, sizeof(*tv)))
> > > + if (get_user(new_ts.tv_sec, &tv->tv_sec) ||
> > > + get_user(new_ts.tv_nsec, &tv->tv_usec))
> > > return -EFAULT;
> >
> > How is that supposed to be correct on a 32bit kernel?
>
> I don't see the problem you are referring to. This should behave the
> same way on a 32-bit kernel and on a 64-bit kernel, sign-extending
> the tv_sec field, and copying the user tv_usec field into the
> kernel tv_nsec, to be multiplied by 1000 a few lines later.
You're right. Tired brain failed to see the implicit sign extension in
get_user().
> Am I missing something?
No.
> > > - if (!timeval_valid(&user_tv))
> > > + if (tv->tv_usec > USEC_PER_SEC)
> > > return -EINVAL;
> >
> > That's incomplete:
> >
> > static inline bool timeval_valid(const struct timeval *tv)
> > {
> > /* Dates before 1970 are bogus */
> > if (tv->tv_sec < 0)
> > return false;
> >
> > /* Can't have more microseconds then a second */
> > if (tv->tv_usec < 0 || tv->tv_usec >= USEC_PER_SEC)
> > return false;
> >
> > return true;
> > }
>
> My idea was to not duplicate the range check that is done
> in do_sys_settimeofday64() and again in do_settimeofday64:
>
> if (!timespec64_valid_settod(ts))
> return -EINVAL;
>
> The only check we should need in addition to this is to ensure
> that passing an invalid tv_usec number doesn't become an
> unexpectedly valid tv_nsec after the multiplication.
Right, but please add a proper comment as you/we are going to scratch heads
4 weeks from now when staring at that check and wondering why it is
incomplete.
Thanks,
tglx
Powered by blists - more mailing lists