From 05bfc74418eb7be4aee9436efb826448c1c67108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordan=20DESNO=C3=8BS?= Date: Fri, 6 Nov 2026 09:05:57 +0100 Subject: [PATCH] sys-kernel/coreos-sources: Backport libceph aes256k support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ceph supports cephx keys of the aes256k type (CEPH_CRYPTO_AES256KRB5, based on AES256-CTS-HMAC384-192 per RFC 8009), and a cluster can be configured to only allow this type. Before Linux 7.0, the in-kernel Ceph client (rbd, CephFS) only supports the legacy AES type, so it cannot authenticate against such a cluster. Backport the libceph series that adds aes256k support, merged in Linux 7.0: commit 0ee8bccf7396 ("libceph: generalize ceph_x_encrypt_offset() and ceph_x_encrypt_buflen()") commit 6cec0b61aacc ("libceph: introduce ceph_crypto_key_prepare()") commit b7cc142dbafe ("libceph: add support for CEPH_CRYPTO_AES256KRB5") commit 8356b4b1103b ("libceph: adapt ceph_x_challenge_blob hashing and msgr1 message signing") The patches only needed context refreshes to apply on top of 6.18.58. No kernel config change is needed: CEPH_LIB now selects CRYPTO_KRB5, which is already built as a module. Signed-off-by: Jordan DESNOƋS --- .../changes/2026-11-06-libceph-aes256k.md | 1 + .../coreos-sources-6.18.58.ebuild | 4 + ...ze-ceph_x_encrypt_offset-and-ceph_x_.patch | 215 ++++++ ...ph-introduce-ceph_crypto_key_prepare.patch | 225 +++++++ ...d-support-for-CEPH_CRYPTO_AES256KRB5.patch | 622 ++++++++++++++++++ ...ph_x_challenge_blob-hashing-and-msgr.patch | 236 +++++++ 6 files changed, 1303 insertions(+) create mode 100644 changelog/changes/2026-11-06-libceph-aes256k.md create mode 100644 sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/files/6.18/z0008-libceph-generalize-ceph_x_encrypt_offset-and-ceph_x_.patch create mode 100644 sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/files/6.18/z0009-libceph-introduce-ceph_crypto_key_prepare.patch create mode 100644 sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/files/6.18/z0010-libceph-add-support-for-CEPH_CRYPTO_AES256KRB5.patch create mode 100644 sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/files/6.18/z0011-libceph-adapt-ceph_x_challenge_blob-hashing-and-msgr.patch diff --git a/changelog/changes/2026-11-06-libceph-aes256k.md b/changelog/changes/2026-11-06-libceph-aes256k.md new file mode 100644 index 00000000000..f6cebdec4ee --- /dev/null +++ b/changelog/changes/2026-11-06-libceph-aes256k.md @@ -0,0 +1 @@ +- Added support for the `aes256k` cephx key type to the kernel Ceph client (`rbd`, CephFS) by backporting the libceph patches from Linux 7.0, so that nodes can connect to Ceph clusters that only allow `aes256k` keys. ([scripts#4363](https://github.com/flatcar/scripts/pull/4363)) diff --git a/sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/coreos-sources-6.18.58.ebuild b/sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/coreos-sources-6.18.58.ebuild index 9ab3150e9a1..ad06320753e 100644 --- a/sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/coreos-sources-6.18.58.ebuild +++ b/sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/coreos-sources-6.18.58.ebuild @@ -42,4 +42,8 @@ UNIPATCH_LIST=" ${PATCH_DIR}/z0005-mtd-phram-slram-Disable-when-the-kernel-is-locked-do.patch \ ${PATCH_DIR}/z0006-arm64-add-kernel-config-option-to-lock-down-when-in-.patch \ ${PATCH_DIR}/z0007-tools-hv-fix-cross-compilation.patch \ + ${PATCH_DIR}/z0008-libceph-generalize-ceph_x_encrypt_offset-and-ceph_x_.patch \ + ${PATCH_DIR}/z0009-libceph-introduce-ceph_crypto_key_prepare.patch \ + ${PATCH_DIR}/z0010-libceph-add-support-for-CEPH_CRYPTO_AES256KRB5.patch \ + ${PATCH_DIR}/z0011-libceph-adapt-ceph_x_challenge_blob-hashing-and-msgr.patch \ " diff --git a/sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/files/6.18/z0008-libceph-generalize-ceph_x_encrypt_offset-and-ceph_x_.patch b/sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/files/6.18/z0008-libceph-generalize-ceph_x_encrypt_offset-and-ceph_x_.patch new file mode 100644 index 00000000000..26bf3bcedfb --- /dev/null +++ b/sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/files/6.18/z0008-libceph-generalize-ceph_x_encrypt_offset-and-ceph_x_.patch @@ -0,0 +1,215 @@ +From 0ee8bccf7396d50726c9c8dd3135fb64a9fe8426 Mon Sep 17 00:00:00 2001 +From: Ilya Dryomov +Date: Sat, 5 Jul 2025 11:28:21 +0200 +Subject: [PATCH] libceph: generalize ceph_x_encrypt_offset() and + ceph_x_encrypt_buflen() + +- introduce the notion of a data offset for ceph_x_encrypt_offset() + to allow for e.g. confounder to be prepended before the encryption + header in the future. For CEPH_CRYPTO_AES, the data offset is 0 + (i.e. nothing is prepended). + +- adjust ceph_x_encrypt_buflen() accordingly and make it account for + PKCS#7 padding that is used by CEPH_CRYPTO_AES precisely instead of + just always adding 16. + +Signed-off-by: Ilya Dryomov +--- + net/ceph/auth_x.c | 44 +++++++++++++++++++++++++++++--------------- + net/ceph/crypto.c | 25 +++++++++++++++++++++++++ + net/ceph/crypto.h | 2 ++ + 3 files changed, 56 insertions(+), 15 deletions(-) + +diff --git a/net/ceph/auth_x.c b/net/ceph/auth_x.c +index f805a81..d1c7b78 100644 +--- a/net/ceph/auth_x.c ++++ b/net/ceph/auth_x.c +@@ -44,23 +44,35 @@ static int ceph_x_should_authenticate(struct ceph_auth_client *ac) + return !!need; + } + +-static int ceph_x_encrypt_offset(void) ++static int __ceph_x_encrypt_offset(const struct ceph_crypto_key *key) + { +- return sizeof(u32) + sizeof(struct ceph_x_encrypt_header); ++ return ceph_crypt_data_offset(key) + ++ sizeof(struct ceph_x_encrypt_header); + } + +-static int ceph_x_encrypt_buflen(int ilen) ++static int ceph_x_encrypt_offset(const struct ceph_crypto_key *key) + { +- return ceph_x_encrypt_offset() + ilen + 16; ++ return sizeof(u32) + __ceph_x_encrypt_offset(key); ++} ++ ++/* ++ * AES: ciphertext_len | hdr | data... | padding ++ */ ++static int ceph_x_encrypt_buflen(const struct ceph_crypto_key *key, ++ int data_len) ++{ ++ int encrypt_len = sizeof(struct ceph_x_encrypt_header) + data_len; ++ return sizeof(u32) + ceph_crypt_buflen(key, encrypt_len); + } + + static int ceph_x_encrypt(struct ceph_crypto_key *secret, void *buf, + int buf_len, int plaintext_len) + { +- struct ceph_x_encrypt_header *hdr = buf + sizeof(u32); ++ struct ceph_x_encrypt_header *hdr; + int ciphertext_len; + int ret; + ++ hdr = buf + sizeof(u32) + ceph_crypt_data_offset(secret); + hdr->struct_v = 1; + hdr->magic = cpu_to_le64(CEPHX_ENC_MAGIC); + +@@ -77,7 +89,7 @@ static int ceph_x_encrypt(struct ceph_crypto_key *secret, void *buf, + static int __ceph_x_decrypt(struct ceph_crypto_key *secret, void *p, + int ciphertext_len) + { +- struct ceph_x_encrypt_header *hdr = p; ++ struct ceph_x_encrypt_header *hdr; + int plaintext_len; + int ret; + +@@ -91,6 +103,7 @@ static int __ceph_x_decrypt(struct ceph_crypto_key *secret, void *p, + return -EINVAL; + } + ++ hdr = p + ceph_crypt_data_offset(secret); + if (le64_to_cpu(hdr->magic) != CEPHX_ENC_MAGIC) { + pr_err("%s bad magic\n", __func__); + return -EINVAL; +@@ -198,7 +211,7 @@ static int process_one_ticket(struct ceph_auth_client *ac, + } + + /* blob for me */ +- dp = *p + ceph_x_encrypt_offset(); ++ dp = *p + ceph_x_encrypt_offset(secret); + ret = ceph_x_decrypt(secret, p, end); + if (ret < 0) + goto out; +@@ -225,7 +238,7 @@ static int process_one_ticket(struct ceph_auth_client *ac, + ceph_decode_8_safe(p, end, is_enc, bad); + if (is_enc) { + /* encrypted */ +- tp = *p + ceph_x_encrypt_offset(); ++ tp = *p + ceph_x_encrypt_offset(&th->session_key); + ret = ceph_x_decrypt(&th->session_key, p, end); + if (ret < 0) + goto out; +@@ -317,7 +330,7 @@ static int encrypt_authorizer(struct ceph_x_authorizer *au, + p = (void *)(msg_a + 1) + le32_to_cpu(msg_a->ticket_blob.blob_len); + end = au->buf->vec.iov_base + au->buf->vec.iov_len; + +- msg_b = p + ceph_x_encrypt_offset(); ++ msg_b = p + ceph_x_encrypt_offset(&au->session_key); + msg_b->struct_v = 2; + msg_b->nonce = cpu_to_le64(au->nonce); + if (server_challenge) { +@@ -373,7 +386,7 @@ static int ceph_x_build_authorizer(struct ceph_auth_client *ac, + goto out_au; + + maxlen = sizeof(*msg_a) + ticket_blob_len + +- ceph_x_encrypt_buflen(sizeof(*msg_b)); ++ ceph_x_encrypt_buflen(&au->session_key, sizeof(*msg_b)); + dout(" need len %d\n", maxlen); + if (au->buf && au->buf->alloc_len < maxlen) { + ceph_buffer_put(au->buf); +@@ -512,7 +525,7 @@ static int ceph_x_build_request(struct ceph_auth_client *ac, + struct ceph_x_authenticate *auth = (void *)(head + 1); + void *enc_buf = xi->auth_authorizer.enc_buf; + struct ceph_x_challenge_blob *blob = enc_buf + +- ceph_x_encrypt_offset(); ++ ceph_x_encrypt_offset(&xi->secret); + u64 *u; + + p = auth + 1; +@@ -639,7 +652,7 @@ static int handle_auth_session_key(struct ceph_auth_client *ac, u64 global_id, + ceph_decode_need(p, end, len, e_inval); + dout("%s connection secret blob len %d\n", __func__, len); + if (len > 0) { +- dp = *p + ceph_x_encrypt_offset(); ++ dp = *p + ceph_x_encrypt_offset(&th->session_key); + ret = ceph_x_decrypt(&th->session_key, p, *p + len); + if (ret < 0) + return ret; +@@ -816,7 +829,7 @@ static int decrypt_authorizer_challenge(struct ceph_crypto_key *secret, + return ret; + + dout("%s decrypted %d bytes\n", __func__, ret); +- dp = challenge + sizeof(struct ceph_x_encrypt_header); ++ dp = challenge + __ceph_x_encrypt_offset(secret); + dend = dp + ret; + + ceph_decode_skip_8(&dp, dend, e_inval); /* struct_v */ +@@ -863,7 +876,7 @@ static int decrypt_authorizer_reply(struct ceph_crypto_key *secret, + u8 struct_v; + int ret; + +- dp = *p + ceph_x_encrypt_offset(); ++ dp = *p + ceph_x_encrypt_offset(secret); + ret = ceph_x_decrypt(secret, p, end); + if (ret < 0) + return ret; +@@ -986,7 +999,8 @@ static int calc_signature(struct ceph_x_authorizer *au, struct ceph_msg *msg, + __le32 front_crc; + __le32 middle_crc; + __le32 data_crc; +- } __packed *sigblock = enc_buf + ceph_x_encrypt_offset(); ++ } __packed *sigblock = enc_buf + ++ ceph_x_encrypt_offset(&au->session_key); + + sigblock->len = cpu_to_le32(4*sizeof(u32)); + sigblock->header_crc = msg->hdr.crc; +diff --git a/net/ceph/crypto.c b/net/ceph/crypto.c +index 5601732..2b98daf 100644 +--- a/net/ceph/crypto.c ++++ b/net/ceph/crypto.c +@@ -285,6 +285,31 @@ int ceph_crypt(const struct ceph_crypto_key *key, bool encrypt, + } + } + ++int ceph_crypt_data_offset(const struct ceph_crypto_key *key) ++{ ++ switch (key->type) { ++ case CEPH_CRYPTO_NONE: ++ case CEPH_CRYPTO_AES: ++ return 0; ++ default: ++ BUG(); ++ } ++} ++ ++int ceph_crypt_buflen(const struct ceph_crypto_key *key, int data_len) ++{ ++ switch (key->type) { ++ case CEPH_CRYPTO_NONE: ++ return data_len; ++ case CEPH_CRYPTO_AES: ++ /* PKCS#7 padding at the end */ ++ return data_len + AES_BLOCK_SIZE - ++ (data_len & (AES_BLOCK_SIZE - 1)); ++ default: ++ BUG(); ++ } ++} ++ + static int ceph_key_preparse(struct key_preparsed_payload *prep) + { + struct ceph_crypto_key *ckey; +diff --git a/net/ceph/crypto.h b/net/ceph/crypto.h +index a20bad6..736ec6d 100644 +--- a/net/ceph/crypto.h ++++ b/net/ceph/crypto.h +@@ -28,6 +28,8 @@ void ceph_crypto_key_destroy(struct ceph_crypto_key *key); + /* crypto.c */ + int ceph_crypt(const struct ceph_crypto_key *key, bool encrypt, + void *buf, int buf_len, int in_len, int *pout_len); ++int ceph_crypt_data_offset(const struct ceph_crypto_key *key); ++int ceph_crypt_buflen(const struct ceph_crypto_key *key, int data_len); + int ceph_crypto_init(void); + void ceph_crypto_shutdown(void); + diff --git a/sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/files/6.18/z0009-libceph-introduce-ceph_crypto_key_prepare.patch b/sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/files/6.18/z0009-libceph-introduce-ceph_crypto_key_prepare.patch new file mode 100644 index 00000000000..923413c6a9d --- /dev/null +++ b/sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/files/6.18/z0009-libceph-introduce-ceph_crypto_key_prepare.patch @@ -0,0 +1,225 @@ +From 6cec0b61aacce4da5125b21c718189f0dc11eb51 Mon Sep 17 00:00:00 2001 +From: Ilya Dryomov +Date: Mon, 22 Dec 2025 19:44:24 +0100 +Subject: [PATCH] libceph: introduce ceph_crypto_key_prepare() + +In preparation for bringing in a new encryption scheme/key type, +decouple decoding or cloning the key from allocating required crypto +API objects and setting them up. The rationale is that a) in some +cases a shallow clone is sufficient and b) ceph_crypto_key_prepare() +may grow additional parameters that would be inconvenient to provide +at the point the key is originally decoded. + +Signed-off-by: Ilya Dryomov +--- + net/ceph/auth_x.c | 26 +++++++++++++---- + net/ceph/crypto.c | 73 +++++++++++++++++++++++------------------------ + net/ceph/crypto.h | 1 + + 3 files changed, 57 insertions(+), 43 deletions(-) + +diff --git a/net/ceph/auth_x.c b/net/ceph/auth_x.c +index d1c7b78..a23e0e2 100644 +--- a/net/ceph/auth_x.c ++++ b/net/ceph/auth_x.c +@@ -226,6 +226,10 @@ static int process_one_ticket(struct ceph_auth_client *ac, + if (ret) + goto out; + ++ ret = ceph_crypto_key_prepare(&new_session_key); ++ if (ret) ++ goto out; ++ + ceph_decode_need(&dp, dend, sizeof(struct ceph_timespec), bad); + ceph_decode_timespec64(&validity, dp); + dp += sizeof(struct ceph_timespec); +@@ -385,6 +389,10 @@ static int ceph_x_build_authorizer(struct ceph_auth_client *ac, + if (ret) + goto out_au; + ++ ret = ceph_crypto_key_prepare(&au->session_key); ++ if (ret) ++ goto out_au; ++ + maxlen = sizeof(*msg_a) + ticket_blob_len + + ceph_x_encrypt_buflen(&au->session_key, sizeof(*msg_b)); + dout(" need len %d\n", maxlen); +@@ -1118,21 +1126,26 @@ int ceph_x_init(struct ceph_auth_client *ac) + int ret; + + dout("ceph_x_init %p\n", ac); +- ret = -ENOMEM; + xi = kzalloc(sizeof(*xi), GFP_NOFS); + if (!xi) +- goto out; ++ return -ENOMEM; + + ret = -EINVAL; + if (!ac->key) { + pr_err("no secret set (for auth_x protocol)\n"); +- goto out_nomem; ++ goto err_xi; + } + + ret = ceph_crypto_key_clone(&xi->secret, ac->key); + if (ret < 0) { + pr_err("cannot clone key: %d\n", ret); +- goto out_nomem; ++ goto err_xi; ++ } ++ ++ ret = ceph_crypto_key_prepare(&xi->secret); ++ if (ret) { ++ pr_err("cannot prepare key: %d\n", ret); ++ goto err_secret; + } + + xi->starting = true; +@@ -1143,8 +1156,9 @@ int ceph_x_init(struct ceph_auth_client *ac) + ac->ops = &ceph_x_ops; + return 0; + +-out_nomem: ++err_secret: ++ ceph_crypto_key_destroy(&xi->secret); ++err_xi: + kfree(xi); +-out: + return ret; + } +diff --git a/net/ceph/crypto.c b/net/ceph/crypto.c +index 2b98daf..3453dc3 100644 +--- a/net/ceph/crypto.c ++++ b/net/ceph/crypto.c +@@ -16,65 +16,61 @@ + #include + #include "crypto.h" + +-/* +- * Set ->key and ->tfm. The rest of the key should be filled in before +- * this function is called. +- */ +-static int set_secret(struct ceph_crypto_key *key, void *buf) ++static int set_aes_tfm(struct ceph_crypto_key *key) + { + unsigned int noio_flag; + int ret; + +- key->key = NULL; +- key->tfm = NULL; +- +- switch (key->type) { +- case CEPH_CRYPTO_NONE: +- return 0; /* nothing to do */ +- case CEPH_CRYPTO_AES: +- break; +- default: +- return -ENOTSUPP; +- } +- +- key->key = kmemdup(buf, key->len, GFP_NOIO); +- if (!key->key) { +- ret = -ENOMEM; +- goto fail; +- } +- +- /* crypto_alloc_sync_skcipher() allocates with GFP_KERNEL */ + noio_flag = memalloc_noio_save(); + key->tfm = crypto_alloc_sync_skcipher("cbc(aes)", 0, 0); + memalloc_noio_restore(noio_flag); + if (IS_ERR(key->tfm)) { + ret = PTR_ERR(key->tfm); + key->tfm = NULL; +- goto fail; ++ return ret; + } + + ret = crypto_sync_skcipher_setkey(key->tfm, key->key, key->len); + if (ret) +- goto fail; ++ return ret; + + return 0; +- +-fail: +- ceph_crypto_key_destroy(key); +- return ret; + } + ++int ceph_crypto_key_prepare(struct ceph_crypto_key *key) ++{ ++ switch (key->type) { ++ case CEPH_CRYPTO_NONE: ++ return 0; /* nothing to do */ ++ case CEPH_CRYPTO_AES: ++ return set_aes_tfm(key); ++ default: ++ return -ENOTSUPP; ++ } ++} ++ ++/* ++ * @dst should be zeroed before this function is called. ++ */ + int ceph_crypto_key_clone(struct ceph_crypto_key *dst, + const struct ceph_crypto_key *src) + { +- memcpy(dst, src, sizeof(struct ceph_crypto_key)); +- return set_secret(dst, src->key); ++ dst->type = src->type; ++ dst->created = src->created; ++ dst->len = src->len; ++ ++ dst->key = kmemdup(src->key, src->len, GFP_NOIO); ++ if (!dst->key) ++ return -ENOMEM; ++ ++ return 0; + } + ++/* ++ * @key should be zeroed before this function is called. ++ */ + int ceph_crypto_key_decode(struct ceph_crypto_key *key, void **p, void *end) + { +- int ret; +- + ceph_decode_need(p, end, 2*sizeof(u16) + sizeof(key->created), bad); + key->type = ceph_decode_16(p); + ceph_decode_copy(p, &key->created, sizeof(key->created)); +@@ -85,10 +81,13 @@ int ceph_crypto_key_decode(struct ceph_crypto_key *key, void **p, void *end) + return -EINVAL; + } + +- ret = set_secret(key, *p); ++ key->key = kmemdup(*p, key->len, GFP_NOIO); ++ if (!key->key) ++ return -ENOMEM; ++ + memzero_explicit(*p, key->len); + *p += key->len; +- return ret; ++ return 0; + + bad: + dout("failed to decode crypto key\n"); +@@ -322,7 +321,7 @@ static int ceph_key_preparse(struct key_preparsed_payload *prep) + goto err; + + ret = -ENOMEM; +- ckey = kmalloc(sizeof(*ckey), GFP_KERNEL); ++ ckey = kzalloc(sizeof(*ckey), GFP_KERNEL); + if (!ckey) + goto err; + +diff --git a/net/ceph/crypto.h b/net/ceph/crypto.h +index 736ec6d..2b8f8f6 100644 +--- a/net/ceph/crypto.h ++++ b/net/ceph/crypto.h +@@ -19,6 +19,7 @@ struct ceph_crypto_key { + struct crypto_sync_skcipher *tfm; + }; + ++int ceph_crypto_key_prepare(struct ceph_crypto_key *key); + int ceph_crypto_key_clone(struct ceph_crypto_key *dst, + const struct ceph_crypto_key *src); + int ceph_crypto_key_decode(struct ceph_crypto_key *key, void **p, void *end); diff --git a/sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/files/6.18/z0010-libceph-add-support-for-CEPH_CRYPTO_AES256KRB5.patch b/sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/files/6.18/z0010-libceph-add-support-for-CEPH_CRYPTO_AES256KRB5.patch new file mode 100644 index 00000000000..2bad4cdb663 --- /dev/null +++ b/sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/files/6.18/z0010-libceph-add-support-for-CEPH_CRYPTO_AES256KRB5.patch @@ -0,0 +1,622 @@ +From b7cc142dbafeaf6c053284ca9121b9f70b6d6d06 Mon Sep 17 00:00:00 2001 +From: Ilya Dryomov +Date: Mon, 22 Dec 2025 20:41:27 +0100 +Subject: [PATCH] libceph: add support for CEPH_CRYPTO_AES256KRB5 + +This is based on AES256-CTS-HMAC384-192 crypto algorithm per RFC 8009 +(i.e. Kerberos 5, hence the name) with custom-defined key usage numbers. +The implementation allows a given key to have/be linked to between one +and three usage numbers. + +The existing CEPH_CRYPTO_AES remains in place and unchanged. The +usage_slot parameter that needed to be added to ceph_crypt() and its +wrappers is simply ignored there. + +Signed-off-by: Ilya Dryomov +--- + include/linux/ceph/ceph_fs.h | 5 +- + net/ceph/Kconfig | 1 + + net/ceph/auth_x.c | 88 ++++++++++++++------ + net/ceph/auth_x_protocol.h | 38 +++++++++ + net/ceph/crypto.c | 157 +++++++++++++++++++++++++++++++---- + net/ceph/crypto.h | 16 +++- + 6 files changed, 257 insertions(+), 48 deletions(-) + +diff --git a/include/linux/ceph/ceph_fs.h b/include/linux/ceph/ceph_fs.h +index 08e5dbe..69ac3e5 100644 +--- a/include/linux/ceph/ceph_fs.h ++++ b/include/linux/ceph/ceph_fs.h +@@ -89,8 +89,9 @@ struct ceph_dir_layout { + } __attribute__ ((packed)); + + /* crypto algorithms */ +-#define CEPH_CRYPTO_NONE 0x0 +-#define CEPH_CRYPTO_AES 0x1 ++#define CEPH_CRYPTO_NONE 0x0 ++#define CEPH_CRYPTO_AES 0x1 ++#define CEPH_CRYPTO_AES256KRB5 0x2 /* AES256-CTS-HMAC384-192 */ + + #define CEPH_AES_IV "cephsageyudagreg" + +diff --git a/net/ceph/Kconfig b/net/ceph/Kconfig +index ea60e3e..7e2528c 100644 +--- a/net/ceph/Kconfig ++++ b/net/ceph/Kconfig +@@ -6,6 +6,7 @@ config CEPH_LIB + select CRYPTO_AES + select CRYPTO_CBC + select CRYPTO_GCM ++ select CRYPTO_KRB5 + select CRYPTO_LIB_SHA256 + select CRYPTO + select KEYS +diff --git a/net/ceph/auth_x.c b/net/ceph/auth_x.c +index a23e0e2..966a382 100644 +--- a/net/ceph/auth_x.c ++++ b/net/ceph/auth_x.c +@@ -17,6 +17,22 @@ + #include "auth_x.h" + #include "auth_x_protocol.h" + ++static const u32 ticket_key_usages[] = { ++ CEPHX_KEY_USAGE_TICKET_SESSION_KEY, ++ CEPHX_KEY_USAGE_TICKET_BLOB, ++ CEPHX_KEY_USAGE_AUTH_CONNECTION_SECRET ++}; ++ ++static const u32 authorizer_key_usages[] = { ++ CEPHX_KEY_USAGE_AUTHORIZE, ++ CEPHX_KEY_USAGE_AUTHORIZE_CHALLENGE, ++ CEPHX_KEY_USAGE_AUTHORIZE_REPLY ++}; ++ ++static const u32 client_key_usages[] = { ++ CEPHX_KEY_USAGE_TICKET_SESSION_KEY ++}; ++ + static void ceph_x_validate_tickets(struct ceph_auth_client *ac, int *pneed); + + static int ceph_x_is_authenticated(struct ceph_auth_client *ac) +@@ -57,6 +73,7 @@ static int ceph_x_encrypt_offset(const struct ceph_crypto_key *key) + + /* + * AES: ciphertext_len | hdr | data... | padding ++ * AES256KRB5: ciphertext_len | confounder | hdr | data... | hmac + */ + static int ceph_x_encrypt_buflen(const struct ceph_crypto_key *key, + int data_len) +@@ -65,19 +82,19 @@ static int ceph_x_encrypt_buflen(const struct ceph_crypto_key *key, + return sizeof(u32) + ceph_crypt_buflen(key, encrypt_len); + } + +-static int ceph_x_encrypt(struct ceph_crypto_key *secret, void *buf, +- int buf_len, int plaintext_len) ++static int ceph_x_encrypt(const struct ceph_crypto_key *key, int usage_slot, ++ void *buf, int buf_len, int plaintext_len) + { + struct ceph_x_encrypt_header *hdr; + int ciphertext_len; + int ret; + +- hdr = buf + sizeof(u32) + ceph_crypt_data_offset(secret); ++ hdr = buf + sizeof(u32) + ceph_crypt_data_offset(key); + hdr->struct_v = 1; + hdr->magic = cpu_to_le64(CEPHX_ENC_MAGIC); + +- ret = ceph_crypt(secret, true, buf + sizeof(u32), buf_len - sizeof(u32), +- plaintext_len + sizeof(struct ceph_x_encrypt_header), ++ ret = ceph_crypt(key, usage_slot, true, buf + sizeof(u32), ++ buf_len - sizeof(u32), plaintext_len + sizeof(*hdr), + &ciphertext_len); + if (ret) + return ret; +@@ -86,15 +103,15 @@ static int ceph_x_encrypt(struct ceph_crypto_key *secret, void *buf, + return sizeof(u32) + ciphertext_len; + } + +-static int __ceph_x_decrypt(struct ceph_crypto_key *secret, void *p, +- int ciphertext_len) ++static int __ceph_x_decrypt(const struct ceph_crypto_key *key, int usage_slot, ++ void *p, int ciphertext_len) + { + struct ceph_x_encrypt_header *hdr; + int plaintext_len; + int ret; + +- ret = ceph_crypt(secret, false, p, ciphertext_len, ciphertext_len, +- &plaintext_len); ++ ret = ceph_crypt(key, usage_slot, false, p, ciphertext_len, ++ ciphertext_len, &plaintext_len); + if (ret) + return ret; + +@@ -103,7 +120,7 @@ static int __ceph_x_decrypt(struct ceph_crypto_key *secret, void *p, + return -EINVAL; + } + +- hdr = p + ceph_crypt_data_offset(secret); ++ hdr = p + ceph_crypt_data_offset(key); + if (le64_to_cpu(hdr->magic) != CEPHX_ENC_MAGIC) { + pr_err("%s bad magic\n", __func__); + return -EINVAL; +@@ -112,7 +129,8 @@ static int __ceph_x_decrypt(struct ceph_crypto_key *secret, void *p, + return plaintext_len - sizeof(*hdr); + } + +-static int ceph_x_decrypt(struct ceph_crypto_key *secret, void **p, void *end) ++static int ceph_x_decrypt(const struct ceph_crypto_key *key, int usage_slot, ++ void **p, void *end) + { + int ciphertext_len; + int ret; +@@ -120,7 +138,7 @@ static int ceph_x_decrypt(struct ceph_crypto_key *secret, void **p, void *end) + ceph_decode_32_safe(p, end, ciphertext_len, e_inval); + ceph_decode_need(p, end, ciphertext_len, e_inval); + +- ret = __ceph_x_decrypt(secret, *p, ciphertext_len); ++ ret = __ceph_x_decrypt(key, usage_slot, *p, ciphertext_len); + if (ret < 0) + return ret; + +@@ -212,7 +230,9 @@ static int process_one_ticket(struct ceph_auth_client *ac, + + /* blob for me */ + dp = *p + ceph_x_encrypt_offset(secret); +- ret = ceph_x_decrypt(secret, p, end); ++ ret = ceph_x_decrypt(secret, ++ 0 /* CEPHX_KEY_USAGE_TICKET_SESSION_KEY */, ++ p, end); + if (ret < 0) + goto out; + dout(" decrypted %d bytes\n", ret); +@@ -226,7 +246,8 @@ static int process_one_ticket(struct ceph_auth_client *ac, + if (ret) + goto out; + +- ret = ceph_crypto_key_prepare(&new_session_key); ++ ret = ceph_crypto_key_prepare(&new_session_key, ticket_key_usages, ++ ARRAY_SIZE(ticket_key_usages)); + if (ret) + goto out; + +@@ -243,7 +264,9 @@ static int process_one_ticket(struct ceph_auth_client *ac, + if (is_enc) { + /* encrypted */ + tp = *p + ceph_x_encrypt_offset(&th->session_key); +- ret = ceph_x_decrypt(&th->session_key, p, end); ++ ret = ceph_x_decrypt(&th->session_key, ++ 1 /* CEPHX_KEY_USAGE_TICKET_BLOB */, ++ p, end); + if (ret < 0) + goto out; + dout(" encrypted ticket, decrypted %d bytes\n", ret); +@@ -346,7 +369,9 @@ static int encrypt_authorizer(struct ceph_x_authorizer *au, + msg_b->server_challenge_plus_one = 0; + } + +- ret = ceph_x_encrypt(&au->session_key, p, end - p, sizeof(*msg_b)); ++ ret = ceph_x_encrypt(&au->session_key, ++ 0 /* CEPHX_KEY_USAGE_AUTHORIZE */, ++ p, end - p, sizeof(*msg_b)); + if (ret < 0) + return ret; + +@@ -389,7 +414,8 @@ static int ceph_x_build_authorizer(struct ceph_auth_client *ac, + if (ret) + goto out_au; + +- ret = ceph_crypto_key_prepare(&au->session_key); ++ ret = ceph_crypto_key_prepare(&au->session_key, authorizer_key_usages, ++ ARRAY_SIZE(authorizer_key_usages)); + if (ret) + goto out_au; + +@@ -547,7 +573,8 @@ static int ceph_x_build_request(struct ceph_auth_client *ac, + get_random_bytes(&auth->client_challenge, sizeof(u64)); + blob->client_challenge = auth->client_challenge; + blob->server_challenge = cpu_to_le64(xi->server_challenge); +- ret = ceph_x_encrypt(&xi->secret, enc_buf, CEPHX_AU_ENC_BUF_LEN, ++ ret = ceph_x_encrypt(&xi->secret, 0 /* dummy */, ++ enc_buf, CEPHX_AU_ENC_BUF_LEN, + sizeof(*blob)); + if (ret < 0) + return ret; +@@ -661,7 +688,9 @@ static int handle_auth_session_key(struct ceph_auth_client *ac, u64 global_id, + dout("%s connection secret blob len %d\n", __func__, len); + if (len > 0) { + dp = *p + ceph_x_encrypt_offset(&th->session_key); +- ret = ceph_x_decrypt(&th->session_key, p, *p + len); ++ ret = ceph_x_decrypt(&th->session_key, ++ 2 /* CEPHX_KEY_USAGE_AUTH_CONNECTION_SECRET */, ++ p, *p + len); + if (ret < 0) + return ret; + +@@ -832,7 +861,9 @@ static int decrypt_authorizer_challenge(struct ceph_crypto_key *secret, + int ret; + + /* no leading len */ +- ret = __ceph_x_decrypt(secret, challenge, challenge_len); ++ ret = __ceph_x_decrypt(secret, ++ 1 /* CEPHX_KEY_USAGE_AUTHORIZE_CHALLENGE */, ++ challenge, challenge_len); + if (ret < 0) + return ret; + +@@ -885,7 +916,8 @@ static int decrypt_authorizer_reply(struct ceph_crypto_key *secret, + int ret; + + dp = *p + ceph_x_encrypt_offset(secret); +- ret = ceph_x_decrypt(secret, p, end); ++ ret = ceph_x_decrypt(secret, 2 /* CEPHX_KEY_USAGE_AUTHORIZE_REPLY */, ++ p, end); + if (ret < 0) + return ret; + +@@ -1016,8 +1048,9 @@ static int calc_signature(struct ceph_x_authorizer *au, struct ceph_msg *msg, + 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)); ++ ret = ceph_x_encrypt(&au->session_key, 0 /* dummy */, ++ enc_buf, CEPHX_AU_ENC_BUF_LEN, ++ sizeof(*sigblock)); + if (ret < 0) + return ret; + +@@ -1048,9 +1081,9 @@ static int calc_signature(struct ceph_x_authorizer *au, struct ceph_msg *msg, + 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); ++ ret = ceph_crypt(&au->session_key, 0 /* dummy */, ++ true, enc_buf, CEPHX_AU_ENC_BUF_LEN, ++ sizeof(*sigblock), &ciphertext_len); + if (ret) + return ret; + +@@ -1142,7 +1175,8 @@ int ceph_x_init(struct ceph_auth_client *ac) + goto err_xi; + } + +- ret = ceph_crypto_key_prepare(&xi->secret); ++ ret = ceph_crypto_key_prepare(&xi->secret, client_key_usages, ++ ARRAY_SIZE(client_key_usages)); + if (ret) { + pr_err("cannot prepare key: %d\n", ret); + goto err_secret; +diff --git a/net/ceph/auth_x_protocol.h b/net/ceph/auth_x_protocol.h +index 9c60fee..d097b36 100644 +--- a/net/ceph/auth_x_protocol.h ++++ b/net/ceph/auth_x_protocol.h +@@ -6,6 +6,44 @@ + #define CEPHX_GET_PRINCIPAL_SESSION_KEY 0x0200 + #define CEPHX_GET_ROTATING_KEY 0x0400 + ++/* Client <-> AuthMonitor */ ++/* ++ * The AUTH session's connection secret: encrypted with the AUTH ++ * ticket session key ++ */ ++#define CEPHX_KEY_USAGE_AUTH_CONNECTION_SECRET 0x03 ++/* ++ * The ticket's blob for the client ("blob for me", contains the ++ * session key): encrypted with the client's secret key in case of ++ * the AUTH ticket and the AUTH ticket session key in case of other ++ * service tickets ++ */ ++#define CEPHX_KEY_USAGE_TICKET_SESSION_KEY 0x04 ++/* ++ * The ticket's blob for the service (ceph_x_ticket_blob): possibly ++ * encrypted with the old AUTH ticket session key in case of the AUTH ++ * ticket and not encrypted in case of other service tickets ++ */ ++#define CEPHX_KEY_USAGE_TICKET_BLOB 0x05 ++ ++/* Client <-> Service */ ++/* ++ * The client's authorization request (ceph_x_authorize_b): ++ * encrypted with the service ticket session key ++ */ ++#define CEPHX_KEY_USAGE_AUTHORIZE 0x10 ++/* ++ * The service's challenge (ceph_x_authorize_challenge): ++ * encrypted with the service ticket session key ++ */ ++#define CEPHX_KEY_USAGE_AUTHORIZE_CHALLENGE 0x11 ++/* ++ * The service's final reply (ceph_x_authorize_reply + the service ++ * session's connection secret): encrypted with the service ticket ++ * session key ++ */ ++#define CEPHX_KEY_USAGE_AUTHORIZE_REPLY 0x12 ++ + /* common bits */ + struct ceph_x_ticket_blob { + __u8 struct_v; +diff --git a/net/ceph/crypto.c b/net/ceph/crypto.c +index 3453dc3..b54085d 100644 +--- a/net/ceph/crypto.c ++++ b/net/ceph/crypto.c +@@ -7,6 +7,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -22,28 +23,68 @@ static int set_aes_tfm(struct ceph_crypto_key *key) + int ret; + + noio_flag = memalloc_noio_save(); +- key->tfm = crypto_alloc_sync_skcipher("cbc(aes)", 0, 0); ++ key->aes_tfm = crypto_alloc_sync_skcipher("cbc(aes)", 0, 0); + memalloc_noio_restore(noio_flag); +- if (IS_ERR(key->tfm)) { +- ret = PTR_ERR(key->tfm); +- key->tfm = NULL; ++ if (IS_ERR(key->aes_tfm)) { ++ ret = PTR_ERR(key->aes_tfm); ++ key->aes_tfm = NULL; + return ret; + } + +- ret = crypto_sync_skcipher_setkey(key->tfm, key->key, key->len); ++ ret = crypto_sync_skcipher_setkey(key->aes_tfm, key->key, key->len); + if (ret) + return ret; + + return 0; + } + +-int ceph_crypto_key_prepare(struct ceph_crypto_key *key) ++static int set_krb5_tfms(struct ceph_crypto_key *key, const u32 *key_usages, ++ int key_usage_cnt) ++{ ++ struct krb5_buffer TK = { .len = key->len, .data = key->key }; ++ unsigned int noio_flag; ++ int ret = 0; ++ int i; ++ ++ if (WARN_ON_ONCE(key_usage_cnt > ARRAY_SIZE(key->krb5_tfms))) ++ return -EINVAL; ++ ++ key->krb5_type = crypto_krb5_find_enctype( ++ KRB5_ENCTYPE_AES256_CTS_HMAC_SHA384_192); ++ if (!key->krb5_type) ++ return -ENOPKG; ++ ++ /* ++ * Despite crypto_krb5_prepare_encryption() taking a gfp mask, ++ * crypto_alloc_aead() inside of it allocates with GFP_KERNEL. ++ */ ++ noio_flag = memalloc_noio_save(); ++ for (i = 0; i < key_usage_cnt; i++) { ++ key->krb5_tfms[i] = crypto_krb5_prepare_encryption( ++ key->krb5_type, &TK, key_usages[i], ++ GFP_NOIO); ++ if (IS_ERR(key->krb5_tfms[i])) { ++ ret = PTR_ERR(key->krb5_tfms[i]); ++ key->krb5_tfms[i] = NULL; ++ goto out_flag; ++ } ++ } ++ ++out_flag: ++ memalloc_noio_restore(noio_flag); ++ return ret; ++} ++ ++int ceph_crypto_key_prepare(struct ceph_crypto_key *key, ++ const u32 *key_usages, int key_usage_cnt) + { + switch (key->type) { + case CEPH_CRYPTO_NONE: + return 0; /* nothing to do */ + case CEPH_CRYPTO_AES: + return set_aes_tfm(key); ++ case CEPH_CRYPTO_AES256KRB5: ++ return set_krb5_tfms(key, key_usages, key_usage_cnt); + default: + return -ENOTSUPP; + } +@@ -123,12 +164,25 @@ int ceph_crypto_key_unarmor(struct ceph_crypto_key *key, const char *inkey) + + void ceph_crypto_key_destroy(struct ceph_crypto_key *key) + { +- if (key) { +- kfree_sensitive(key->key); +- key->key = NULL; +- if (key->tfm) { +- crypto_free_sync_skcipher(key->tfm); +- key->tfm = NULL; ++ int i; ++ ++ if (!key) ++ return; ++ ++ kfree_sensitive(key->key); ++ key->key = NULL; ++ ++ if (key->type == CEPH_CRYPTO_AES) { ++ if (key->aes_tfm) { ++ crypto_free_sync_skcipher(key->aes_tfm); ++ key->aes_tfm = NULL; ++ } ++ } else if (key->type == CEPH_CRYPTO_AES256KRB5) { ++ for (i = 0; i < ARRAY_SIZE(key->krb5_tfms); i++) { ++ if (key->krb5_tfms[i]) { ++ crypto_free_aead(key->krb5_tfms[i]); ++ key->krb5_tfms[i] = NULL; ++ } + } + } + } +@@ -208,7 +262,7 @@ static void teardown_sgtable(struct sg_table *sgt) + static int ceph_aes_crypt(const struct ceph_crypto_key *key, bool encrypt, + void *buf, int buf_len, int in_len, int *pout_len) + { +- SYNC_SKCIPHER_REQUEST_ON_STACK(req, key->tfm); ++ SYNC_SKCIPHER_REQUEST_ON_STACK(req, key->aes_tfm); + struct sg_table sgt; + struct scatterlist prealloc_sg; + char iv[AES_BLOCK_SIZE] __aligned(8); +@@ -224,7 +278,7 @@ static int ceph_aes_crypt(const struct ceph_crypto_key *key, bool encrypt, + return ret; + + memcpy(iv, aes_iv, AES_BLOCK_SIZE); +- skcipher_request_set_sync_tfm(req, key->tfm); ++ skcipher_request_set_sync_tfm(req, key->aes_tfm); + skcipher_request_set_callback(req, 0, NULL, NULL); + skcipher_request_set_crypt(req, sgt.sgl, sgt.sgl, crypt_len, iv); + +@@ -269,7 +323,68 @@ out_sgt: + return ret; + } + +-int ceph_crypt(const struct ceph_crypto_key *key, bool encrypt, ++static int ceph_krb5_encrypt(const struct ceph_crypto_key *key, int usage_slot, ++ void *buf, int buf_len, int in_len, int *pout_len) ++{ ++ struct sg_table sgt; ++ struct scatterlist prealloc_sg; ++ int ret; ++ ++ if (WARN_ON_ONCE(usage_slot >= ARRAY_SIZE(key->krb5_tfms))) ++ return -EINVAL; ++ ++ ret = setup_sgtable(&sgt, &prealloc_sg, buf, buf_len); ++ if (ret) ++ return ret; ++ ++ ret = crypto_krb5_encrypt(key->krb5_type, key->krb5_tfms[usage_slot], ++ sgt.sgl, sgt.nents, buf_len, AES_BLOCK_SIZE, ++ in_len, false); ++ if (ret < 0) { ++ pr_err("%s encrypt failed: %d\n", __func__, ret); ++ goto out_sgt; ++ } ++ ++ *pout_len = ret; ++ ret = 0; ++ ++out_sgt: ++ teardown_sgtable(&sgt); ++ return ret; ++} ++ ++static int ceph_krb5_decrypt(const struct ceph_crypto_key *key, int usage_slot, ++ void *buf, int buf_len, int in_len, int *pout_len) ++{ ++ struct sg_table sgt; ++ struct scatterlist prealloc_sg; ++ size_t data_off = 0; ++ size_t data_len = in_len; ++ int ret; ++ ++ if (WARN_ON_ONCE(usage_slot >= ARRAY_SIZE(key->krb5_tfms))) ++ return -EINVAL; ++ ++ ret = setup_sgtable(&sgt, &prealloc_sg, buf, in_len); ++ if (ret) ++ return ret; ++ ++ ret = crypto_krb5_decrypt(key->krb5_type, key->krb5_tfms[usage_slot], ++ sgt.sgl, sgt.nents, &data_off, &data_len); ++ if (ret) { ++ pr_err("%s decrypt failed: %d\n", __func__, ret); ++ goto out_sgt; ++ } ++ ++ WARN_ON(data_off != AES_BLOCK_SIZE); ++ *pout_len = data_len; ++ ++out_sgt: ++ teardown_sgtable(&sgt); ++ return ret; ++} ++ ++int ceph_crypt(const struct ceph_crypto_key *key, int usage_slot, bool encrypt, + void *buf, int buf_len, int in_len, int *pout_len) + { + switch (key->type) { +@@ -279,6 +394,12 @@ int ceph_crypt(const struct ceph_crypto_key *key, bool encrypt, + case CEPH_CRYPTO_AES: + return ceph_aes_crypt(key, encrypt, buf, buf_len, in_len, + pout_len); ++ case CEPH_CRYPTO_AES256KRB5: ++ return encrypt ? ++ ceph_krb5_encrypt(key, usage_slot, buf, buf_len, in_len, ++ pout_len) : ++ ceph_krb5_decrypt(key, usage_slot, buf, buf_len, in_len, ++ pout_len); + default: + return -ENOTSUPP; + } +@@ -290,6 +411,9 @@ int ceph_crypt_data_offset(const struct ceph_crypto_key *key) + case CEPH_CRYPTO_NONE: + case CEPH_CRYPTO_AES: + return 0; ++ case CEPH_CRYPTO_AES256KRB5: ++ /* confounder */ ++ return AES_BLOCK_SIZE; + default: + BUG(); + } +@@ -304,6 +428,9 @@ int ceph_crypt_buflen(const struct ceph_crypto_key *key, int data_len) + /* PKCS#7 padding at the end */ + return data_len + AES_BLOCK_SIZE - + (data_len & (AES_BLOCK_SIZE - 1)); ++ case CEPH_CRYPTO_AES256KRB5: ++ /* confounder at the beginning and 192-bit HMAC at the end */ ++ return AES_BLOCK_SIZE + data_len + 24; + default: + BUG(); + } +diff --git a/net/ceph/crypto.h b/net/ceph/crypto.h +index 2b8f8f6..2c37c54 100644 +--- a/net/ceph/crypto.h ++++ b/net/ceph/crypto.h +@@ -5,7 +5,7 @@ + #include + #include + +-#define CEPH_MAX_KEY_LEN 16 ++#define CEPH_MAX_KEY_LEN 32 + #define CEPH_MAX_CON_SECRET_LEN 64 + + /* +@@ -16,10 +16,18 @@ struct ceph_crypto_key { + struct ceph_timespec created; + int len; + void *key; +- struct crypto_sync_skcipher *tfm; ++ ++ union { ++ struct crypto_sync_skcipher *aes_tfm; ++ struct { ++ const struct krb5_enctype *krb5_type; ++ struct crypto_aead *krb5_tfms[3]; ++ }; ++ }; + }; + +-int ceph_crypto_key_prepare(struct ceph_crypto_key *key); ++int ceph_crypto_key_prepare(struct ceph_crypto_key *key, ++ const u32 *key_usages, int key_usage_cnt); + int ceph_crypto_key_clone(struct ceph_crypto_key *dst, + const struct ceph_crypto_key *src); + int ceph_crypto_key_decode(struct ceph_crypto_key *key, void **p, void *end); +@@ -27,7 +35,7 @@ int ceph_crypto_key_unarmor(struct ceph_crypto_key *key, const char *in); + void ceph_crypto_key_destroy(struct ceph_crypto_key *key); + + /* crypto.c */ +-int ceph_crypt(const struct ceph_crypto_key *key, bool encrypt, ++int ceph_crypt(const struct ceph_crypto_key *key, int usage_slot, bool encrypt, + void *buf, int buf_len, int in_len, int *pout_len); + int ceph_crypt_data_offset(const struct ceph_crypto_key *key); + int ceph_crypt_buflen(const struct ceph_crypto_key *key, int data_len); diff --git a/sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/files/6.18/z0011-libceph-adapt-ceph_x_challenge_blob-hashing-and-msgr.patch b/sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/files/6.18/z0011-libceph-adapt-ceph_x_challenge_blob-hashing-and-msgr.patch new file mode 100644 index 00000000000..08abe0cfb96 --- /dev/null +++ b/sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/files/6.18/z0011-libceph-adapt-ceph_x_challenge_blob-hashing-and-msgr.patch @@ -0,0 +1,236 @@ +From 8356b4b1103b8c970648c94bab724aa30e42d869 Mon Sep 17 00:00:00 2001 +From: Ilya Dryomov +Date: Sat, 12 Jul 2025 17:11:55 +0200 +Subject: [PATCH] libceph: adapt ceph_x_challenge_blob hashing and msgr1 + message signing + +The existing approach where ceph_x_challenge_blob is encrypted with the +client's secret key and then the digest derived from the ciphertext is +used for the test doesn't work with CEPH_CRYPTO_AES256KRB5 because the +confounder randomizes the ciphertext: the client and the server get two +different ciphertexts and therefore two different digests. + +msgr1 signatures are affected the same way: a digest derived from the +ciphertext for the message's "sigblock" is what becomes a signature and +the two sides disagree on the expected value. + +For CEPH_CRYPTO_AES256KRB5 (and potential future encryption schemes), +switch to HMAC-SHA256 function keyed in the same way as the existing +encryption. For CEPH_CRYPTO_AES, everything is preserved as is. + +Signed-off-by: Ilya Dryomov +--- + net/ceph/auth_x.c | 59 ++++++++++++++++++++++++++++++----------- + net/ceph/crypto.c | 18 +++++++++++++ + net/ceph/crypto.h | 4 +++ + net/ceph/messenger_v2.c | 14 +++++----- + 4 files changed, 72 insertions(+), 23 deletions(-) + +diff --git a/net/ceph/auth_x.c b/net/ceph/auth_x.c +index 966a382..9350e1a 100644 +--- a/net/ceph/auth_x.c ++++ b/net/ceph/auth_x.c +@@ -558,8 +558,7 @@ static int ceph_x_build_request(struct ceph_auth_client *ac, + if (need & CEPH_ENTITY_TYPE_AUTH) { + struct ceph_x_authenticate *auth = (void *)(head + 1); + void *enc_buf = xi->auth_authorizer.enc_buf; +- struct ceph_x_challenge_blob *blob = enc_buf + +- ceph_x_encrypt_offset(&xi->secret); ++ struct ceph_x_challenge_blob *blob; + u64 *u; + + p = auth + 1; +@@ -569,15 +568,29 @@ static int ceph_x_build_request(struct ceph_auth_client *ac, + dout(" get_auth_session_key\n"); + head->op = cpu_to_le16(CEPHX_GET_AUTH_SESSION_KEY); + +- /* encrypt and hash */ ++ if (xi->secret.type == CEPH_CRYPTO_AES) { ++ blob = enc_buf + ceph_x_encrypt_offset(&xi->secret); ++ } else { ++ BUILD_BUG_ON(SHA256_DIGEST_SIZE + sizeof(*blob) > ++ CEPHX_AU_ENC_BUF_LEN); ++ blob = enc_buf + SHA256_DIGEST_SIZE; ++ } ++ + get_random_bytes(&auth->client_challenge, sizeof(u64)); + blob->client_challenge = auth->client_challenge; + blob->server_challenge = cpu_to_le64(xi->server_challenge); +- ret = ceph_x_encrypt(&xi->secret, 0 /* dummy */, +- enc_buf, CEPHX_AU_ENC_BUF_LEN, +- sizeof(*blob)); +- if (ret < 0) +- return ret; ++ ++ if (xi->secret.type == CEPH_CRYPTO_AES) { ++ ret = ceph_x_encrypt(&xi->secret, 0 /* dummy */, ++ enc_buf, CEPHX_AU_ENC_BUF_LEN, ++ sizeof(*blob)); ++ if (ret < 0) ++ return ret; ++ } else { ++ ceph_hmac_sha256(&xi->secret, blob, sizeof(*blob), ++ enc_buf); ++ ret = SHA256_DIGEST_SIZE; ++ } + + auth->struct_v = 3; /* nautilus+ */ + auth->key = 0; +@@ -1065,11 +1078,19 @@ static int calc_signature(struct ceph_x_authorizer *au, struct ceph_msg *msg, + __le32 data_crc; + __le32 data_len; + __le32 seq_lower_word; +- } __packed *sigblock = enc_buf; ++ } __packed *sigblock; + struct { + __le64 a, b, c, d; + } __packed *penc = enc_buf; +- int ciphertext_len; ++ ++ if (au->session_key.type == CEPH_CRYPTO_AES) { ++ /* no leading len, no ceph_x_encrypt_header */ ++ sigblock = enc_buf; ++ } else { ++ BUILD_BUG_ON(SHA256_DIGEST_SIZE + sizeof(*sigblock) > ++ CEPHX_AU_ENC_BUF_LEN); ++ sigblock = enc_buf + SHA256_DIGEST_SIZE; ++ } + + sigblock->header_crc = msg->hdr.crc; + sigblock->front_crc = msg->footer.front_crc; +@@ -1080,12 +1101,18 @@ static int calc_signature(struct ceph_x_authorizer *au, struct ceph_msg *msg, + 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, 0 /* dummy */, +- true, enc_buf, CEPHX_AU_ENC_BUF_LEN, +- sizeof(*sigblock), &ciphertext_len); +- if (ret) +- return ret; ++ if (au->session_key.type == CEPH_CRYPTO_AES) { ++ int ciphertext_len; /* unused */ ++ ++ ret = ceph_crypt(&au->session_key, 0 /* dummy */, ++ true, enc_buf, CEPHX_AU_ENC_BUF_LEN, ++ sizeof(*sigblock), &ciphertext_len); ++ if (ret) ++ return ret; ++ } else { ++ ceph_hmac_sha256(&au->session_key, sigblock, ++ sizeof(*sigblock), enc_buf); ++ } + + *psig = penc->a ^ penc->b ^ penc->c ^ penc->d; + } +diff --git a/net/ceph/crypto.c b/net/ceph/crypto.c +index b54085d..b2067ea 100644 +--- a/net/ceph/crypto.c ++++ b/net/ceph/crypto.c +@@ -84,6 +84,7 @@ int ceph_crypto_key_prepare(struct ceph_crypto_key *key, + case CEPH_CRYPTO_AES: + return set_aes_tfm(key); + case CEPH_CRYPTO_AES256KRB5: ++ hmac_sha256_preparekey(&key->hmac_key, key->key, key->len); + return set_krb5_tfms(key, key_usages, key_usage_cnt); + default: + return -ENOTSUPP; +@@ -178,6 +179,7 @@ void ceph_crypto_key_destroy(struct ceph_crypto_key *key) + key->aes_tfm = NULL; + } + } else if (key->type == CEPH_CRYPTO_AES256KRB5) { ++ memzero_explicit(&key->hmac_key, sizeof(key->hmac_key)); + for (i = 0; i < ARRAY_SIZE(key->krb5_tfms); i++) { + if (key->krb5_tfms[i]) { + crypto_free_aead(key->krb5_tfms[i]); +@@ -436,6 +438,22 @@ int ceph_crypt_buflen(const struct ceph_crypto_key *key, int data_len) + } + } + ++void ceph_hmac_sha256(const struct ceph_crypto_key *key, const void *buf, ++ int buf_len, u8 hmac[SHA256_DIGEST_SIZE]) ++{ ++ switch (key->type) { ++ case CEPH_CRYPTO_NONE: ++ case CEPH_CRYPTO_AES: ++ memset(hmac, 0, SHA256_DIGEST_SIZE); ++ return; ++ case CEPH_CRYPTO_AES256KRB5: ++ hmac_sha256(&key->hmac_key, buf, buf_len, hmac); ++ return; ++ default: ++ BUG(); ++ } ++} ++ + static int ceph_key_preparse(struct key_preparsed_payload *prep) + { + struct ceph_crypto_key *ckey; +diff --git a/net/ceph/crypto.h b/net/ceph/crypto.h +index 2c37c54..3a2ade1 100644 +--- a/net/ceph/crypto.h ++++ b/net/ceph/crypto.h +@@ -2,6 +2,7 @@ + #ifndef _FS_CEPH_CRYPTO_H + #define _FS_CEPH_CRYPTO_H + ++#include + #include + #include + +@@ -20,6 +21,7 @@ struct ceph_crypto_key { + union { + struct crypto_sync_skcipher *aes_tfm; + struct { ++ struct hmac_sha256_key hmac_key; + const struct krb5_enctype *krb5_type; + struct crypto_aead *krb5_tfms[3]; + }; +@@ -39,6 +41,8 @@ int ceph_crypt(const struct ceph_crypto_key *key, int usage_slot, bool encrypt, + void *buf, int buf_len, int in_len, int *pout_len); + int ceph_crypt_data_offset(const struct ceph_crypto_key *key); + int ceph_crypt_buflen(const struct ceph_crypto_key *key, int data_len); ++void ceph_hmac_sha256(const struct ceph_crypto_key *key, const void *buf, ++ int buf_len, u8 hmac[SHA256_DIGEST_SIZE]); + int ceph_crypto_init(void); + void ceph_crypto_shutdown(void); + +diff --git a/net/ceph/messenger_v2.c b/net/ceph/messenger_v2.c +index 4bb238e..d5300c6 100644 +--- a/net/ceph/messenger_v2.c ++++ b/net/ceph/messenger_v2.c +@@ -778,9 +778,9 @@ static int setup_crypto(struct ceph_connection *con, + return 0; /* auth_x, secure mode */ + } + +-static void ceph_hmac_sha256(struct ceph_connection *con, +- const struct kvec *kvecs, int kvec_cnt, +- u8 hmac[SHA256_DIGEST_SIZE]) ++static void con_hmac_sha256(struct ceph_connection *con, ++ const struct kvec *kvecs, int kvec_cnt, ++ u8 hmac[SHA256_DIGEST_SIZE]) + { + struct hmac_sha256_ctx ctx; + int i; +@@ -1437,8 +1437,8 @@ static int prepare_auth_signature(struct ceph_connection *con) + if (!buf) + return -ENOMEM; + +- ceph_hmac_sha256(con, con->v2.in_sign_kvecs, con->v2.in_sign_kvec_cnt, +- CTRL_BODY(buf)); ++ con_hmac_sha256(con, con->v2.in_sign_kvecs, con->v2.in_sign_kvec_cnt, ++ CTRL_BODY(buf)); + + return prepare_control(con, FRAME_TAG_AUTH_SIGNATURE, buf, + SHA256_DIGEST_SIZE); +@@ -2441,8 +2441,8 @@ static int process_auth_signature(struct ceph_connection *con, + return -EINVAL; + } + +- ceph_hmac_sha256(con, con->v2.out_sign_kvecs, con->v2.out_sign_kvec_cnt, +- hmac); ++ con_hmac_sha256(con, con->v2.out_sign_kvecs, con->v2.out_sign_kvec_cnt, ++ hmac); + + ceph_decode_need(&p, end, SHA256_DIGEST_SIZE, bad); + if (crypto_memneq(p, hmac, SHA256_DIGEST_SIZE)) {