mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH] select: fix 64-bit timeout truncation on pre-time64 kernels
@ 2023-03-02  5:10 Alexey Izbyshev
  0 siblings, 0 replies; only message in thread
From: Alexey Izbyshev @ 2023-03-02  5:10 UTC (permalink / raw)
  To: musl

If the (normalized) timeout passed to select exceeds INT_MAX seconds on
an arch with SYS_pselect6_time64 and the kernel is too old to support
time64 syscalls, the timeout is implicitly converted to (32-bit) long on
the fallback path, losing its upper 32 bits and potentially becoming a
small positive value, violating the intended semantics, or even
a negative value, causing the fallback syscall failure. Fix this by
saturating the timeout at INT_MAX as done in other time64 fallback
 src/select/select.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/select/select.c b/src/select/select.c
index 8a786884..f1d72863 100644
--- a/src/select/select.c
+++ b/src/select/select.c
@@ -33,6 +33,7 @@ int select(int n, fd_set *restrict rfds, fd_set *restrict wfds, fd_set *restrict
 			((syscall_arg_t[]){ 0, _NSIG/8 }));
 	if (SYS_pselect6 == SYS_pselect6_time64 || r!=-ENOSYS)
 		return __syscall_ret(r);
+	s = CLAMP(s);
 #ifdef SYS_select
 	return syscall_cp(SYS_select, n, rfds, wfds, efds,

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-02  5:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-02  5:10 [musl] [PATCH] select: fix 64-bit timeout truncation on pre-time64 kernels Alexey Izbyshev

Code repositories for project(s) associated with this public inbox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).