<feed xmlns='http://www.w3.org/2005/Atom'>
<title>musl/src/time, branch master</title>
<subtitle>musl - an implementation of the standard library for Linux-based systems</subtitle>
<link rel='alternate' type='text/html' href='http://git.musl-libc.org/cgit/musl/'/>
<entry>
<title>SIGEV_THREAD timers: fix deadlock when timer_create syscall fails</title>
<updated>2026-10-12T23:11:47+00:00</updated>
<author>
<name>Colin Cross</name>
<email>ccross@android.com</email>
</author>
<published>2026-09-02T20:38:08+00:00</published>
<link rel='alternate' type='text/html' href='http://git.musl-libc.org/cgit/musl/commit/?id=f607123b7210b52ddfff7c8d5a8a9b84efbe2d6b'/>
<id>f607123b7210b52ddfff7c8d5a8a9b84efbe2d6b</id>
<content type='text'>
sem_wait is a cancellation point.  If the parent thread in timer_create
sets td-&gt;cancel = 1 before the child thread reaches sem_wait then
the thread will exit and sem_post will never be called, causing
the parent thread to deadlock in sem_wait.

3ad3fa962efee12067d68c3405a537dce156a7ac set td-&gt;cancel = 1 to fix
a thread leak when the syscall failed.  The switch to two-way semaphores
cde213f9c3ac1aa168581222edee6a6642113323 allows checking if self-&gt;timer_id
is -1 instead of self-&gt;cancel because timer_delete can't have been called
before the sem_post allows the parent thread to return from timer_create.

The deadlock was observed in a test that called
timer_create(CLOCK_BOOTTIME_ALARM, SIGEV_THREAD, ...) without
CAP_WAKE_ALARM, causing the kernel to return EPERM.

Also disable cancellation around the parent semaphores to avoid
the parent being cancelled while the child is still accessing
the args on the parent stack, and save the result of the timer_create
syscall to return as errno on error.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
sem_wait is a cancellation point.  If the parent thread in timer_create
sets td-&gt;cancel = 1 before the child thread reaches sem_wait then
the thread will exit and sem_post will never be called, causing
the parent thread to deadlock in sem_wait.

3ad3fa962efee12067d68c3405a537dce156a7ac set td-&gt;cancel = 1 to fix
a thread leak when the syscall failed.  The switch to two-way semaphores
cde213f9c3ac1aa168581222edee6a6642113323 allows checking if self-&gt;timer_id
is -1 instead of self-&gt;cancel because timer_delete can't have been called
before the sem_post allows the parent thread to return from timer_create.

The deadlock was observed in a test that called
timer_create(CLOCK_BOOTTIME_ALARM, SIGEV_THREAD, ...) without
CAP_WAKE_ALARM, causing the kernel to return EPERM.

Also disable cancellation around the parent semaphores to avoid
the parent being cancelled while the child is still accessing
the args on the parent stack, and save the result of the timer_create
syscall to return as errno on error.
</pre>
</div>
</content>
</entry>
<entry>
<title>time: fix TZif version parsing</title>
<updated>2026-09-09T19:51:00+00:00</updated>
<author>
<name>Matthias Goergens</name>
<email>matthias.goergens@gmail.com</email>
</author>
<published>2026-08-05T07:57:51+00:00</published>
<link rel='alternate' type='text/html' href='http://git.musl-libc.org/cgit/musl/commit/?id=c0c6e62a93682b88bce8018dde6401e486d77190'/>
<id>c0c6e62a93682b88bce8018dde6401e486d77190</id>
<content type='text'>
TZif v1 encodes its version as NUL, but do_tzset treats only the byte
'1' as v1. It consequently reads a valid v1 file as if it contained a
second header.

Use zero and nonzero version bytes to distinguish v1 from later files.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
TZif v1 encodes its version as NUL, but do_tzset treats only the byte
'1' as v1. It consequently reads a valid v1 file as if it contained a
second header.

Use zero and nonzero version bytes to distinguish v1 from later files.
</pre>
</div>
</content>
</entry>
<entry>
<title>fix build regression in clock_nanosleep on 64-bit archs</title>
<updated>2026-09-06T18:25:12+00:00</updated>
<author>
<name>Rich Felker</name>
<email>dalias@aerifal.cx</email>
</author>
<published>2026-09-06T18:25:12+00:00</published>
<link rel='alternate' type='text/html' href='http://git.musl-libc.org/cgit/musl/commit/?id=5e9972eaef08ccf55dabe254ac829a30329793d3'/>
<id>5e9972eaef08ccf55dabe254ac829a30329793d3</id>
<content type='text'>
commit cb0cdc2e88c652af225d2fc31c1dec99b9880d39 broke this as part of
future proofing.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit cb0cdc2e88c652af225d2fc31c1dec99b9880d39 broke this as part of
future proofing.
</pre>
</div>
</content>
</entry>
<entry>
<title>clock_nanosleep: don't assume nanosleep syscall exists</title>
<updated>2026-08-18T00:47:19+00:00</updated>
<author>
<name>Rich Felker</name>
<email>dalias@aerifal.cx</email>
</author>
<published>2026-08-18T00:47:19+00:00</published>
<link rel='alternate' type='text/html' href='http://git.musl-libc.org/cgit/musl/commit/?id=cb0cdc2e88c652af225d2fc31c1dec99b9880d39'/>
<id>cb0cdc2e88c652af225d2fc31c1dec99b9880d39</id>
<content type='text'>
this fixes a build regression for riscv32 introduced in commit
b306b16af15c89a04d8e0c55cac2dadbeb39c083. prior to that, the riscv32
bits/syscall.h.in defined a macro for the nanosleep syscall, despite
the kernel on time64-native archs having no such syscall.

our clock_nanosleep uses the old nanosleep syscall when possible as
part of minimal compatibility with pre-2.6 kernels. using a
non-functional syscall number didn't have any ill effect on riscv32 or
future time64-native archs, since the affected code is unreachable in
that case, but removing the wrongly defined macro broke the build.
this change fixes it.

in order not to need to fix this again if future 64-bit archs also
drop the old nanosleep syscall factor out the conditional use of
SYS_nanosleep and use the same approach in the preprocessor else block
for them.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
this fixes a build regression for riscv32 introduced in commit
b306b16af15c89a04d8e0c55cac2dadbeb39c083. prior to that, the riscv32
bits/syscall.h.in defined a macro for the nanosleep syscall, despite
the kernel on time64-native archs having no such syscall.

our clock_nanosleep uses the old nanosleep syscall when possible as
part of minimal compatibility with pre-2.6 kernels. using a
non-functional syscall number didn't have any ill effect on riscv32 or
future time64-native archs, since the affected code is unreachable in
that case, but removing the wrongly defined macro broke the build.
this change fixes it.

in order not to need to fix this again if future 64-bit archs also
drop the old nanosleep syscall factor out the conditional use of
SYS_nanosleep and use the same approach in the preprocessor else block
for them.
</pre>
</div>
</content>
</entry>
<entry>
<title>time: avoid overflow normalizing extreme tm_mday</title>
<updated>2026-08-05T23:56:37+00:00</updated>
<author>
<name>Matthias Goergens</name>
<email>matthias.goergens@gmail.com</email>
</author>
<published>2026-08-05T07:57:48+00:00</published>
<link rel='alternate' type='text/html' href='http://git.musl-libc.org/cgit/musl/commit/?id=c2021b7795c72848712218356556a62a49037206'/>
<id>c2021b7795c72848712218356556a62a49037206</id>
<content type='text'>
mktime is required to accept and normalize out-of-range members of
struct tm. When tm_mday is INT_MIN, subtracting one from it overflows
before the existing long long multiplication takes effect.

Perform the subtraction in long long so the complete int range can be
normalized as intended.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
mktime is required to accept and normalize out-of-range members of
struct tm. When tm_mday is INT_MIN, subtracting one from it overflows
before the existing long long multiplication takes effect.

