08c3a6
commit 4bbd0f866ad0ff197f72346f776ebee9b7e1a706
08c3a6
Author: Noah Goldstein <goldstein.w.n@gmail.com>
08c3a6
Date:   Fri Dec 3 15:29:25 2021 -0800
08c3a6
08c3a6
    x86-64: Use notl in EVEX strcmp [BZ #28646]
08c3a6
    
08c3a6
    Must use notl %edi here as lower bits are for CHAR comparisons
08c3a6
    potentially out of range thus can be 0 without indicating mismatch.
08c3a6
    This fixes BZ #28646.
08c3a6
    
08c3a6
    Co-Authored-By: H.J. Lu <hjl.tools@gmail.com>
08c3a6
    (cherry picked from commit 4df1fa6ddc8925a75f3da644d5da3bb16eb33f02)
08c3a6
08c3a6
diff --git a/string/test-strcmp.c b/string/test-strcmp.c
08c3a6
index 7feababf4ddc5603..a0255b9625fbcedd 100644
08c3a6
--- a/string/test-strcmp.c
08c3a6
+++ b/string/test-strcmp.c
08c3a6
@@ -25,6 +25,7 @@
08c3a6
 # define TEST_NAME "strcmp"
08c3a6
 #endif
08c3a6
 #include "test-string.h"
08c3a6
+#include <support/test-driver.h>
08c3a6
 
08c3a6
 #ifdef WIDE
08c3a6
 # include <wchar.h>
08c3a6
@@ -392,6 +393,32 @@ check2 (void)
08c3a6
 	}
08c3a6
 }
08c3a6
 
08c3a6
+static void
08c3a6
+check3 (void)
08c3a6
+{
08c3a6
+  size_t size = 0xd000 + 0x4000;
08c3a6
+  CHAR *s1, *s2;
08c3a6
+  CHAR *buffer1 = mmap (NULL, size, PROT_READ | PROT_WRITE,
08c3a6
+			MAP_PRIVATE | MAP_ANON, -1, 0);
08c3a6
+  CHAR *buffer2 = mmap (NULL, size, PROT_READ | PROT_WRITE,
08c3a6
+			MAP_PRIVATE | MAP_ANON, -1, 0);
08c3a6
+  if (buffer1 == MAP_FAILED || buffer1 == MAP_FAILED)
08c3a6
+    error (EXIT_UNSUPPORTED, errno, "mmap failed");
08c3a6
+
08c3a6
+  s1 = (CHAR *) (buffer1 + 0x8f8 / sizeof (CHAR));
08c3a6
+  s2 = (CHAR *) (buffer2 + 0xcff3 / sizeof (CHAR));
08c3a6
+
08c3a6
+  STRCPY(s1, L("/export/redhat/rpms/BUILD/java-1.8.0-openjdk-1.8.0.312.b07-2.fc35.x86_64/openjdk/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/PathDocFileFactory.java"));
08c3a6
+  STRCPY(s2, L("/export/redhat/rpms/BUILD/java-1.8.0-openjdk-1.8.0.312.b07-2.fc35.x86_64/openjdk/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/ThrowsTaglet.java"));
08c3a6
+
08c3a6
+  int exp_result = SIMPLE_STRCMP (s1, s2);
08c3a6
+  FOR_EACH_IMPL (impl, 0)
08c3a6
+    check_result (impl, s1, s2, exp_result);
08c3a6
+
08c3a6
+  munmap ((void *) buffer1, size);
08c3a6
+  munmap ((void *) buffer2, size);
08c3a6
+}
08c3a6
+
08c3a6
 int
08c3a6
 test_main (void)
08c3a6
 {
08c3a6
@@ -400,6 +427,7 @@ test_main (void)
08c3a6
   test_init ();
08c3a6
   check();
08c3a6
   check2 ();
08c3a6
+  check3 ();
08c3a6
 
08c3a6
   printf ("%23s", "");
08c3a6
   FOR_EACH_IMPL (impl, 0)
08c3a6
diff --git a/sysdeps/x86_64/multiarch/strcmp-evex.S b/sysdeps/x86_64/multiarch/strcmp-evex.S
08c3a6
index 82f12ac89bcae20b..6f5c4bf984da2b80 100644
08c3a6
--- a/sysdeps/x86_64/multiarch/strcmp-evex.S
08c3a6
+++ b/sysdeps/x86_64/multiarch/strcmp-evex.S
08c3a6
@@ -656,12 +656,13 @@ L(loop_cross_page):
08c3a6
 	   in YMM3 and 32 bytes at VEC_SIZE(%rdx, %r10).  */
08c3a6
 	VPCMP	$0, VEC_SIZE(%rdx, %r10), %YMM3, %k3{%k4}
08c3a6
 	kmovd	%k3, %edi
08c3a6
+    /* Must use notl %edi here as lower bits are for CHAR
08c3a6
+	   comparisons potentially out of range thus can be 0 without
08c3a6
+	   indicating mismatch.  */
08c3a6
+	notl	%edi
08c3a6
 # ifdef USE_AS_WCSCMP
08c3a6
 	/* Don't use subl since it is the upper 8 bits of EDI below.  */
08c3a6
-	notl	%edi
08c3a6
 	andl	$0xff, %edi
08c3a6
-# else
08c3a6
-	incl	%edi
08c3a6
 # endif
08c3a6
 
08c3a6
 # ifdef USE_AS_WCSCMP
08c3a6
@@ -743,12 +744,13 @@ L(loop_cross_page_2_vec):
08c3a6
 	   in YMM1 and 32 bytes at (VEC_SIZE * 3)(%rdx, %r10).  */
08c3a6
 	VPCMP	$0, (VEC_SIZE * 3)(%rdx, %r10), %YMM1, %k3{%k4}
08c3a6
 	kmovd	%k3, %edi
08c3a6
+	/* Must use notl %edi here as lower bits are for CHAR
08c3a6
+	   comparisons potentially out of range thus can be 0 without
08c3a6
+	   indicating mismatch.  */
08c3a6
+	notl	%edi
08c3a6
 # ifdef USE_AS_WCSCMP
08c3a6
 	/* Don't use subl since it is the upper 8 bits of EDI below.  */
08c3a6
-	notl	%edi
08c3a6
 	andl	$0xff, %edi
08c3a6
-# else
08c3a6
-	incl	%edi
08c3a6
 # endif
08c3a6
 
08c3a6
 # ifdef USE_AS_WCSCMP