aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/x86_64/multiarch
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2022-12-01 16:37:11 -0800
committerH.J. Lu <hjl.tools@gmail.com>2022-12-02 08:18:10 -0800
commitf566b028524149ddfebe7f9770a3befb13b81a13 (patch)
tree7ddae400809cd9e2902af7fcd59e3bf22597809c /sysdeps/x86_64/multiarch
parent6ae0737d430900fff02569548a92bdca49622a15 (diff)
downloadglibc-f566b028524149ddfebe7f9770a3befb13b81a13.tar
glibc-f566b028524149ddfebe7f9770a3befb13b81a13.tar.gz
glibc-f566b028524149ddfebe7f9770a3befb13b81a13.tar.bz2
glibc-f566b028524149ddfebe7f9770a3befb13b81a13.zip
x86-64 strncat: Properly handle the length parameter [BZ# 24097]
On x32, the size_t parameter may be passed in the lower 32 bits of a 64-bit register with the non-zero upper 32 bits. The string/memory functions written in assembly can only use the lower 32 bits of a 64-bit register as length or must clear the upper 32 bits before using the full 64-bit register for length. This pach fixes strncat for x32. Tested on x86-64 and x32. On x86-64, libc.so is the same with and without the fix. Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
Diffstat (limited to 'sysdeps/x86_64/multiarch')
-rw-r--r--sysdeps/x86_64/multiarch/strcat-sse2-unaligned.S4
-rw-r--r--sysdeps/x86_64/multiarch/strncat-avx2.S4
-rw-r--r--sysdeps/x86_64/multiarch/strncat-evex.S5
3 files changed, 13 insertions, 0 deletions
diff --git a/sysdeps/x86_64/multiarch/strcat-sse2-unaligned.S b/sysdeps/x86_64/multiarch/strcat-sse2-unaligned.S
index 9d2ca1d504..b0f9c5fa83 100644
--- a/sysdeps/x86_64/multiarch/strcat-sse2-unaligned.S
+++ b/sysdeps/x86_64/multiarch/strcat-sse2-unaligned.S
@@ -35,6 +35,10 @@
ENTRY (STRCAT)
mov %rdi, %r9
# ifdef USE_AS_STRNCAT
+# ifdef __ILP32__
+ /* Clear the upper 32 bits. */
+ movl %edx, %edx
+# endif
mov %rdx, %r8
# endif
diff --git a/sysdeps/x86_64/multiarch/strncat-avx2.S b/sysdeps/x86_64/multiarch/strncat-avx2.S
index ffa58bd0de..73baeee473 100644
--- a/sysdeps/x86_64/multiarch/strncat-avx2.S
+++ b/sysdeps/x86_64/multiarch/strncat-avx2.S
@@ -51,6 +51,10 @@
.section SECTION(.text), "ax", @progbits
ENTRY(STRNCAT)
+# ifdef __ILP32__
+ /* Clear the upper 32 bits. */
+ movl %edx, %edx
+# endif
/* Filter zero length strings and very long strings. Zero
length strings just return, very long strings are handled by
using the non-length variant {wcs|str}cat. */
diff --git a/sysdeps/x86_64/multiarch/strncat-evex.S b/sysdeps/x86_64/multiarch/strncat-evex.S
index bced4e8944..1ef3a22209 100644
--- a/sysdeps/x86_64/multiarch/strncat-evex.S
+++ b/sysdeps/x86_64/multiarch/strncat-evex.S
@@ -79,6 +79,11 @@
.section SECTION(.text), "ax", @progbits
ENTRY(STRNCAT)
+# ifdef __ILP32__
+ /* Clear the upper 32 bits. */
+ movl %edx, %edx
+# endif
+
movq %rdi, %rax
/* NB: It's safe to filter out zero-length strings WITHOUT