Skip to content

Commit e302309

Browse files
committed
dm crypt: Avoid using MAX_CIPHER_BLOCKSIZE
MAX_CIPHER_BLOCKSIZE is an internal implementation detail and should not be relied on by users of the Crypto API. Instead of storing the IV on the stack, allocate it together with the crypto request. Signed-off-by: Herbert Xu <[email protected]> Reviewed-by: Mike Snitzer <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent f005184 commit e302309

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

drivers/md/dm-crypt.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
#include <asm/unaligned.h>
3232
#include <crypto/hash.h>
3333
#include <crypto/md5.h>
34-
#include <crypto/algapi.h>
3534
#include <crypto/skcipher.h>
3635
#include <crypto/aead.h>
3736
#include <crypto/authenc.h>
37+
#include <crypto/utils.h>
3838
#include <linux/rtnetlink.h> /* for struct rtattr and RTA macros only */
3939
#include <linux/key-type.h>
4040
#include <keys/user-type.h>
@@ -745,16 +745,23 @@ static int crypt_iv_eboiv_ctr(struct crypt_config *cc, struct dm_target *ti,
745745
static int crypt_iv_eboiv_gen(struct crypt_config *cc, u8 *iv,
746746
struct dm_crypt_request *dmreq)
747747
{
748-
u8 buf[MAX_CIPHER_BLOCKSIZE] __aligned(__alignof__(__le64));
748+
struct crypto_skcipher *tfm = any_tfm(cc);
749749
struct skcipher_request *req;
750750
struct scatterlist src, dst;
751751
DECLARE_CRYPTO_WAIT(wait);
752+
unsigned int reqsize;
752753
int err;
754+
u8 *buf;
753755

754-
req = skcipher_request_alloc(any_tfm(cc), GFP_NOIO);
756+
reqsize = ALIGN(crypto_skcipher_reqsize(tfm), __alignof__(__le64));
757+
758+
req = kmalloc(reqsize + cc->iv_size, GFP_NOIO);
755759
if (!req)
756760
return -ENOMEM;
757761

762+
skcipher_request_set_tfm(req, tfm);
763+
764+
buf = (u8 *)req + reqsize;
758765
memset(buf, 0, cc->iv_size);
759766
*(__le64 *)buf = cpu_to_le64(dmreq->iv_sector * cc->sector_size);
760767

@@ -763,7 +770,7 @@ static int crypt_iv_eboiv_gen(struct crypt_config *cc, u8 *iv,
763770
skcipher_request_set_crypt(req, &src, &dst, cc->iv_size, buf);
764771
skcipher_request_set_callback(req, 0, crypto_req_done, &wait);
765772
err = crypto_wait_req(crypto_skcipher_encrypt(req), &wait);
766-
skcipher_request_free(req);
773+
kfree_sensitive(req);
767774

768775
return err;
769776
}

0 commit comments

Comments
 (0)