libceph: add CEPH_CRYPTO_AES256KRB5 support
cover libceph: add CEPH_CRYPTO_AES256KRB5 support
Backport of the libceph aes256k series from v7.0, as discussed in [1]. Ilya is fine with it going to 6.18.y.
Patches 2 and 4 cherry-pick cleanly. Patches 1 and 3 conflict in __ceph_x_decrypt() with 821365487aa5 ("libceph: Fix potential out-of-bounds access in __ceph_x_decrypt()"), which 6.18.y already has; the resolution gives the same code as mainline.
Tested on 6.18.58 against a Ceph 20.2.4 cluster restricted to aes256k:
rbd and CephFS via ceph-csi, map/unmap, reboot, and 24h of I/O across ticket renewals. Build-tested on top of 6.18.64.
---
Ilya Dryomov (4):
libceph: generalize ceph_x_encrypt_offset() and ceph_x_encrypt_buflen()
libceph: introduce ceph_crypto_key_prepare()
libceph: add support for CEPH_CRYPTO_AES256KRB5
libceph: adapt ceph_x_challenge_blob hashing and msgr1 message signing
include/linux/ceph/ceph_fs.h | 5 +- net/ceph/Kconfig | 1 + net/ceph/auth_x.c | 195 ++++++++++++++++++++++--------- net/ceph/auth_x_protocol.h | 38 ++++++ net/ceph/crypto.c | 269 +++++++++++++++++++++++++++++++++++-------- net/ceph/crypto.h | 21 +++- net/ceph/messenger_v2.c | 14 +-- 7 files changed, 428 insertions(+), 115 deletions(-)
---
base-commit: fd7cfd39c88596fec816639ad83cbf3e9d316372
change-id: 20261119-aes256k-6-18-y-4bfd567896ec
Best regards,
Signature · 1 line
Jordan DESNOËS <[email protected]>
PATCH 1/4 libceph: generalize ceph_x_encrypt_offset() and ceph_x_encrypt_buflen()
From: Ilya Dryomov <[email protected]>
commit 0ee8bccf7396d50726c9c8dd3135fb64a9fe8426 upstream.
- 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.
--- net/ceph/auth_x.c | 44 +++++++++++++++++++++++++++++--------------- net/ceph/crypto.c | 25 +++++++++++++++++++++++++ net/ceph/crypto.h | 2 ++ 3 files changed, 56 insertions(+), 15 deletions(-)
net/ceph/auth_x.c +29 -15
@@ -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;
net/ceph/crypto.c +25 -0
@@ -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;
net/ceph/crypto.h +2 -0
@@ -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 );
Signature · 1 line
2.43.0
PATCH 2/4 libceph: introduce ceph_crypto_key_prepare()
In reply to Jordan DESNOËSFrom: Ilya Dryomov <[email protected]>
commit 6cec0b61aacce4da5125b21c718189f0dc11eb51 upstream.
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.
--- net/ceph/auth_x.c | 26 +++++++++++++++----- net/ceph/crypto.c | 73 +++++++++++++++++++++++++++---------------------------- net/ceph/crypto.h | 1 + 3 files changed, 57 insertions(+), 43 deletions(-)
net/ceph/auth_x.c +20 -6
@@ -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; }
net/ceph/crypto.c +36 -37
118 lines not on this page · raw message
net/ceph/crypto.h +1 -0
@@ -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);
Signature · 1 line
2.43.0
PATCH 3/4 libceph: add support for CEPH_CRYPTO_AES256KRB5
In reply to Jordan DESNOËSFrom: Ilya Dryomov <[email protected]>
commit b7cc142dbafeaf6c053284ca9121b9f70b6d6d06 upstream.
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.
--- 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(-)
include/linux/ceph/ceph_fs.h +3 -2
@@ -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"
net/ceph/Kconfig +1 -0
@@ -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
net/ceph/auth_x.c +61 -27
215 lines not on this page · raw message
net/ceph/auth_x_protocol.h +38 -0
@@ -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;
net/ceph/crypto.c +142 -15
227 lines not on this page · raw message
net/ceph/crypto.h +12 -4
@@ -5,7 +5,7 @@#include <linux/ceph/types.h> #include <linux/ceph/buffer.h> -#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);
Signature · 1 line
2.43.0
PATCH 4/4 libceph: adapt ceph_x_challenge_blob hashing and msgr1 message signing
In reply to Jordan DESNOËSFrom: Ilya Dryomov <[email protected]>
commit 8356b4b1103b8c970648c94bab724aa30e42d869 upstream.
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.
--- 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(-)
net/ceph/auth_x.c +43 -16
@@ -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; }
net/ceph/crypto.c +18 -0
@@ -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;
net/ceph/crypto.h +4 -0
@@ -2,6 +2,7 @@#ifndef _FS_CEPH_CRYPTO_H#define _FS_CEPH_CRYPTO_H +#include <crypto/sha2.h> #include <linux/ceph/types.h> #include <linux/ceph/buffer.h>
@@ -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 );
net/ceph/messenger_v2.c +7 -7
@@ -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 )) {
Signature · 1 line
2.43.0
Sasha Levin
maintainerQuoted 2 lines
Backport of the libceph aes256k series from v7.0, as discussed in [1]. Ilya is fine with it going to 6.18.y.
Ugh, this really looks like a brand new feature... Is it not?
Signature · 2 lines
Thanks, Sasha
Quoted 1 line · On Thu, Nov 19, 2026 Sasha Levin wrote:
Ugh, this really looks like a brand new feature... Is it not?
It is, but it's the client side of a security fix: aes256k is Ceph's remediation for CVE-2025-30156 (CephX auth bypass via the old "aes" key type) [1]. Completing the remediation means disallowing "aes", which breaks kernel clients older than 7.0 [2]. CentOS Stream 9 and 10 already carry a backport, and Ilya is fine with this one [3].
[1] https://docs.ceph.com/en/latest/security/CVE-2025-30156/
[2] https://docs.ceph.com/en/latest/rados/configuration/auth-config-ref/#cephx-upgrade
[3] https://lore.kernel.org/stable/PR1P264MB1805408F7C4A11E6F4D2F6BE887B2@PR1P264MB1805.FRAP264.PROD.OUTLOOK.COM/T/#u
Thanks,
Jordan
Quoted 2 lines
Backport of the libceph aes256k series from v7.0, as discussed in [1]. Ilya is fine with it going to 6.18.y.
Queued for 6.18, thanks.
Signature · 2 lines
Thanks, Sasha