Commit dc568baf authored by Kees Cook's avatar Kees Cook Committed by Herbert Xu

block: cryptoloop: Remove VLA usage of skcipher

In the quest to remove all stack VLA usage from the kernel[1], this
replaces struct crypto_skcipher and SKCIPHER_REQUEST_ON_STACK() usage
with struct crypto_sync_skcipher and SYNC_SKCIPHER_REQUEST_ON_STACK(),
which uses a fixed stack size.

[1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com

Cc: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Acked-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 88fe0b95
...@@ -45,7 +45,7 @@ cryptoloop_init(struct loop_device *lo, const struct loop_info64 *info) ...@@ -45,7 +45,7 @@ cryptoloop_init(struct loop_device *lo, const struct loop_info64 *info)
char cms[LO_NAME_SIZE]; /* cipher-mode string */ char cms[LO_NAME_SIZE]; /* cipher-mode string */
char *mode; char *mode;
char *cmsp = cms; /* c-m string pointer */ char *cmsp = cms; /* c-m string pointer */
struct crypto_skcipher *tfm; struct crypto_sync_skcipher *tfm;
/* encryption breaks for non sector aligned offsets */ /* encryption breaks for non sector aligned offsets */
...@@ -80,11 +80,11 @@ cryptoloop_init(struct loop_device *lo, const struct loop_info64 *info) ...@@ -80,11 +80,11 @@ cryptoloop_init(struct loop_device *lo, const struct loop_info64 *info)
*cmsp++ = ')'; *cmsp++ = ')';
*cmsp = 0; *cmsp = 0;
tfm = crypto_alloc_skcipher(cms, 0, CRYPTO_ALG_ASYNC); tfm = crypto_alloc_sync_skcipher(cms, 0, 0);
if (IS_ERR(tfm)) if (IS_ERR(tfm))
return PTR_ERR(tfm); return PTR_ERR(tfm);
err = crypto_skcipher_setkey(tfm, info->lo_encrypt_key, err = crypto_sync_skcipher_setkey(tfm, info->lo_encrypt_key,
info->lo_encrypt_key_size); info->lo_encrypt_key_size);
if (err != 0) if (err != 0)
...@@ -94,7 +94,7 @@ cryptoloop_init(struct loop_device *lo, const struct loop_info64 *info) ...@@ -94,7 +94,7 @@ cryptoloop_init(struct loop_device *lo, const struct loop_info64 *info)
return 0; return 0;
out_free_tfm: out_free_tfm:
crypto_free_skcipher(tfm); crypto_free_sync_skcipher(tfm);
out: out:
return err; return err;
...@@ -109,8 +109,8 @@ cryptoloop_transfer(struct loop_device *lo, int cmd, ...@@ -109,8 +109,8 @@ cryptoloop_transfer(struct loop_device *lo, int cmd,
struct page *loop_page, unsigned loop_off, struct page *loop_page, unsigned loop_off,
int size, sector_t IV) int size, sector_t IV)
{ {
struct crypto_skcipher *tfm = lo->key_data; struct crypto_sync_skcipher *tfm = lo->key_data;
SKCIPHER_REQUEST_ON_STACK(req, tfm); SYNC_SKCIPHER_REQUEST_ON_STACK(req, tfm);
struct scatterlist sg_out; struct scatterlist sg_out;
struct scatterlist sg_in; struct scatterlist sg_in;
...@@ -119,7 +119,7 @@ cryptoloop_transfer(struct loop_device *lo, int cmd, ...@@ -119,7 +119,7 @@ cryptoloop_transfer(struct loop_device *lo, int cmd,
unsigned in_offs, out_offs; unsigned in_offs, out_offs;
int err; int err;
skcipher_request_set_tfm(req, tfm); skcipher_request_set_sync_tfm(req, tfm);
skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_SLEEP, skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_SLEEP,
NULL, NULL); NULL, NULL);
...@@ -175,9 +175,9 @@ cryptoloop_ioctl(struct loop_device *lo, int cmd, unsigned long arg) ...@@ -175,9 +175,9 @@ cryptoloop_ioctl(struct loop_device *lo, int cmd, unsigned long arg)
static int static int
cryptoloop_release(struct loop_device *lo) cryptoloop_release(struct loop_device *lo)
{ {
struct crypto_skcipher *tfm = lo->key_data; struct crypto_sync_skcipher *tfm = lo->key_data;
if (tfm != NULL) { if (tfm != NULL) {
crypto_free_skcipher(tfm); crypto_free_sync_skcipher(tfm);
lo->key_data = NULL; lo->key_data = NULL;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment