All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Zeng Tao <prime.zeng@hisilicon.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Vincenzo Frascino <vincenzo.frascino@arm.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] time: Avoid undefined behaviour in timespec64_to_ns
Date: Tue, 1 Sep 2020 14:46:52 +0200	[thread overview]
Message-ID: <CAK8P3a1SJEEJ_U9Vai1jCyXYEH=qcsk+zaeo9sjzbB5qByPKDA@mail.gmail.com> (raw)
In-Reply-To: <1598952616-6416-1-git-send-email-prime.zeng@hisilicon.com>

On Tue, Sep 1, 2020 at 11:32 AM Zeng Tao <prime.zeng@hisilicon.com> wrote:
>
> Since commit bd40a175769d ("y2038: itimer: change implementation to timespec64")
> we have break the time clamping which handles the potential overflow.

Indeed, good catch!

And I broke it despite the comment telling me about the problem.

> In this patch, we fix it in the timespec64_to_ns because there is
> possiblity to cause the same undefined behaviour on overflow whenever
> the function is called.

I checked the most important callers of this function, and I agree
that truncating at the maximum would be sensible in most cases
here.

In timekeeping_init(), there is already a check for
timespec64_valid_settod() that limits it even further, but that
wouldn't make sense for most callers.

> Fixes: bd40a175769d ("y2038: itimer: change implementation to timespec64")

This one caused the regression, but if we add the check here, it
may be best to also add it in prior kernels that may have the same
bug in other callers of the same function. Maybe backport all the
way to stable kernels that first added timespec64?

Cc <stable@vger.kernel.org> # v3.17+

> Signed-off-by: Zeng Tao <prime.zeng@hisilicon.com>

Reviewed-by: Arnd Bergmann <arnd@arndb.de>

  reply	other threads:[~2020-09-01 12:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-01  9:30 [PATCH] time: Avoid undefined behaviour in timespec64_to_ns Zeng Tao
2020-09-01 12:46 ` Arnd Bergmann [this message]
2020-09-15 12:20   ` Zengtao (B)
2020-09-15 12:45     ` Arnd Bergmann
2020-09-17  2:43       ` Zengtao (B)
2020-10-26 10:51 ` [tip: timers/urgent] time: Prevent undefined behaviour in timespec64_to_ns() tip-bot2 for Zeng Tao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAK8P3a1SJEEJ_U9Vai1jCyXYEH=qcsk+zaeo9sjzbB5qByPKDA@mail.gmail.com' \
    --to=arnd@arndb.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=prime.zeng@hisilicon.com \
    --cc=tglx@linutronix.de \
    --cc=vincenzo.frascino@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.