about summary refs log tree commit diff
path: root/sysdeps/x86_64/multiarch
diff options
context:
space:
mode:
authorNoah Goldstein <goldstein.w.n@gmail.com>2022-02-15 20:27:21 -0600
committerNoah Goldstein <goldstein.w.n@gmail.com>2022-02-16 02:11:16 -0600
commite108c02a5e23c8c88ce66d8705d4a24bb6b9a8bf (patch)
treeaa7b3178016dfb0f5a270d900385d889016be1ee /sysdeps/x86_64/multiarch
parent0281c7a7ec8f3f46d8e6f5f3d7fca548946dbfce (diff)
downloadglibc-e108c02a5e23c8c88ce66d8705d4a24bb6b9a8bf.tar.gz
glibc-e108c02a5e23c8c88ce66d8705d4a24bb6b9a8bf.tar.xz
glibc-e108c02a5e23c8c88ce66d8705d4a24bb6b9a8bf.zip
x86: Fix bug in strncmp-evex and strncmp-avx2 [BZ #28895]
Logic can read before the start of `s1` / `s2` if both `s1` and `s2`
are near the start of a page. To avoid having the result contimated by
these comparisons the `strcmp` variants would mask off these
comparisons. This was missing in the `strncmp` variants causing
the bug. This commit adds the masking to `strncmp` so that out of
range comparisons don't affect the result.

test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all pass as
well a full xcheck on x86_64 linux.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
Diffstat (limited to 'sysdeps/x86_64/multiarch')
-rw-r--r--sysdeps/x86_64/multiarch/strcmp-avx2.S1
-rw-r--r--sysdeps/x86_64/multiarch/strcmp-evex.S1
2 files changed, 2 insertions, 0 deletions
diff --git a/sysdeps/x86_64/multiarch/strcmp-avx2.S b/sysdeps/x86_64/multiarch/strcmp-avx2.S
index 99e5349be8..07a5a2c889 100644
--- a/sysdeps/x86_64/multiarch/strcmp-avx2.S
+++ b/sysdeps/x86_64/multiarch/strcmp-avx2.S
@@ -661,6 +661,7 @@ L(ret8):
 # ifdef USE_AS_STRNCMP
 	.p2align 4,, 10
 L(return_page_cross_end_check):
+	andl	%r10d, %ecx
 	tzcntl	%ecx, %ecx
 	leal	-VEC_SIZE(%rax, %rcx), %ecx
 	cmpl	%ecx, %edx
diff --git a/sysdeps/x86_64/multiarch/strcmp-evex.S b/sysdeps/x86_64/multiarch/strcmp-evex.S
index 6f42e3155a..56d8c118e4 100644
--- a/sysdeps/x86_64/multiarch/strcmp-evex.S
+++ b/sysdeps/x86_64/multiarch/strcmp-evex.S
@@ -689,6 +689,7 @@ L(ret8):
 # ifdef USE_AS_STRNCMP
 	.p2align 4,, 10
 L(return_page_cross_end_check):
+	andl	%r10d, %ecx
 	tzcntl	%ecx, %ecx
 	leal	-VEC_SIZE(%rax, %rcx, SIZE_OF_CHAR), %ecx
 #  ifdef USE_AS_WCSCMP