Skip to content

Commit ac431d5

Browse files
committed
libceph: define and enforce CEPH_MAX_KEY_LEN
When decoding the key, verify that the key material would fit into a fixed-size buffer in process_auth_done() and generally has a sane length. The new CEPH_MAX_KEY_LEN check replaces the existing check for a key with no key material which is a) not universal since CEPH_CRYPTO_NONE has to be excluded and b) doesn't provide much value since a smaller than needed key is just as invalid as no key -- this has to be handled elsewhere anyway. Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent 05f7e89 commit ac431d5

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

net/ceph/crypto.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ static int set_secret(struct ceph_crypto_key *key, void *buf)
3737
return -ENOTSUPP;
3838
}
3939

40-
if (!key->len)
41-
return -EINVAL;
42-
4340
key->key = kmemdup(buf, key->len, GFP_NOIO);
4441
if (!key->key) {
4542
ret = -ENOMEM;
@@ -83,6 +80,11 @@ int ceph_crypto_key_decode(struct ceph_crypto_key *key, void **p, void *end)
8380
ceph_decode_copy(p, &key->created, sizeof(key->created));
8481
key->len = ceph_decode_16(p);
8582
ceph_decode_need(p, end, key->len, bad);
83+
if (key->len > CEPH_MAX_KEY_LEN) {
84+
pr_err("secret too big %d\n", key->len);
85+
return -EINVAL;
86+
}
87+
8688
ret = set_secret(key, *p);
8789
memzero_explicit(*p, key->len);
8890
*p += key->len;

net/ceph/crypto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <linux/ceph/types.h>
66
#include <linux/ceph/buffer.h>
77

8-
#define CEPH_KEY_LEN 16
8+
#define CEPH_MAX_KEY_LEN 16
99
#define CEPH_MAX_CON_SECRET_LEN 64
1010

1111
/*

net/ceph/messenger_v2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2360,7 +2360,7 @@ static int process_auth_reply_more(struct ceph_connection *con,
23602360
*/
23612361
static int process_auth_done(struct ceph_connection *con, void *p, void *end)
23622362
{
2363-
u8 session_key_buf[CEPH_KEY_LEN + 16];
2363+
u8 session_key_buf[CEPH_MAX_KEY_LEN + 16];
23642364
u8 con_secret_buf[CEPH_MAX_CON_SECRET_LEN + 16];
23652365
u8 *session_key = PTR_ALIGN(&session_key_buf[0], 16);
23662366
u8 *con_secret = PTR_ALIGN(&con_secret_buf[0], 16);

0 commit comments

Comments
 (0)