From 2154be1a802a518aa80b5a29ad34eedfd4761aee Mon Sep 17 00:00:00 2001 From: Ulrich Weigand Date: Mon, 2 Sep 2019 21:23:47 +0200 Subject: [PATCH] cephx: Fix incorrect use of __le16/32/64 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 --- src/auth/cephx/CephxProtocol.cc | 4 +- src/auth/cephx/CephxSessionHandler.cc | 54 +++++++++++++-------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/auth/cephx/CephxProtocol.cc b/src/auth/cephx/CephxProtocol.cc index 5b7a2bcb86e..d975cbea09e 100644 --- a/src/auth/cephx/CephxProtocol.cc +++ b/src/auth/cephx/CephxProtocol.cc @@ -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; } diff --git a/src/auth/cephx/CephxSessionHandler.cc b/src/auth/cephx/CephxSessionHandler.cc index 6ef45eaa76f..966f87197d7 100644 --- a/src/auth/cephx/CephxSessionHandler.cc +++ b/src/auth/cephx/CephxSessionHandler.cc @@ -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(4*4), - mswab(header.crc), mswab(footer.front_crc), - mswab(footer.middle_crc), mswab(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(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(header.crc), - mswab(footer.front_crc), - mswab(header.front_len), - mswab(footer.middle_crc), - mswab(header.middle_len), - mswab(footer.data_crc), - mswab(header.data_len), - mswab(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(exp_buf); *psig = penc->a ^ penc->b ^ penc->c ^ penc->d; } -- 2.39.5