mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sun Jian <sun.jian.kdev@gmail.com>
To: Andy Lutomirski <luto@kernel.org>
Cc: Thomas Gleixner <tglx@kernel.org>,
	Vincenzo Frascino <vincenzo.frascino@arm.com>,
	linux-kernel@vger.kernel.org, Sun Jian <sun.jian.kdev@gmail.com>
Subject: [PATCH] lib/vdso: guard clockid before building u32 bitmask
Date: Wed, 14 Jan 2026 16:45:29 +0800	[thread overview]
Message-ID: <20260114084529.1676356-1-sun.jian.kdev@gmail.com> (raw)

__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@gmail.com>
---
 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


             reply	other threads:[~2026-01-14  8:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-14  8:45 Sun Jian [this message]
2026-01-14  8:56 ` Thomas Weißschuh
2026-01-14  9:31   ` sun jian
2026-01-14  9:53     ` Thomas Weißschuh
2026-01-14 10:26       ` sun jian
2026-01-14 10:35         ` Thomas Weißschuh

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=20260114084529.1676356-1-sun.jian.kdev@gmail.com \
    --to=sun.jian.kdev@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=tglx@kernel.org \
    --cc=vincenzo.frascino@arm.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®