Blame SOURCES/cryptsetup-2.4.2-Do-not-try-to-set-compiler-optimization-flag-if-wipe.patch

a743d1
From a76310b53fbb117e620f2c37350b68dd267f1088 Mon Sep 17 00:00:00 2001
a743d1
From: Milan Broz <gmazyland@gmail.com>
a743d1
Date: Mon, 20 Sep 2021 17:42:20 +0200
a743d1
Subject: [PATCH] Do not try to set compiler optimization flag if wipe is
a743d1
 implemented in libc.
a743d1
a743d1
If zeroing memory is implemented through libc call (like memset_bzero),
a743d1
compiler should never remove such call. It is not needed to set O0
a743d1
optimization flag explicitly.
a743d1
a743d1
Various checkers like annocheck causes problems with these flags,
a743d1
just remove it where it makes no sense.
a743d1
a743d1
(Moreover, we use the same pattern without compiler magic
a743d1
in crypt_backend_memzero() already.)
a743d1
---
a743d1
 lib/crypto_backend/argon2/core.c | 10 ++++++++--
a743d1
 1 file changed, 8 insertions(+), 2 deletions(-)
a743d1
a743d1
diff --git a/lib/crypto_backend/argon2/core.c b/lib/crypto_backend/argon2/core.c
a743d1
index b204ba98..db9a7741 100644
a743d1
--- a/lib/crypto_backend/argon2/core.c
a743d1
+++ b/lib/crypto_backend/argon2/core.c
a743d1
@@ -120,18 +120,24 @@ void free_memory(const argon2_context *context, uint8_t *memory,
a743d1
     }
a743d1
 }
a743d1
 
a743d1
-void NOT_OPTIMIZED secure_wipe_memory(void *v, size_t n) {
a743d1
 #if defined(_MSC_VER) && VC_GE_2005(_MSC_VER)
a743d1
+void secure_wipe_memory(void *v, size_t n) {
a743d1
     SecureZeroMemory(v, n);
a743d1
+}
a743d1
 #elif defined memset_s
a743d1
+void secure_wipe_memory(void *v, size_t n) {
a743d1
     memset_s(v, n, 0, n);
a743d1
+}
a743d1
 #elif defined(HAVE_EXPLICIT_BZERO)
a743d1
+void secure_wipe_memory(void *v, size_t n) {
a743d1
     explicit_bzero(v, n);
a743d1
+}
a743d1
 #else
a743d1
+void NOT_OPTIMIZED secure_wipe_memory(void *v, size_t n) {
a743d1
     static void *(*const volatile memset_sec)(void *, int, size_t) = &memset;
a743d1
     memset_sec(v, 0, n);
a743d1
-#endif
a743d1
 }
a743d1
+#endif
a743d1
 
a743d1
 /* Memory clear flag defaults to true. */
a743d1
 int FLAG_clear_internal_memory = 1;
a743d1
-- 
a743d1
2.27.0
a743d1