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 32093 invoked from network); 11 Apr 2023 13:23:17 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 11 Apr 2023 13:23:17 -0000 Received: (qmail 17952 invoked by uid 550); 11 Apr 2023 13:23:14 -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 17916 invoked from network); 11 Apr 2023 13:23:13 -0000 Date: Tue, 11 Apr 2023 09:23:01 -0400 From: Rich Felker To: musl@lists.openwall.com Message-ID: <20230411132300.GJ4163@brightrain.aerifal.cx> References: <20230306175625.219519-1-izbyshev@ispras.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230306175625.219519-1-izbyshev@ispras.ru> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] [PATCH] semtimedop: fix timespec kernel ABI mismatch for 32-bit timeouts on x32 On Mon, Mar 06, 2023 at 08:56:25PM +0300, Alexey Izbyshev wrote: > For time64 support, musl normally defines SYS_foo to the time32 variant > of that syscall on arches that have it, and to the time64 variant > otherwise, so that "SYS_foo == SYS_foo_time64" implies that the arch is > time64-only. However, SYS_semtimedop is an odd case: some arches define > only SYS_semtimedop_time64, yet they are not time64-only, because the > time32 variant is provided via SYS_ipc instead. For such arches, > defining SYS_semtimedop to SYS_semtimedop_time64 would break the > implication above, so commit 4bbd7baea7c8538b3fb8e30f7b022a1eee071450 > doesn't do this. Commit eb2e298cdc814493a6ced8c05cf0d0f5cccc8b63 > attempts to detect time64-only arches by checking that both > SYS_semtimedop and SYS_ipc are undefined, but this doesn't work for > x32, because it's a time64-only arch that does define SYS_semtimedop. > As a result, 32-bit timeouts trigger the fallback path that passes > a 32-bit timespec to the kernel while it expects a 64-bit one, so > the effective tv_sec is formed by interpreting 32-bit tv_sec and > tv_nsec as a single long long, and the effective tv_nsec is whatever > is located in the next 64 bits of the stack. > > Fix this by expanding the time64-only check to include arches where > SYS_semtimedop is the time64 variant of the syscall. > --- > src/ipc/semtimedop.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/src/ipc/semtimedop.c b/src/ipc/semtimedop.c > index 1632e7b0..a104af21 100644 > --- a/src/ipc/semtimedop.c > +++ b/src/ipc/semtimedop.c > @@ -7,7 +7,8 @@ > #define IS32BIT(x) !((x)+0x80000000ULL>>32) > #define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63)) > > -#if !defined(SYS_semtimedop) && !defined(SYS_ipc) > +#if !defined(SYS_semtimedop) && !defined(SYS_ipc) || \ > + SYS_semtimedop == SYS_semtimedop_time64 > #define NO_TIME32 1 > #else > #define NO_TIME32 0 > -- > 2.39.1 It looks like I'd overlooked this; applying it now. Thanks! Rich