From: Zhan Xusheng <zhanxusheng1024@gmail.com>
To: Thomas Gleixner <tglx@kernel.org>
Cc: "Thomas Weißschuh" <thomas.weissschuh@linutronix.de>,
"Yury Norov" <yury.norov@gmail.com>,
"Rasmus Villemoes" <linux@rasmusvillemoes.dk>,
"Andy Lutomirski" <luto@kernel.org>,
"Vincenzo Frascino" <vincenzo.frascino@arm.com>,
"David Laight" <david.laight.linux@gmail.com>,
linux-kernel@vger.kernel.org,
"Zhan Xusheng" <zhanxusheng@xiaomi.com>
Subject: [PATCH] vdso/gettimeofday: Assert that the clockid fits into the u32 bitmask
Date: Fri, 16 Oct 2026 23:32:12 +0800 [thread overview]
Message-ID: <20261016153212.2733798-1-zhanxusheng1024@gmail.com> (raw)
From: Zhan Xusheng <zhanxusheng@xiaomi.com>
__cvdso_clock_gettime_common() and __cvdso_clock_getres_common() turn the
clockid into a bitmask:
msk = 1U << clock;
The shift count stays in range because vdso_clockid_valid() rejects
anything above CLOCK_AUX_LAST, which is 23. Nothing records that, so
raising MAX_AUX_CLOCKS past 16 would take CLOCK_AUX_LAST to 32 and make
the shift undefined.
Assert it in vdso_clockid_valid(), which is where the bound comes from
and covers both conversion sites.
8 * sizeof(u32) rather than BITS_PER_TYPE(): the latter lives in
linux/bits.h, which lib/vdso/gettimeofday.c only reaches on
architectures whose asm/vdso/gettimeofday.h happens to pull it in.
MAX_AUX_CLOCKS=16 still builds, 17 trips the assert.
Suggested-by: Thomas Gleixner <tglx@kernel.org>
Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
---
Last patch of
https://lore.kernel.org/all/20261002153104.1347978-1-zhanxusheng@xiaomi.com/
("[PATCH v7 0/5] vdso: Keep the CLOCK_AUX base at full precision")
1-3 are in tip/timers/vdso. Please drop 4/5: it moved BITS_PER_TYPE()
into vdso/bits.h only so this assert could use it.
Changes since v7 5/5: assert on CLOCK_AUX_LAST rather than the clock
parameter, and keep a single assert in vdso_clockid_valid().
lib/vdso/gettimeofday.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/lib/vdso/gettimeofday.c b/lib/vdso/gettimeofday.c
index c0e81996532dc..6386f664b9a01 100644
--- a/lib/vdso/gettimeofday.c
+++ b/lib/vdso/gettimeofday.c
@@ -99,6 +99,12 @@ static __always_inline const struct vdso_time_data *__arch_get_vdso_u_time_data(
static __always_inline bool vdso_clockid_valid(clockid_t clock)
{
+ /*
+ * The callers turn an accepted clockid into a bitmask with
+ * 1U << clock, so the largest one has to fit into that u32.
+ */
+ BUILD_BUG_ON(CLOCK_AUX_LAST >= 8 * sizeof(u32));
+
/* Check for negative values or invalid clocks */
return likely((u32) clock <= CLOCK_AUX_LAST);
}
base-commit: 8d17190fae2caab89cd5df19257ed9dac0739e3b
--
2.43.0
next reply other threads:[~2026-10-16 15:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 15:32 Zhan Xusheng [this message]
2026-11-09 15:25 ` [tip: timers/vdso] " tip-bot2 for Zhan Xusheng
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=20261016153212.2733798-1-zhanxusheng1024@gmail.com \
--to=zhanxusheng1024@gmail.com \
--cc=david.laight.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=luto@kernel.org \
--cc=tglx@kernel.org \
--cc=thomas.weissschuh@linutronix.de \
--cc=vincenzo.frascino@arm.com \
--cc=yury.norov@gmail.com \
--cc=zhanxusheng@xiaomi.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
all inboxes | Powered by JetHome®