From: Elizabeth Figura <zfigura@codeweavers.com>
To: arnd@arndb.de, Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Maoyi Xie <maoyixie.tju@gmail.com>
Cc: wine-devel@winehq.org, linux-kernel@vger.kernel.org
Subject: Re: ntsync: absolute MONOTONIC timeout ignores time namespace offset
Date: Wed, 20 May 2026 22:44:10 -0500 [thread overview]
Message-ID: <53921477.W1JGFHXlht@camazotz> (raw)
In-Reply-To: <CAHPEe=G7A3qcsNJmXpF71iP2UTaQA_p630oYSPNhz4Sob4kJxg@mail.gmail.com>
On Monday, 18 May 2026 05:21:08 CDT Maoyi Xie wrote:
> Hi all,
>
> While reading drivers/misc/ntsync.c I noticed something that
> might be a time-namespace bug. I would appreciate it if you
> could take a look and let me know whether this is a real bug,
> and whether it is worth fixing.
>
> ntsync_schedule() takes the user-supplied absolute timeout
> and hands it to schedule_hrtimeout_range_clock() with
> HRTIMER_MODE_ABS. For the default CLOCK_MONOTONIC path, it
> does not call timens_ktime_to_host() first.
>
> A process inside a CLOCK_MONOTONIC time namespace computes
> the absolute timeout in its own clock view. The kernel reads
> the same value against the host clock. The two differ by the
> namespace offset.
>
> The other absolute-timeout consumers (timerfd, posix-timers,
> alarmtimer, posix-stubs, futex) all run user-supplied
> absolute MONOTONIC ktime through timens_ktime_to_host()
> before hrtimer. ntsync was added post-5.17 and seems to have
> missed that step.
>
> /dev/ntsync is mode 0666, so any user in a time namespace
> that can open it is affected. The user-visible impact is
> wrong timeout behaviour for Wine inside a container that
> sets a CLOCK_MONOTONIC offset.
>
> Attached PoC: baseline run elapsed ~100 ms; the --in-timens
> run inside a -10s namespace elapsed ~0 ms.
>
> A candidate fix would call timens_ktime_to_host(clock, timeout)
> in the else branch (i.e., when NTSYNC_WAIT_REALTIME is not set)
> before passing the value to schedule_hrtimeout_range_clock().
>
> If this is intentional or already known, please disregard.
I was not aware of time namespaces, so no, this was not intentional, and there's no reason to keep it this way. I don't remember at this point if I wrote the timeout logic using any other code as a model... you'd think I would have used futex, but evidently I either didn't or missed the timens call. Thank you for catching this.
> Otherwise, I am happy to send a [PATCH] or to leave the fix to you.
No strong feelings here, so I suppose whoever gets to it first ;-)
> Thank you for your time, and sorry for the noise if this is not actually
> a bug or has already been spotted.
>
> Thanks,
> Maoyi Xie
> https://maoyixie.com/
>
next prev parent reply other threads:[~2026-05-21 4:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-18 10:21 Maoyi Xie
2026-05-21 3:44 ` Elizabeth Figura [this message]
2026-05-21 15:39 ` Maoyi Xie
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=53921477.W1JGFHXlht@camazotz \
--to=zfigura@codeweavers.com \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maoyixie.tju@gmail.com \
--cc=wine-devel@winehq.org \
/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®