The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Wake Liu <wakel@google.com>
Cc: Andy Lutomirski <luto@kernel.org>,
	Vincenzo Frascino <vincenzo.frascino@arm.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] vdso: Define NSEC_PER_SEC as 64-bit to prevent overflow
Date: Sun, 10 Aug 2025 10:03:19 +0200	[thread overview]
Message-ID: <87wm7bbo3c.ffs@tglx> (raw)
In-Reply-To: <CAOcRiAFzN61FE=By1ANB3aK4PKVTBQAzrCcfoHfHwMX7Qn8wYA@mail.gmail.com>

On Sat, Aug 09 2025 at 17:49, Wake Liu wrote:

Please do not top post and trim your replies.

> CLOCK_REALTIME         ABSTIME PERIODIC timer fired early:       1 : [FAILED]
> Looks like there is some integer overflow on 32 bit builds in the
> timespec_sub function:
>
> long long timespec_sub(struct timespec a, struct timespec b)

That's in selftests and not in the kernel VDSO code.

Can you please be precise with your subject and changelog? You claimed:

 "This can lead to incorrect time calculations within the VDSO"

No, it can't not because the VDSO does not use it that way.

> {
> long long ret = NSEC_PER_SEC * b.tv_sec + b.tv_nsec;
>
> ret -= NSEC_PER_SEC * a.tv_sec + a.tv_nsec;
> return ret;
> }
>
> on 32 bit builds NSEC_PER_SEC and b.tv_sec are only 32 bit values
> which I'm guessing is causing the overflow.

Guessing is not a valid technical problem solving approach.

> NSEC_PER_SEC is defined as 1000000000L but if we change this to
> 1000000000LL then the test starts passing.

Yes, that function bogus on 32bit.

There are at least ten different ways to implement this function 32-bit
safe, but you picked the worst option of all, which breaks the kernel
build as you got told by 0-day.

I'm sure you can figure out how to ensure that the multiplication is
actually expanding to 64-bit or use some other approach to calculate
that delta.

And please make that an inline function and put it into a header file in
the timer selftest directory, and replace _all_ copies of it in the
various timer tests.

Thanks,

        tglx

  reply	other threads:[~2025-08-10  8:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-05 16:21 [PATCH] vdso: Define NSEC_PER_SEC as 64-bit to prevent overflow Wake Liu
2025-08-06  8:44 ` Thomas Gleixner
2025-08-06  8:55 ` Thomas Gleixner
2025-08-09  9:49   ` Wake Liu
2025-08-10  8:03     ` Thomas Gleixner [this message]
2025-08-10  8:28       ` Thomas Weißschuh
2025-09-15 19:19         ` [PATCH v2] selftests/timers: Consolidate and fix 32-bit overflow in timespec_sub Wake Liu
2025-09-21  7:49           ` Thomas Gleixner
2026-01-07 23:19             ` Carlos Llamas
2025-08-06 20:28 ` [PATCH] vdso: Define NSEC_PER_SEC as 64-bit to prevent overflow kernel test robot
2025-08-07  7:37 ` kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2025-08-05 16:20 Wake Liu

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=87wm7bbo3c.ffs@tglx \
    --to=tglx@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=vincenzo.frascino@arm.com \
    --cc=wakel@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox