]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common,librbd: add portable ceph_memzero_s
authorLucian Petrut <lpetrut@cloudbasesolutions.com>
Tue, 13 Oct 2020 10:26:10 +0000 (10:26 +0000)
committerLucian Petrut <lpetrut@cloudbasesolutions.com>
Thu, 22 Oct 2020 12:04:34 +0000 (12:04 +0000)
We need a portable way of safely zero-ing out a buffer.

We're adding ceph_memzero_s, which will use one of the
following functions, dependning which one is available:
memset_s, SecureZeroMemory and explicit_bzero.

Signed-off-by: Lucian Petrut <lpetrut@cloudbasesolutions.com>
src/common/compat.cc
src/include/compat.h
src/librbd/crypto/openssl/DataCryptor.cc

index f78822ef1566cc972f2c818295c73a70a81b065c..aacfcc524a4400dab708726cf4783394515f0119 100644 (file)
@@ -232,6 +232,17 @@ char *ceph_strerror_r(int errnum, char *buf, size_t buflen)
 #endif
 }
 
+int ceph_memzero_s(void *dest, size_t destsz, size_t count) {
+#ifdef __STDC_LIB_EXT1__
+    return memset_s(dest, destsz, 0, count);
+#elif defined(_WIN32)
+    SecureZeroMemory(dest, count);
+#else
+    explicit_bzero(dest, count);
+#endif
+    return 0;
+}
+
 #ifdef _WIN32
 
 #include <iomanip>
index 748fafee983229667b7693fcd445a29f29badb2e..a73e7fcac38aec86d958e8a898b1fbe957027302 100644 (file)
@@ -203,6 +203,8 @@ int pipe_cloexec(int pipefd[2], int flags);
 char *ceph_strerror_r(int errnum, char *buf, size_t buflen);
 unsigned get_page_size();
 
+int ceph_memzero_s(void *dest, size_t destsz, size_t count);
+
 #ifdef __cplusplus
 }
 #endif
index 4394b17855b898d7b7a1d9c39f4cc02890568ec7..0ed1d84ed3b9fb1cc55c558041dc8fb395d3033b 100644 (file)
@@ -5,6 +5,7 @@
 #include <openssl/err.h>
 #include <string.h>
 #include "include/ceph_assert.h"
+#include "include/compat.h"
 
 namespace librbd {
 namespace crypto {
@@ -46,7 +47,8 @@ int DataCryptor::init(const char* cipher_name, const unsigned char* key,
 
 DataCryptor::~DataCryptor() {
   if (m_key != nullptr) {
-    explicit_bzero(m_key, EVP_CIPHER_key_length(m_cipher));
+    ceph_memzero_s(m_key, EVP_CIPHER_key_length(m_cipher),
+                   EVP_CIPHER_key_length(m_cipher));
     delete m_key;
     m_key = nullptr;
   }