mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhan Xusheng <zhanxusheng1024@gmail.com>
To: tglx@kernel.org, luto@kernel.org, vincenzo.frascino@arm.com
Cc: thomas.weissschuh@linutronix.de, david.laight.linux@gmail.com,
	linux-kernel@vger.kernel.org, zhanxusheng@xiaomi.com
Subject: [PATCH v3 3/3] vdso/gettimeofday: Assert that the clock id fits the dispatch mask
Date: Tue,  1 Sep 2026 10:06:36 +0800	[thread overview]
Message-ID: <20260901020636.1821993-4-zhanxusheng@xiaomi.com> (raw)
In-Reply-To: <20260901020636.1821993-1-zhanxusheng@xiaomi.com>

The clock id dispatch turns the id into a bit in a u32:

  if (!vdso_clockid_valid(clock))
      return false;
  msk = 1U << clock;

vdso_clockid_valid() admits everything up to CLOCK_AUX_LAST, which is 23,
so the shift is in range.  Nothing states the dependency though, and
raising MAX_AUX_CLOCKS past 16 would take CLOCK_AUX_LAST to 32 or beyond
and make the shift undefined.

Assert it at both dispatch sites.  The condition is on a parameter rather
than a constant, so it relies on the compiler deriving the range from the
vdso_clockid_valid() bail-out above it.  gcc 13 and clang 18 both do: x86
vdso64 and vdso32 build clean, and raising MAX_AUX_CLOCKS to 17 fails the
assert as intended.

Suggested-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
Reviewed-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
No change since v1.

 lib/vdso/gettimeofday.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/vdso/gettimeofday.c b/lib/vdso/gettimeofday.c
index f7a591aba59f..ef4dcc614489 100644
--- a/lib/vdso/gettimeofday.c
+++ b/lib/vdso/gettimeofday.c
@@ -285,6 +285,7 @@ __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.
 	 */
+	BUILD_BUG_ON(clock >= BITS_PER_TYPE(msk));
 	msk = 1U << clock;
 	if (likely(msk & VDSO_HRES))
 		vc = &vc[CS_HRES_COARSE];
@@ -438,6 +439,7 @@ 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.
 	 */
+	BUILD_BUG_ON(clock >= BITS_PER_TYPE(msk));
 	msk = 1U << clock;
 	if (msk & (VDSO_HRES | VDSO_RAW)) {
 		/*
-- 
2.43.0


      parent reply	other threads:[~2026-09-01  2:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-01  2:06 [PATCH v3 0/3] vdso: Keep the CLOCK_AUX base at full precision Zhan Xusheng
2026-09-01  2:06 ` [PATCH v3 1/3] vdso/math64: Add and use __iter_div64_u64_rem() Zhan Xusheng
2026-09-01  8:35   ` Thomas Weißschuh
2026-09-01 12:48     ` David Laight
2026-09-01 13:05       ` Thomas Weißschuh
2026-09-01  2:06 ` [PATCH v3 2/3] vdso/vsyscall: Keep the CLOCK_AUX base scaled Zhan Xusheng
2026-09-01  8:42   ` Thomas Weißschuh
2026-09-01  2:06 ` Zhan Xusheng [this message]

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=20260901020636.1821993-4-zhanxusheng@xiaomi.com \
    --to=zhanxusheng1024@gmail.com \
    --cc=david.laight.linux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=tglx@kernel.org \
    --cc=thomas.weissschuh@linutronix.de \
    --cc=vincenzo.frascino@arm.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®