提交 88fe0b95 编写于 作者: K Kees Cook 提交者: Herbert Xu

x86/fpu: 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: x86@kernel.org
Signed-off-by: NKees Cook <keescook@chromium.org>
Reviewed-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
上级 531fa5d6
...@@ -20,21 +20,23 @@ ...@@ -20,21 +20,23 @@
#include <asm/fpu/api.h> #include <asm/fpu/api.h>
struct crypto_fpu_ctx { struct crypto_fpu_ctx {
struct crypto_skcipher *child; struct crypto_sync_skcipher *child;
}; };
static int crypto_fpu_setkey(struct crypto_skcipher *parent, const u8 *key, static int crypto_fpu_setkey(struct crypto_skcipher *parent, const u8 *key,
unsigned int keylen) unsigned int keylen)
{ {
struct crypto_fpu_ctx *ctx = crypto_skcipher_ctx(parent); struct crypto_fpu_ctx *ctx = crypto_skcipher_ctx(parent);
struct crypto_skcipher *child = ctx->child; struct crypto_sync_skcipher *child = ctx->child;
int err; int err;
crypto_skcipher_clear_flags(child, CRYPTO_TFM_REQ_MASK); crypto_sync_skcipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
crypto_skcipher_set_flags(child, crypto_skcipher_get_flags(parent) & crypto_sync_skcipher_set_flags(child,
crypto_skcipher_get_flags(parent) &
CRYPTO_TFM_REQ_MASK); CRYPTO_TFM_REQ_MASK);
err = crypto_skcipher_setkey(child, key, keylen); err = crypto_sync_skcipher_setkey(child, key, keylen);
crypto_skcipher_set_flags(parent, crypto_skcipher_get_flags(child) & crypto_skcipher_set_flags(parent,
crypto_sync_skcipher_get_flags(child) &
CRYPTO_TFM_RES_MASK); CRYPTO_TFM_RES_MASK);
return err; return err;
} }
...@@ -43,11 +45,11 @@ static int crypto_fpu_encrypt(struct skcipher_request *req) ...@@ -43,11 +45,11 @@ static int crypto_fpu_encrypt(struct skcipher_request *req)
{ {
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
struct crypto_fpu_ctx *ctx = crypto_skcipher_ctx(tfm); struct crypto_fpu_ctx *ctx = crypto_skcipher_ctx(tfm);
struct crypto_skcipher *child = ctx->child; struct crypto_sync_skcipher *child = ctx->child;
SKCIPHER_REQUEST_ON_STACK(subreq, child); SYNC_SKCIPHER_REQUEST_ON_STACK(subreq, child);
int err; int err;
skcipher_request_set_tfm(subreq, child); skcipher_request_set_sync_tfm(subreq, child);
skcipher_request_set_callback(subreq, 0, NULL, NULL); skcipher_request_set_callback(subreq, 0, NULL, NULL);
skcipher_request_set_crypt(subreq, req->src, req->dst, req->cryptlen, skcipher_request_set_crypt(subreq, req->src, req->dst, req->cryptlen,
req->iv); req->iv);
...@@ -64,11 +66,11 @@ static int crypto_fpu_decrypt(struct skcipher_request *req) ...@@ -64,11 +66,11 @@ static int crypto_fpu_decrypt(struct skcipher_request *req)
{ {
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
struct crypto_fpu_ctx *ctx = crypto_skcipher_ctx(tfm); struct crypto_fpu_ctx *ctx = crypto_skcipher_ctx(tfm);
struct crypto_skcipher *child = ctx->child; struct crypto_sync_skcipher *child = ctx->child;
SKCIPHER_REQUEST_ON_STACK(subreq, child); SYNC_SKCIPHER_REQUEST_ON_STACK(subreq, child);
int err; int err;
skcipher_request_set_tfm(subreq, child); skcipher_request_set_sync_tfm(subreq, child);
skcipher_request_set_callback(subreq, 0, NULL, NULL); skcipher_request_set_callback(subreq, 0, NULL, NULL);
skcipher_request_set_crypt(subreq, req->src, req->dst, req->cryptlen, skcipher_request_set_crypt(subreq, req->src, req->dst, req->cryptlen,
req->iv); req->iv);
...@@ -93,7 +95,7 @@ static int crypto_fpu_init_tfm(struct crypto_skcipher *tfm) ...@@ -93,7 +95,7 @@ static int crypto_fpu_init_tfm(struct crypto_skcipher *tfm)
if (IS_ERR(cipher)) if (IS_ERR(cipher))
return PTR_ERR(cipher); return PTR_ERR(cipher);
ctx->child = cipher; ctx->child = (struct crypto_sync_skcipher *)cipher;
return 0; return 0;
} }
...@@ -102,7 +104,7 @@ static void crypto_fpu_exit_tfm(struct crypto_skcipher *tfm) ...@@ -102,7 +104,7 @@ static void crypto_fpu_exit_tfm(struct crypto_skcipher *tfm)
{ {
struct crypto_fpu_ctx *ctx = crypto_skcipher_ctx(tfm); struct crypto_fpu_ctx *ctx = crypto_skcipher_ctx(tfm);
crypto_free_skcipher(ctx->child); crypto_free_sync_skcipher(ctx->child);
} }
static void crypto_fpu_free(struct skcipher_instance *inst) static void crypto_fpu_free(struct skcipher_instance *inst)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册