Perform the subtraction in long long so the complete int range can be
normalized as intended.
</pre>
</div>
</content>
</entry>
<entry>
<title>fix incorrect access to tzname[] by strptime %Z conversion specifier</title>
<updated>2026-03-30T19:57:10+00:00</updated>
<author>
<name>Rich Felker</name>
<email>dalias@aerifal.cx</email>
</author>
<published>2026-03-23T01:32:35+00:00</published>
<link rel='alternate' type='text/html' href='http://git.musl-libc.org/cgit/musl/commit/?id=0572555dab1d1e10b5f7351a005ec588cab41e25'/>
<id>0572555dab1d1e10b5f7351a005ec588cab41e25</id>
<content type='text'>
there are three issues here:

1. if tzset has not been called (explicitly or implicitly), the
tzname[] array will contain null pointers, and the dereference to
compare against them has undefined behavior (and will fault).

2. access to tzname[] was performed without the timezone lock held.
this resulted in a data race if the timezone is concurrently changed
from another thread.

3. due to unintended signedness of the types, the open-coded isalpha
in the non-matching case was wrong and would continue past null
termination.

to fix the first two issues, the body of the %Z conversion is moved to
__tz.c where it has access to locking, and null checks are added.

there is probably an argument to be made that the equivalent of tzset
should happen here, but POSIX does not specify that to happen, so in
the absence of an interpretation adding such an allowance or
requirement, it is not done.

the third issue is fixed just by using the existing isalpha macro.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
there are three issues here:

1. if tzset has not been called (explicitly or implicitly), the
tzname[] array will contain null pointers, and the dereference to
compare against them has undefined behavior (and will fault).

2. access to tzname[] was performed without the timezone lock held.
this resulted in a data race if the timezone is concurrently changed
from another thread.

3. due to unintended signedness of the types, the open-coded isalpha
in the non-matching case was wrong and would continue past null
termination.

to fix the first two issues, the body of the %Z conversion is moved to
__tz.c where it has access to locking, and null checks are added.

there is probably an argument to be made that the equivalent of tzset
should happen here, but POSIX does not specify that to happen, so in
the absence of an interpretation adding such an allowance or
requirement, it is not done.

the third issue is fixed just by using the existing isalpha macro.
</pre>
</div>
</content>
</entry>
<entry>
<title>SIGEV_THREAD timers: re-block signals when reusing kernel thread</title>
<updated>2024-12-13T11:41:54+00:00</updated>
<author>
<name>Rich Felker</name>
<email>dalias@aerifal.cx</email>
</author>
<published>2024-12-13T11:41:54+00:00</published>
<link rel='alternate' type='text/html' href='http://git.musl-libc.org/cgit/musl/commit/?id=561cd07dff8003251729569e5539b00698941697'/>
<id>561cd07dff8003251729569e5539b00698941697</id>
<content type='text'>
previously, we left any changes made by the application to the timer
thread's signal mask active when resetting the thread state for reuse.
not only did this violate the intended invariant that timer threads
start with all signals blocked; it also allowed application code to
execute in a thread that, formally, did not exist. and further, if the
internal SIGTIMER signal became unblocked, it could also lead to
missed timer expiration events.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
previously, we left any changes made by the application to the timer
thread's signal mask active when resetting the thread state for reuse.
not only did this violate the intended invariant that timer threads
start with all signals blocked; it also allowed application code to
execute in a thread that, formally, did not exist. and further, if the
internal SIGTIMER signal became unblocked, it could also lead to
missed timer expiration events.
</pre>
</div>
</content>
</entry>
<entry>
<title>SIGEV_THREAD timers: fix fatal signal if internal SIGTIMER becomes unblocked</title>
<updated>2024-12-13T11:31:40+00:00</updated>
<author>
<name>Rich Felker</name>
<email>dalias@aerifal.cx</email>
</author>
<published>2024-12-13T11:31:40+00:00</published>
<link rel='alternate' type='text/html' href='http://git.musl-libc.org/cgit/musl/commit/?id=47fa6e4fcc5f61c365c91a9bc90e7ed8b3a178ef'/>
<id>47fa6e4fcc5f61c365c91a9bc90e7ed8b3a178ef</id>
<content type='text'>
commit 6ae2568bc2367b4d47e0ea1cb043fd56e697912f introduced a fatal
signal condition if the internal timer signal used for SIGEV_THREAD
timers is unblocked. this can happen whenever the application alters
the signal mask with SIG_SETMASK, since sigset_t objects never include
the bits used for implementation-internal signals.

this patch effectively reverts the breakage by adding back a no-op
signal handler.

overruns will not be accounted if the timer signal becomes unblocked,
but POSIX does not specify them except for SIGEV_SIGNAL timers anyway.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 6ae2568bc2367b4d47e0ea1cb043fd56e697912f introduced a fatal
signal condition if the internal timer signal used for SIGEV_THREAD
timers is unblocked. this can happen whenever the application alters
the signal mask with SIG_SETMASK, since sigset_t objects never include
the bits used for implementation-internal signals.

this patch effectively reverts the breakage by adding back a no-op
signal handler.

overruns will not be accounted if the timer signal becomes unblocked,
but POSIX does not specify them except for SIGEV_SIGNAL timers anyway.
</pre>
</div>
</content>
</entry>
<entry>
<title>timer_create: replace pthread barrier with semaphores for thread start</title>
<updated>2024-07-24T16:56:01+00:00</updated>
<author>
<name>Rich Felker</name>
<email>dalias@aerifal.cx</email>
</author>
<published>2024-07-24T16:41:04+00:00</published>
<link rel='alternate' type='text/html' href='http://git.musl-libc.org/cgit/musl/commit/?id=cde213f9c3ac1aa168581222edee6a6642113323'/>
<id>cde213f9c3ac1aa168581222edee6a6642113323</id>
<content type='text'>
our pthread barrier implementation reportedly has bugs that are could
lead to malfunction or crash in timer_create. while this has not been
reviewed to confirm, there have been past reports of pthread barrier
bugs, and it seems likely that something is actually wrong.

pthread barriers are an obscure primitive, and timer_create is the
only place we are using them internally at present. even if they were
working correctly, this means we are imposing linking of otherwise
likely-dead code whenever timer_create is used.

a pair of semaphores functions identically to a 2-waiter barrier
except for destruction order properties. since the parent is
responsible for the argument structure (including semaphores)
lifetimes, the last operation on them in the timer thread must be
posting to the parent.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
our pthread barrier implementation reportedly has bugs that are could
lead to malfunction or crash in timer_create. while this has not been
reviewed to confirm, there have been past reports of pthread barrier
bugs, and it seems likely that something is actually wrong.

pthread barriers are an obscure primitive, and timer_create is the
only place we are using them internally at present. even if they were
working correctly, this means we are imposing linking of otherwise
likely-dead code whenever timer_create is used.

a pair of semaphores functions identically to a 2-waiter barrier
except for destruction order properties. since the parent is
responsible for the argument structure (including semaphores)
lifetimes, the last operation on them in the timer thread must be
posting to the parent.
</pre>
</div>
</content>
</entry>
<entry>
<title>move __utc string object to its own translation unit</title>
<updated>2024-07-23T16:01:41+00:00</updated>
<author>
<name>Rich Felker</name>
<email>dalias@aerifal.cx</email>
</author>
<published>2024-07-23T16:01:41+00:00</published>
<link rel='alternate' type='text/html' href='http://git.musl-libc.org/cgit/musl/commit/?id=ef7d0ae21240eac9fc1e8088112bfb0fac507578'/>
<id>ef7d0ae21240eac9fc1e8088112bfb0fac507578</id>
<content type='text'>
having it in __tz.c caused gmtime[_r] and timegm to pull in all of the
time zone code despite having no need for it.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
having it in __tz.c caused gmtime[_r] and timegm to pull in all of the
time zone code despite having no need for it.
</pre>
</div>
</content>
</entry>
</feed>
