Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20260805075730.3520535-1-matthias.goergens@gmail.com>
Date: Wed,  5 Aug 2026 15:57:30 +0800
From: Matthias Goergens <matthias.goergens@...il.com>
To: musl@...ts.openwall.com
Cc: Matthias Goergens <matthias.goergens@...il.com>
Subject: [PATCH] thread: avoid overflow for expired timed waits

__timedwait_cp subtracts the current clock from an absolute deadline
before checking whether the deadline has expired. An extreme past
deadline can therefore overflow time_t and become an unintended wait.

Compare the timestamps first and return ETIMEDOUT for an expired
deadline. Keep the check in the blocking path, so callers still succeed
immediately when the synchronisation object is already available.
Preserve the futex check at equality so a concurrent change is observed.
---
 src/thread/__timedwait.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/thread/__timedwait.c b/src/thread/__timedwait.c
index 666093be..a93d6e3c 100644
--- a/src/thread/__timedwait.c
+++ b/src/thread/__timedwait.c
@@ -40,6 +40,9 @@ int __timedwait_cp(volatile int *addr, int val,
 	if (at) {
 		if (at->tv_nsec >= 1000000000UL) return EINVAL;
 		if (__clock_gettime(clk, &to)) return EINVAL;
+		if (at->tv_sec < to.tv_sec ||
+		    (at->tv_sec == to.tv_sec && at->tv_nsec < to.tv_nsec))
+			return ETIMEDOUT;
 		to.tv_sec = at->tv_sec - to.tv_sec;
 		if ((to.tv_nsec = at->tv_nsec - to.tv_nsec) < 0) {
 			to.tv_sec--;
-- 
2.55.0

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.