From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 28771 invoked from network); 2 Mar 2023 05:17:13 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 2 Mar 2023 05:17:13 -0000 Received: (qmail 29853 invoked by uid 550); 2 Mar 2023 05:17:09 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 29782 invoked from network); 2 Mar 2023 05:17:08 -0000 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 4FF6940737AB From: Alexey Izbyshev To: musl@lists.openwall.com Date: Thu, 2 Mar 2023 08:16:56 +0300 Message-Id: <20230302051656.260369-1-izbyshev@ispras.ru> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Mail-Followup-To: musl@lists.openwall.com Content-Transfer-Encoding: 8bit Subject: [musl] [PATCH] poll: fix timespec kernel ABI mismatch on 32-bit arches without SYS_poll 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