21136-rdrand.patch 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. From ac334617a9f20b79f5e554135dca15a4c8144f49 Mon Sep 17 00:00:00 2001
  2. From: Antony Polukhin <antoshkka@gmail.com>
  3. Date: Tue, 6 Jun 2023 18:09:27 +0300
  4. Subject: [PATCH 1/2] Workaround false positive warning of MSAN in eng_rdrand.c
  5. ---
  6. crypto/engine/eng_rdrand.c | 10 ++++++++++
  7. 1 file changed, 10 insertions(+)
  8. diff --git a/crypto/engine/eng_rdrand.c b/crypto/engine/eng_rdrand.c
  9. index f46a5145974e..88f2fa20bc3e 100644
  10. --- a/crypto/engine/eng_rdrand.c
  11. +++ b/crypto/engine/eng_rdrand.c
  12. @@ -32,6 +32,16 @@ static int get_random_bytes(unsigned char *buf, int num)
  13. return 0;
  14. }
  15. +#if defined(__has_feature)
  16. +#if __has_feature(memory_sanitizer)
  17. + /*
  18. + * MemorySanitizer fails to understand asm and produces false positive
  19. + * use-of-uninitialized-value warnings without memset.
  20. + */
  21. + memset(buf, 0, num);
  22. +#endif
  23. +#endif
  24. +
  25. return (size_t)num == OPENSSL_ia32_rdrand_bytes(buf, (size_t)num);
  26. }
  27. From 7096737ce9e2fdc5a1c18e34020c613c4074778c Mon Sep 17 00:00:00 2001
  28. From: Antony Polukhin <antoshkka@gmail.com>
  29. Date: Tue, 6 Jun 2023 20:07:23 +0300
  30. Subject: [PATCH 2/2] Review fixes
  31. ---
  32. crypto/engine/eng_rdrand.c | 18 ++++++++++++------
  33. 1 file changed, 12 insertions(+), 6 deletions(-)
  34. diff --git a/crypto/engine/eng_rdrand.c b/crypto/engine/eng_rdrand.c
  35. index 88f2fa20bc3e..a18a772fb364 100644
  36. --- a/crypto/engine/eng_rdrand.c
  37. +++ b/crypto/engine/eng_rdrand.c
  38. @@ -20,6 +20,12 @@
  39. #include <openssl/err.h>
  40. #include <openssl/crypto.h>
  41. +#if defined(__has_feature)
  42. +# if __has_feature(memory_sanitizer)
  43. +# include <sanitizer/msan_interface.h>
  44. +# endif
  45. +#endif
  46. +
  47. #if (defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
  48. defined(__x86_64) || defined(__x86_64__) || \
  49. defined(_M_AMD64) || defined (_M_X64)) && defined(OPENSSL_CPUID_OBJ)
  50. @@ -32,15 +38,15 @@ static int get_random_bytes(unsigned char *buf, int num)
  51. return 0;
  52. }
  53. -#if defined(__has_feature)
  54. -#if __has_feature(memory_sanitizer)
  55. +# if defined(__has_feature)
  56. +# if __has_feature(memory_sanitizer)
  57. /*
  58. * MemorySanitizer fails to understand asm and produces false positive
  59. - * use-of-uninitialized-value warnings without memset.
  60. + * use-of-uninitialized-value warnings.
  61. */
  62. - memset(buf, 0, num);
  63. -#endif
  64. -#endif
  65. + __msan_unpoison(buf, num);
  66. +# endif
  67. +# endif
  68. return (size_t)num == OPENSSL_ia32_rdrand_bytes(buf, (size_t)num);
  69. }