public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vdso: Define NSEC_PER_SEC as 64-bit to prevent overflow
@ 2025-08-05 16:21 Wake Liu
  2025-08-06  8:44 ` Thomas Gleixner
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Wake Liu @ 2025-08-05 16:21 UTC (permalink / raw)
  To: Andy Lutomirski, Thomas Gleixner, Vincenzo Frascino; +Cc: linux-kernel, wakel

The constant NSEC_PER_SEC (1,000,000,000) is defined as a long literal.
On 32-bit systems like arm32, where long is 32 bits, this value can
overflow when used in 64-bit calculations.

This can lead to incorrect time calculations within the VDSO.

To fix this, define NSEC_PER_SEC as a long long literal (1000000000LL),
ensuring it is treated as a 64-bit value on all architectures and
preventing potential overflows.

Signed-off-by: Wake Liu <wakel@google.com>
---
 include/vdso/time64.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/vdso/time64.h b/include/vdso/time64.h
index b40cfa2aa33c..07641b27d139 100644
--- a/include/vdso/time64.h
+++ b/include/vdso/time64.h
@@ -8,7 +8,7 @@
 #define NSEC_PER_USEC	1000L
 #define NSEC_PER_MSEC	1000000L
 #define USEC_PER_SEC	1000000L
-#define NSEC_PER_SEC	1000000000L
+#define NSEC_PER_SEC	1000000000LL
 #define PSEC_PER_SEC	1000000000000LL
 #define FSEC_PER_SEC	1000000000000000LL
 
-- 
2.50.1.565.gc32cd1483b-goog


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-01-07 23:19 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox