From: Alexey Izbyshev <izbyshev@ispras.ru>
To: musl@lists.openwall.com
Subject: [musl] [PATCH] poll: fix timespec kernel ABI mismatch on 32-bit arches without SYS_poll
Date: Thu, 2 Mar 2023 08:16:56 +0300 [thread overview]
Message-ID: <20230302051656.260369-1-izbyshev@ispras.ru> (raw)
After migration to 64-bit time_t in struct timespec, passing it to
SYS_ppoll on arches where the syscall expects the 32-bit version of
the struct became wrong and results in overlaying 64-bit tv_sec over the
whole expected struct. In this case, tv_nsec is completely ignored, and
interpretation of tv_sec depends on endianness. Because its value in the
case of poll fits into 32 bits, on little endian arches tv_sec is
interpreted as the correct number of seconds and zero nanoseconds, so
the original timeout is effectively rounded down to seconds. On big
endian arches, tv_sec is interpreted as nanoseconds (and zero seconds),
so the original timeout is effectively divided by 10^9 and rounded down
to nanoseconds.
The only in-tree affected arch is or1k, which is big endian.
Fix this by passing the timeout in the array of the type actually
expected by the kernel for SYS_ppoll, as done in other time64-related
code.
---
src/select/poll.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/select/poll.c b/src/select/poll.c
index c84c8a99..d1caefcc 100644
--- a/src/select/poll.c
+++ b/src/select/poll.c
@@ -8,8 +8,14 @@ int poll(struct pollfd *fds, nfds_t n, int timeout)
#ifdef SYS_poll
return syscall_cp(SYS_poll, fds, n, timeout);
#else
- return syscall_cp(SYS_ppoll, fds, n, timeout>=0 ?
- &((struct timespec){ .tv_sec = timeout/1000,
- .tv_nsec = timeout%1000*1000000 }) : 0, 0, _NSIG/8);
+ time_t s = timeout>=0 ? timeout/1000 : 0;
+ long ns = timeout>=0 ? timeout%1000*1000000 : 0;
+#ifdef SYS_ppoll_time64
+ if (SYS_ppoll == SYS_ppoll_time64)
+ return syscall_cp(SYS_ppoll_time64, fds, n,
+ timeout>=0 ? ((long long[]){s, ns}) : 0, 0, _NSIG/8);
+#endif
+ return syscall_cp(SYS_ppoll, fds, n,
+ timeout>=0 ? ((long[]){s, ns}) : 0, 0, _NSIG/8);
#endif
}
--
2.39.1
next reply other threads:[~2023-03-02 5:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-02 5:16 Alexey Izbyshev [this message]
2023-03-03 1:19 ` Rich Felker
2023-03-03 4:03 ` Alexey Izbyshev
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=20230302051656.260369-1-izbyshev@ispras.ru \
--to=izbyshev@ispras.ru \
--cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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).