]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
x86-64: Fix the tcb field load for x32 [BZ #31185]
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 21 Dec 2023 03:42:12 +0000 (19:42 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Sat, 23 Dec 2023 15:50:29 +0000 (07:50 -0800)
_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.

(cherry picked from commit 81be2a61dafc168327c1639e97b6dae128c7ccf3)

NEWS
sysdeps/x86_64/dl-tlsdesc.S

diff --git a/NEWS b/NEWS
index e4777c13da923d33e7c8a7afca717209bc062ab5..4ba7fabddbf5cb8e56f2ed07856996c7d6c9f10b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -85,6 +85,7 @@ The following bugs are resolved with this release:
   [30804] F_GETLK, F_SETLK, and F_SETLKW value change for powerpc64 with
     -D_FILE_OFFSET_BITS=64
   [31184] FAIL: elf/tst-tlsgap
+  [31185] Incorrect thread point access in _dl_tlsdesc_undefweak and _dl_tlsdesc_dynamic
 
 Security related changes:
 
index 706856e095de6230e48055ff7b2b34cfcb4c63d8..7619e743e1be41bf5431081780e9ab58809b96cd 100644 (file)
@@ -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: