]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
x86: use default cache size if it cannot be determined [BZ #28784]
authorAurelien Jarno <aurelien@aurel32.net>
Mon, 17 Jan 2022 18:41:40 +0000 (19:41 +0100)
committerAurelien Jarno <aurelien@aurel32.net>
Mon, 17 Jan 2022 18:46:24 +0000 (19:46 +0100)
In some cases (e.g QEMU, non-Intel/AMD CPU) the cache information can
not be retrieved and the corresponding values are set to 0.

Commit 2d651eb9265d ("x86: Move x86 processor cache info to
cpu_features") changed the behaviour in such case by defining the
__x86_shared_cache_size and __x86_data_cache_size variables to 0 instead
of using the default values. This cause an issue with the i686 SSE2
optimized bzero/routine which assumes that the cache size is at least
128 bytes, and otherwise tries to zero/set the whole address space minus
128 bytes.

Fix that by restoring the original code to only update
__x86_shared_cache_size and __x86_data_cache_size variables if the
corresponding cache sizes are not zero.

Fixes bug 28784
Fixes commit 2d651eb9265d

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
(cherry picked from commit c242fcce06e3102ca663b2f992611d0bda4f2668)

NEWS
sysdeps/x86/cacheinfo.h

diff --git a/NEWS b/NEWS
index 58c6ae84fb9a3601681d59572d15879a0b082543..7e773bd0058ff8fbeb5842c7d3ff54f4b00b99c5 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -42,6 +42,7 @@ The following bugs are resolved with this release:
   [28744] A64FX string functions are selected without SVE HWCAP
   [28771] %ebx optimization macros are incompatible with .altmacro
   [28768] CVE-2022-23218: Buffer overflow in sunrpc svcunix_create
+  [28784] x86: crash in 32bit memset-sse2.s when the cache size can not be determined
 
 \f
 Version 2.34
index 41d2c81369840adac88ce3859143b0c1b017e88f..63f36877e3f35d99c2afc38d91c3eff63d455e99 100644 (file)
@@ -61,14 +61,20 @@ init_cacheinfo (void)
   long int data = cpu_features->data_cache_size;
   /* Round data cache size to multiple of 256 bytes.  */
   data = data & ~255L;
-  __x86_data_cache_size_half = data / 2;
-  __x86_data_cache_size = data;
+  if (data > 0)
+    {
+      __x86_data_cache_size_half = data / 2;
+      __x86_data_cache_size = data;
+    }
 
   long int shared = cpu_features->shared_cache_size;
   /* Round shared cache size to multiple of 256 bytes.  */
   shared = shared & ~255L;
-  __x86_shared_cache_size_half = shared / 2;
-  __x86_shared_cache_size = shared;
+  if (shared > 0)
+    {
+      __x86_shared_cache_size_half = shared / 2;
+      __x86_shared_cache_size = shared;
+    }
 
   __x86_shared_non_temporal_threshold
     = cpu_features->non_temporal_threshold;