513694
From fd7108a4c9dc46113f4041e7575c1f1217c0d57d Mon Sep 17 00:00:00 2001
513694
From: Noah Goldstein <goldstein.w.n@gmail.com>
513694
Date: Thu, 24 Mar 2022 15:50:33 -0500
513694
Subject: [PATCH] x86: Fix fallback for wcsncmp_avx2 in strcmp-avx2.S [BZ
513694
 #28896]
513694
513694
Overflow case for __wcsncmp_avx2_rtm should be __wcscmp_avx2_rtm not
513694
__wcscmp_avx2.
513694
513694
commit ddf0992cf57a93200e0c782e2a94d0733a5a0b87
513694
Author: Noah Goldstein <goldstein.w.n@gmail.com>
513694
Date:   Sun Jan 9 16:02:21 2022 -0600
513694
513694
    x86: Fix __wcsncmp_avx2 in strcmp-avx2.S [BZ# 28755]
513694
513694
Set the wrong fallback function for `__wcsncmp_avx2_rtm`. It was set
513694
to fallback on to `__wcscmp_avx2` instead of `__wcscmp_avx2_rtm` which
513694
can cause spurious aborts.
513694
513694
This change will need to be backported.
513694
513694
All string/memory tests pass.
513694
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
513694
513694
(cherry picked from commit 9fef7039a7d04947bc89296ee0d187bc8d89b772)
513694
---
513694
 sysdeps/x86/tst-strncmp-rtm.c          | 15 +++++++++++++++
513694
 sysdeps/x86_64/multiarch/strcmp-avx2.S |  2 +-
513694
 2 files changed, 16 insertions(+), 1 deletion(-)
513694
513694
diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
513694
index aef9866c..ba6543be 100644
513694
--- a/sysdeps/x86/tst-strncmp-rtm.c
513694
+++ b/sysdeps/x86/tst-strncmp-rtm.c
513694
@@ -70,6 +70,16 @@ function_overflow (void)
513694
     return 1;
513694
 }
513694
 
513694
+__attribute__ ((noinline, noclone))
513694
+static int
513694
+function_overflow2 (void)
513694
+{
513694
+  if (STRNCMP (string1, string2, SIZE_MAX >> 4) == 0)
513694
+    return 0;
513694
+  else
513694
+    return 1;
513694
+}
513694
+
513694
 static int
513694
 do_test (void)
513694
 {
513694
@@ -77,5 +87,10 @@ do_test (void)
513694
   if (status != EXIT_SUCCESS)
513694
     return status;
513694
   status = do_test_1 (TEST_NAME, LOOP, prepare, function_overflow);
513694
+  if (status != EXIT_SUCCESS)
513694
+    return status;
513694
+  status = do_test_1 (TEST_NAME, LOOP, prepare, function_overflow2);
513694
+  if (status != EXIT_SUCCESS)
513694
+    return status;
513694
   return status;
513694
 }
513694
diff --git a/sysdeps/x86_64/multiarch/strcmp-avx2.S b/sysdeps/x86_64/multiarch/strcmp-avx2.S
513694
index 179cc0e3..782f9472 100644
513694
--- a/sysdeps/x86_64/multiarch/strcmp-avx2.S
513694
+++ b/sysdeps/x86_64/multiarch/strcmp-avx2.S
513694
@@ -122,7 +122,7 @@ ENTRY(STRCMP)
513694
 	   are cases where length is large enough that it can never be a
513694
 	   bound on valid memory so just use wcscmp.  */
513694
 	shrq	$56, %rcx
513694
-	jnz	__wcscmp_avx2
513694
+	jnz	OVERFLOW_STRCMP
513694
 
513694
 	leaq	(, %rdx, 4), %rdx
513694
 #  endif
513694
-- 
513694
GitLab
513694