]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
cephx: Fix incorrect use of __le16/32/64
authorUlrich Weigand <ulrich.weigand@de.ibm.com>
Mon, 2 Sep 2019 19:23:47 +0000 (21:23 +0200)
committerUlrich Weigand <ulrich.weigand@de.ibm.com>
Thu, 5 Sep 2019 08:50:04 +0000 (10:50 +0200)
Use ceph_le16/32/64 instead of __le16/32/64 (which are no-op outside
of kernel code).

Note that I've also changes cephx_calc_client_server_challenge to
use ceph_le64 instead of manually byte-swapping by mswab.  (This
is a no-op, but it seems more consistent to use the ceph_le types
throughout.)

Fixes (partially): https://tracker.ceph.com/issues/41605

Signed-off-by: Ulrich Weigand <ulrich.weigand@de.ibm.com>
src/auth/cephx/CephxProtocol.cc
src/auth/cephx/CephxSessionHandler.cc

index 5b7a2bcb86ed4303e226c034ec785b95c7c20959..d975cbea09ed1ecf1ddb3b20899681a75804bba7 100644 (file)
@@ -37,9 +37,9 @@ void cephx_calc_client_server_challenge(CephContext *cct, CryptoKey& secret, uin
     return;
 
   uint64_t k = 0;
-  const uint64_t *p = (const uint64_t *)enc.c_str();
+  const ceph_le64 *p = (const ceph_le64 *)enc.c_str();
   for (int pos = 0; pos + sizeof(k) <= enc.length(); pos+=sizeof(k), p++)
-    k ^= mswab(*p);
+    k ^= *p;
   *key = k;
 }
 
index 6ef45eaa76f762f3d78b86456cdc486a60127859..966f87197d795150ff95e7efcec480911dc10482 100644 (file)
@@ -49,16 +49,16 @@ int CephxSessionHandler::_calc_signature(Message *m, uint64_t *psig)
     // - skip the leading 4 byte wrapper from encode_encrypt
     struct {
       __u8 v;
-      __le64 magic;
-      __le32 len;
-      __le32 header_crc;
-      __le32 front_crc;
-      __le32 middle_crc;
-      __le32 data_crc;
+      ceph_le64 magic;
+      ceph_le32 len;
+      ceph_le32 header_crc;
+      ceph_le32 front_crc;
+      ceph_le32 middle_crc;
+      ceph_le32 data_crc;
     } __attribute__ ((packed)) sigblock = {
-      1, mswab(AUTH_ENC_MAGIC), mswab<uint32_t>(4*4),
-      mswab<uint32_t>(header.crc), mswab<uint32_t>(footer.front_crc),
-      mswab<uint32_t>(footer.middle_crc), mswab<uint32_t>(footer.data_crc)
+      1, init_le64(AUTH_ENC_MAGIC), init_le32(4*4),
+      init_le32(header.crc), init_le32(footer.front_crc),
+      init_le32(footer.middle_crc), init_le32(footer.data_crc)
     };
 
     char exp_buf[CryptoKey::get_max_outbuf_size(sizeof(sigblock))];
@@ -78,27 +78,27 @@ int CephxSessionHandler::_calc_signature(Message *m, uint64_t *psig)
       return -1;
     }
 
-    *psig = *reinterpret_cast<__le64*>(exp_buf);
+    *psig = *reinterpret_cast<ceph_le64*>(exp_buf);
   } else {
     // newer mimic+ signatures
     struct {
-      __le32 header_crc;
-      __le32 front_crc;
-      __le32 front_len;
-      __le32 middle_crc;
-      __le32 middle_len;
-      __le32 data_crc;
-      __le32 data_len;
-      __le32 seq_lower_word;
+      ceph_le32 header_crc;
+      ceph_le32 front_crc;
+      ceph_le32 front_len;
+      ceph_le32 middle_crc;
+      ceph_le32 middle_len;
+      ceph_le32 data_crc;
+      ceph_le32 data_len;
+      ceph_le32 seq_lower_word;
     } __attribute__ ((packed)) sigblock = {
-      mswab<uint32_t>(header.crc),
-      mswab<uint32_t>(footer.front_crc),
-      mswab<uint32_t>(header.front_len),
-      mswab<uint32_t>(footer.middle_crc),
-      mswab<uint32_t>(header.middle_len),
-      mswab<uint32_t>(footer.data_crc),
-      mswab<uint32_t>(header.data_len),
-      mswab<uint32_t>(header.seq)
+      init_le32(header.crc),
+      init_le32(footer.front_crc),
+      init_le32(header.front_len),
+      init_le32(footer.middle_crc),
+      init_le32(header.middle_len),
+      init_le32(footer.data_crc),
+      init_le32(header.data_len),
+      init_le32(header.seq)
     };
 
     char exp_buf[CryptoKey::get_max_outbuf_size(sizeof(sigblock))];
@@ -119,7 +119,7 @@ int CephxSessionHandler::_calc_signature(Message *m, uint64_t *psig)
     }
 
     struct enc {
-      __le64 a, b, c, d;
+      ceph_le64 a, b, c, d;
     } *penc = reinterpret_cast<enc*>(exp_buf);
     *psig = penc->a ^ penc->b ^ penc->c ^ penc->d;
   }