Skip to content

Commit

Permalink
libceph: align session_key and con_secret to 16 bytes
Browse files Browse the repository at this point in the history
crypto_shash_setkey() and crypto_aead_setkey() will do a (small)
GFP_ATOMIC allocation to align the key if it isn't suitably aligned.
It's not a big deal, but at the same time easy to avoid.

The actual alignment requirement is dynamic, queryable with
crypto_shash_alignmask() and crypto_aead_alignmask(), but shouldn't
be stricter than 16 bytes for our algorithms.

Fixes: cd1a677 ("libceph, ceph: implement msgr2.1 protocol (crc and secure modes)")
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
  • Loading branch information
idryomov committed Dec 28, 2020
1 parent ad32fe8 commit f5f2c9a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions net/ceph/messenger_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2033,10 +2033,18 @@ static int process_auth_reply_more(struct ceph_connection *con,
return -EINVAL;
}

/*
* Align session_key and con_secret to avoid GFP_ATOMIC allocation
* inside crypto_shash_setkey() and crypto_aead_setkey() called from
* setup_crypto(). __aligned(16) isn't guaranteed to work for stack
* objects, so do it by hand.
*/
static int process_auth_done(struct ceph_connection *con, void *p, void *end)
{
u8 session_key[CEPH_KEY_LEN];
u8 con_secret[CEPH_MAX_CON_SECRET_LEN];
u8 session_key_buf[CEPH_KEY_LEN + 16];
u8 con_secret_buf[CEPH_MAX_CON_SECRET_LEN + 16];
u8 *session_key = PTR_ALIGN(&session_key_buf[0], 16);
u8 *con_secret = PTR_ALIGN(&con_secret_buf[0], 16);
int session_key_len, con_secret_len;
int payload_len;
u64 global_id;
Expand Down

0 comments on commit f5f2c9a

Please sign in to comment.