]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
msg/async/crypto_onwire: add asserts for reset_tx_handler() reservation
authorIlya Dryomov <idryomov@gmail.com>
Fri, 3 Apr 2020 13:43:10 +0000 (15:43 +0200)
committerIlya Dryomov <idryomov@gmail.com>
Mon, 13 Jul 2020 12:44:44 +0000 (14:44 +0200)
Add asserts to avoid bugs like the one fixed in 1a975fb3a801
("msg/async: fix unnecessary 4 kB allocation in secure mode.").

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
(cherry picked from commit 4894e591200c2234dff7241de95997981ad90972)

src/msg/async/crypto_onwire.cc

index 596e578488cd2b56f1e72b9f49e87bc4a976674d..102c8a14e0cd3d2bd70b11e80bdc751172b6c95f 100644 (file)
@@ -95,6 +95,7 @@ void AES128GCM_OnWireTxHandler::reset_tx_handler(const uint32_t* first,
     throw std::runtime_error("EVP_EncryptInit_ex failed");
   }
 
+  ceph_assert(buffer.get_append_buffer_unused_tail_length() == 0);
   buffer.reserve(std::accumulate(first, last, AESGCM_TAG_LEN));
 
   nonce.random_seq = nonce.random_seq + 1;
@@ -103,6 +104,8 @@ void AES128GCM_OnWireTxHandler::reset_tx_handler(const uint32_t* first,
 void AES128GCM_OnWireTxHandler::authenticated_encrypt_update(
   const ceph::bufferlist& plaintext)
 {
+  ceph_assert(buffer.get_append_buffer_unused_tail_length() >=
+              plaintext.length());
   auto filler = buffer.append_hole(plaintext.length());
 
   for (const auto& plainbuf : plaintext.buffers()) {
@@ -129,6 +132,8 @@ void AES128GCM_OnWireTxHandler::authenticated_encrypt_update(
 ceph::bufferlist AES128GCM_OnWireTxHandler::authenticated_encrypt_final()
 {
   int final_len = 0;
+  ceph_assert(buffer.get_append_buffer_unused_tail_length() ==
+              AESGCM_BLOCK_LEN);
   auto filler = buffer.append_hole(AESGCM_BLOCK_LEN);
   if(1 != EVP_EncryptFinal_ex(ectx.get(),
        reinterpret_cast<unsigned char*>(filler.c_str()),