On Mon, Dec 12, 2016 at 10:11 PM, Sage Weil <sage@xxxxxxxxxxxx> wrote: > On Mon, 12 Dec 2016, Ilya Dryomov wrote: >> Starting with 4.9, kernel stacks may be vmalloced and therefore not >> guaranteed to be physically contiguous; the new CONFIG_VMAP_STACK >> option is enabled by default on x86. This makes it invalid to use >> on-stack buffers with the crypto scatterlist API, as sg_set_buf() >> expects a logical address and won't work with vmalloced addresses. >> >> There isn't a different (e.g. kvec-based) crypto API we could switch >> net/ceph/crypto.c to and the current scatterlist.h API isn't getting >> updated to accommodate this use case. Allocating a new header and >> padding for each operation is a non-starter, so do the en/decryption >> in-place on a single pre-assembled (header + data + padding) heap >> buffer. This is explicitly supported by the crypto API: >> >> "... the caller may provide the same scatter/gather list for the >> plaintext and cipher text. After the completion of the cipher >> operation, the plaintext data is replaced with the ciphertext data >> in case of an encryption and vice versa for a decryption." >> >> Signed-off-by: Ilya Dryomov <idryomov@xxxxxxxxx> >> --- >> net/ceph/crypto.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> net/ceph/crypto.h | 2 ++ >> 2 files changed, 89 insertions(+) >> >> diff --git a/net/ceph/crypto.c b/net/ceph/crypto.c >> index db2847ac5f12..32099c5c4c75 100644 >> --- a/net/ceph/crypto.c >> +++ b/net/ceph/crypto.c >> @@ -526,6 +526,93 @@ int ceph_encrypt2(struct ceph_crypto_key *secret, void *dst, size_t *dst_len, >> } >> } >> >> +static int ceph_aes_crypt(const struct ceph_crypto_key *key, bool encrypt, >> + void *buf, int buf_len, int in_len, int *pout_len) >> +{ >> + struct crypto_skcipher *tfm = ceph_crypto_alloc_cipher(); >> + SKCIPHER_REQUEST_ON_STACK(req, tfm); >> + struct sg_table sgt; >> + struct scatterlist prealloc_sg; >> + char iv[AES_BLOCK_SIZE]; >> + int pad_byte = AES_BLOCK_SIZE - (in_len & (AES_BLOCK_SIZE - 1)); > > nit: pad_bytes? It's also used as a PKCS7 pad *byte* > >> + int crypt_len = encrypt ? in_len + pad_byte : in_len; >> + int ret; >> + >> + if (IS_ERR(tfm)) >> + return PTR_ERR(tfm); >> + >> + WARN_ON(crypt_len > buf_len); >> + if (encrypt) >> + memset(buf + in_len, pad_byte, pad_byte); here, so I went with byte. Thanks, Ilya -- To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html