OSDN Git Service

libceph: implement CEPHX_V2 calculation mode
authorIlya Dryomov <idryomov@gmail.com>
Fri, 27 Jul 2018 17:25:32 +0000 (19:25 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 8 Dec 2018 12:05:10 +0000 (13:05 +0100)
commit cc255c76c70f7a87d97939621eae04b600d9f4a1 upstream.

Derive the signature from the entire buffer (both AES cipher blocks)
instead of using just the first half of the first block, leaving out
data_crc entirely.

This addresses CVE-2018-1129.

Link: http://tracker.ceph.com/issues/24837
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Reviewed-by: Sage Weil <sage@redhat.com>
[bwh: Backported to 4.9:
 - Define and test the feature bit in the old way
 - Don't change any other feature bits in ceph_features.h]
Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
include/linux/ceph/ceph_features.h
net/ceph/auth_x.c

index ae2f668..cf765db 100644 (file)
@@ -76,6 +76,7 @@
 // duplicated since it was introduced at the same time as CEPH_FEATURE_CRUSH_TUNABLES5
 #define CEPH_FEATURE_NEW_OSDOPREPLY_ENCODING   (1ULL<<58) /* New, v7 encoding */
 #define CEPH_FEATURE_FS_FILE_LAYOUT_V2       (1ULL<<58) /* file_layout_t */
+#define CEPH_FEATURE_CEPHX_V2  (1ULL<<61) // *do not share this bit*
 
 /*
  * The introduction of CEPH_FEATURE_OSD_SNAPMAPPER caused the feature
@@ -124,7 +125,8 @@ static inline u64 ceph_sanitize_features(u64 features)
         CEPH_FEATURE_MSGR_KEEPALIVE2 |         \
         CEPH_FEATURE_CRUSH_V4 |                \
         CEPH_FEATURE_CRUSH_TUNABLES5 |         \
-        CEPH_FEATURE_NEW_OSDOPREPLY_ENCODING)
+        CEPH_FEATURE_NEW_OSDOPREPLY_ENCODING | \
+        CEPH_FEATURE_CEPHX_V2)
 
 #define CEPH_FEATURES_REQUIRED_DEFAULT   \
        (CEPH_FEATURE_NOSRCADDR |        \
index 35a5694..fb1dec9 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <linux/ceph/decode.h>
 #include <linux/ceph/auth.h>
+#include <linux/ceph/ceph_features.h>
 #include <linux/ceph/libceph.h>
 #include <linux/ceph/messenger.h>
 
@@ -799,26 +800,64 @@ static int calc_signature(struct ceph_x_authorizer *au, struct ceph_msg *msg,
                          __le64 *psig)
 {
        void *enc_buf = au->enc_buf;
-       struct {
-               __le32 len;
-               __le32 header_crc;
-               __le32 front_crc;
-               __le32 middle_crc;
-               __le32 data_crc;
-       } __packed *sigblock = enc_buf + ceph_x_encrypt_offset();
        int ret;
 
-       sigblock->len = cpu_to_le32(4*sizeof(u32));
-       sigblock->header_crc = msg->hdr.crc;
-       sigblock->front_crc = msg->footer.front_crc;
-       sigblock->middle_crc = msg->footer.middle_crc;
-       sigblock->data_crc =  msg->footer.data_crc;
-       ret = ceph_x_encrypt(&au->session_key, enc_buf, CEPHX_AU_ENC_BUF_LEN,
-                            sizeof(*sigblock));
-       if (ret < 0)
-               return ret;
+       if (msg->con->peer_features & CEPH_FEATURE_CEPHX_V2) {
+               struct {
+                       __le32 len;
+                       __le32 header_crc;
+                       __le32 front_crc;
+                       __le32 middle_crc;
+                       __le32 data_crc;
+               } __packed *sigblock = enc_buf + ceph_x_encrypt_offset();
+
+               sigblock->len = cpu_to_le32(4*sizeof(u32));
+               sigblock->header_crc = msg->hdr.crc;
+               sigblock->front_crc = msg->footer.front_crc;
+               sigblock->middle_crc = msg->footer.middle_crc;
+               sigblock->data_crc =  msg->footer.data_crc;
+
+               ret = ceph_x_encrypt(&au->session_key, enc_buf,
+                                    CEPHX_AU_ENC_BUF_LEN, sizeof(*sigblock));
+               if (ret < 0)
+                       return ret;
+
+               *psig = *(__le64 *)(enc_buf + sizeof(u32));
+       } else {
+               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;
+               } __packed *sigblock = enc_buf;
+               struct {
+                       __le64 a, b, c, d;
+               } __packed *penc = enc_buf;
+               int ciphertext_len;
+
+               sigblock->header_crc = msg->hdr.crc;
+               sigblock->front_crc = msg->footer.front_crc;
+               sigblock->front_len = msg->hdr.front_len;
+               sigblock->middle_crc = msg->footer.middle_crc;
+               sigblock->middle_len = msg->hdr.middle_len;
+               sigblock->data_crc =  msg->footer.data_crc;
+               sigblock->data_len = msg->hdr.data_len;
+               sigblock->seq_lower_word = *(__le32 *)&msg->hdr.seq;
+
+               /* no leading len, no ceph_x_encrypt_header */
+               ret = ceph_crypt(&au->session_key, true, enc_buf,
+                                CEPHX_AU_ENC_BUF_LEN, sizeof(*sigblock),
+                                &ciphertext_len);
+               if (ret)
+                       return ret;
+
+               *psig = penc->a ^ penc->b ^ penc->c ^ penc->d;
+       }
 
-       *psig = *(__le64 *)(enc_buf + sizeof(u32));
        return 0;
 }