[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87wm7bbo3c.ffs@tglx>
Date: Sun, 10 Aug 2025 10:03:19 +0200
From: Thomas Gleixner <tglx@...utronix.de>
To: Wake Liu <wakel@...gle.com>
Cc: Andy Lutomirski <luto@...nel.org>, Vincenzo Frascino
<vincenzo.frascino@....com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] vdso: Define NSEC_PER_SEC as 64-bit to prevent overflow
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
Powered by blists - more mailing lists