public inbox for libc-stable@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: libc-alpha@sourceware.org,
	 Libc-stable Mailing List <libc-stable@sourceware.org>,
	Noah Goldstein <goldstein.w.n@gmail.com>
Subject: Re: [PATCH] x86-64: Fix the tcb field load for x32 [BZ #31185]
Date: Thu, 21 Dec 2023 08:10:01 -0800	[thread overview]
Message-ID: <CAMe9rOqfk_Q7qGS8c=oGjovbcx6S+nmBOwmPke-bGSkzfQgA2A@mail.gmail.com> (raw)
In-Reply-To: <20231221034212.2608829-1-hjl.tools@gmail.com>

On Wed, Dec 20, 2023 at 7:42 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> _dl_tlsdesc_undefweak and _dl_tlsdesc_dynamic access the thread pointer
> via the tcb field in TCB:
>
> _dl_tlsdesc_undefweak:
>         _CET_ENDBR
>         movq    8(%rax), %rax
>         subq    %fs:0, %rax
>         ret
>
> _dl_tlsdesc_dynamic:
>         ...
>         subq    %fs:0, %rax
>         movq    -8(%rsp), %rdi
>         ret
>
> Since the tcb field in TCB is a pointer, %fs:0 is a 32-bit location,
> not 64-bit. It should use "sub %fs:0, %RAX_LP" instead.  Since
> _dl_tlsdesc_undefweak returns ptrdiff_t and _dl_make_tlsdesc_dynamic
> returns void *, RAX_LP is appropriate here for x32 and x86-64.  This
> fixes BZ #31185.
> ---
>  sysdeps/x86_64/dl-tlsdesc.S | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/sysdeps/x86_64/dl-tlsdesc.S b/sysdeps/x86_64/dl-tlsdesc.S
> index c4823547d7..4579424bf7 100644
> --- a/sysdeps/x86_64/dl-tlsdesc.S
> +++ b/sysdeps/x86_64/dl-tlsdesc.S
> @@ -61,7 +61,7 @@ _dl_tlsdesc_return:
>  _dl_tlsdesc_undefweak:
>         _CET_ENDBR
>         movq    8(%rax), %rax
> -       subq    %fs:0, %rax
> +       sub     %fs:0, %RAX_LP
>         ret
>         cfi_endproc
>         .size   _dl_tlsdesc_undefweak, .-_dl_tlsdesc_undefweak
> @@ -116,7 +116,7 @@ _dl_tlsdesc_dynamic:
>         addq    TLSDESC_MODOFF(%rdi), %rax
>  .Lret:
>         movq    -16(%rsp), %rsi
> -       subq    %fs:0, %rax
> +       sub     %fs:0, %RAX_LP
>         movq    -8(%rsp), %rdi
>         ret
>  .Lslow:
> --
> 2.43.0
>

I will check it in tomorrow and back it to release branches later.

Thanks.

-- 
H.J.

           reply	other threads:[~2023-12-21 16:10 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <20231221034212.2608829-1-hjl.tools@gmail.com>]

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='CAMe9rOqfk_Q7qGS8c=oGjovbcx6S+nmBOwmPke-bGSkzfQgA2A@mail.gmail.com' \
    --to=hjl.tools@gmail.com \
    --cc=goldstein.w.n@gmail.com \
    --cc=libc-alpha@sourceware.org \
    --cc=libc-stable@sourceware.org \
    /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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).