[PATCH] lib/vdso: guard clockid before building u32 bitmask

From: Sun Jian

Date: Wed Jan 14 2026 - 03:45:40 EST


__cvdso_clock_gettime_common() and __cvdso_clock_getres_common() build a
u32 bitmask from clockid_t using "1U << clock". This requires the shift
amount to be < 32, otherwise leading to undefined behaviour.

Add a guard to reject out-of-range clockids before building the bitmask.
This avoids undefined shifts and silences sparse "shift too big" warnings.

No functional change intended.

Signed-off-by: Sun Jian <sun.jian.kdev@xxxxxxxxx>
---
lib/vdso/gettimeofday.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/lib/vdso/gettimeofday.c b/lib/vdso/gettimeofday.c
index 95df0153f05a..eee30f2bc6c6 100644
--- a/lib/vdso/gettimeofday.c
+++ b/lib/vdso/gettimeofday.c
@@ -298,6 +298,9 @@ __cvdso_clock_gettime_common(const struct vdso_time_data *vd, clockid_t clock,
* Convert the clockid to a bitmask and use it to check which
* clocks are handled in the VDSO directly.
*/
+ if ((u32)clock >= 32)
+ return false;
+
msk = 1U << clock;
if (likely(msk & VDSO_HRES))
vc = &vc[CS_HRES_COARSE];
@@ -440,6 +443,9 @@ bool __cvdso_clock_getres_common(const struct vdso_time_data *vd, clockid_t cloc
* Convert the clockid to a bitmask and use it to check which
* clocks are handled in the VDSO directly.
*/
+ if ((u32)clock >= 32)
+ return false;
+
msk = 1U << clock;
if (msk & (VDSO_HRES | VDSO_RAW)) {
/*
--
2.43.0