mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: [musl] [PATCH] semtimedop: fix timespec kernel ABI mismatch for 32-bit timeouts on x32
Date: Tue, 11 Apr 2023 09:23:01 -0400	[thread overview]
Message-ID: <20230411132300.GJ4163@brightrain.aerifal.cx> (raw)
In-Reply-To: <20230306175625.219519-1-izbyshev@ispras.ru>

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

      reply	other threads:[~2023-04-11 13:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-06 17:56 Alexey Izbyshev
2023-04-11 13:23 ` Rich Felker [this message]

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=20230411132300.GJ4163@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --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).