fix_avx_detection.patch 1.6 KB

123456789101112131415161718192021222324252627282930313233
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Samuel Attard <[email protected]>
  3. Date: Wed, 15 Nov 2023 13:31:14 -0800
  4. Subject: Fix AVX detection
  5. The old/faulty code would try to use AVX/AVX2 if either the SSE bit or
  6. the AVX bit were set in XCR0, but did not check if both bits were set.
  7. In most cases, this still worked, but on some machines, enabling linux
  8. kernel mitigations for the "gather data sampling" vulnerability results
  9. in only the SSE bit but not the AVX bit being set, thus resulting in an
  10. illegal instruction and crashing the application.
  11. Fix this by checking that both bits are set.
  12. Fixes: 4bbb590 ("Proper check of CPU's AVX2 feature support (with MSVC support)")
  13. Signed-off-by: Pascal Ernster <[email protected]>
  14. Cherry-Picked from https://github.com/aklomp/base64/commit/9003f9b183327df80fda97aa82dfc8054e1d3dce
  15. diff --git a/deps/base64/base64/lib/codec_choose.c b/deps/base64/base64/lib/codec_choose.c
  16. index 6a07d6a74cc24f61cf2b16d13c075234d5c7e2a3..f4215f1ef9d42087ef6735e6817c714ecc43a0ca 100644
  17. --- a/deps/base64/base64/lib/codec_choose.c
  18. +++ b/deps/base64/base64/lib/codec_choose.c
  19. @@ -194,7 +194,7 @@ codec_choose_x86 (struct codec *codec)
  20. if (ecx & bit_XSAVE_XRSTORE) {
  21. uint64_t xcr_mask;
  22. xcr_mask = _xgetbv(_XCR_XFEATURE_ENABLED_MASK);
  23. - if (xcr_mask & _XCR_XMM_AND_YMM_STATE_ENABLED_BY_OS) {
  24. + if ((xcr_mask & _XCR_XMM_AND_YMM_STATE_ENABLED_BY_OS) == _XCR_XMM_AND_YMM_STATE_ENABLED_BY_OS) { // check multiple bits at once
  25. #if HAVE_AVX2
  26. if (max_level >= 7) {
  27. __cpuid_count(7, 0, eax, ebx, ecx, edx);