提交 3103f4a7 编写于 作者: K Kees Cook 提交者: Herbert Xu

mac802154: 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: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@datenfreihafen.org>
Cc: linux-wpan@vger.kernel.org
Signed-off-by: NKees Cook <keescook@chromium.org>
Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
上级 db20f570
...@@ -146,18 +146,18 @@ llsec_key_alloc(const struct ieee802154_llsec_key *template) ...@@ -146,18 +146,18 @@ llsec_key_alloc(const struct ieee802154_llsec_key *template)
goto err_tfm; goto err_tfm;
} }
key->tfm0 = crypto_alloc_skcipher("ctr(aes)", 0, CRYPTO_ALG_ASYNC); key->tfm0 = crypto_alloc_sync_skcipher("ctr(aes)", 0, 0);
if (IS_ERR(key->tfm0)) if (IS_ERR(key->tfm0))
goto err_tfm; goto err_tfm;
if (crypto_skcipher_setkey(key->tfm0, template->key, if (crypto_sync_skcipher_setkey(key->tfm0, template->key,
IEEE802154_LLSEC_KEY_SIZE)) IEEE802154_LLSEC_KEY_SIZE))
goto err_tfm0; goto err_tfm0;
return key; return key;
err_tfm0: err_tfm0:
crypto_free_skcipher(key->tfm0); crypto_free_sync_skcipher(key->tfm0);
err_tfm: err_tfm:
for (i = 0; i < ARRAY_SIZE(key->tfm); i++) for (i = 0; i < ARRAY_SIZE(key->tfm); i++)
if (key->tfm[i]) if (key->tfm[i])
...@@ -177,7 +177,7 @@ static void llsec_key_release(struct kref *ref) ...@@ -177,7 +177,7 @@ static void llsec_key_release(struct kref *ref)
for (i = 0; i < ARRAY_SIZE(key->tfm); i++) for (i = 0; i < ARRAY_SIZE(key->tfm); i++)
crypto_free_aead(key->tfm[i]); crypto_free_aead(key->tfm[i]);
crypto_free_skcipher(key->tfm0); crypto_free_sync_skcipher(key->tfm0);
kzfree(key); kzfree(key);
} }
...@@ -622,7 +622,7 @@ llsec_do_encrypt_unauth(struct sk_buff *skb, const struct mac802154_llsec *sec, ...@@ -622,7 +622,7 @@ llsec_do_encrypt_unauth(struct sk_buff *skb, const struct mac802154_llsec *sec,
{ {
u8 iv[16]; u8 iv[16];
struct scatterlist src; struct scatterlist src;
SKCIPHER_REQUEST_ON_STACK(req, key->tfm0); SYNC_SKCIPHER_REQUEST_ON_STACK(req, key->tfm0);
int err, datalen; int err, datalen;
unsigned char *data; unsigned char *data;
...@@ -632,7 +632,7 @@ llsec_do_encrypt_unauth(struct sk_buff *skb, const struct mac802154_llsec *sec, ...@@ -632,7 +632,7 @@ llsec_do_encrypt_unauth(struct sk_buff *skb, const struct mac802154_llsec *sec,
datalen = skb_tail_pointer(skb) - data; datalen = skb_tail_pointer(skb) - data;
sg_init_one(&src, data, datalen); sg_init_one(&src, data, datalen);
skcipher_request_set_tfm(req, key->tfm0); skcipher_request_set_sync_tfm(req, key->tfm0);
skcipher_request_set_callback(req, 0, NULL, NULL); skcipher_request_set_callback(req, 0, NULL, NULL);
skcipher_request_set_crypt(req, &src, &src, datalen, iv); skcipher_request_set_crypt(req, &src, &src, datalen, iv);
err = crypto_skcipher_encrypt(req); err = crypto_skcipher_encrypt(req);
...@@ -840,7 +840,7 @@ llsec_do_decrypt_unauth(struct sk_buff *skb, const struct mac802154_llsec *sec, ...@@ -840,7 +840,7 @@ llsec_do_decrypt_unauth(struct sk_buff *skb, const struct mac802154_llsec *sec,
unsigned char *data; unsigned char *data;
int datalen; int datalen;
struct scatterlist src; struct scatterlist src;
SKCIPHER_REQUEST_ON_STACK(req, key->tfm0); SYNC_SKCIPHER_REQUEST_ON_STACK(req, key->tfm0);
int err; int err;
llsec_geniv(iv, dev_addr, &hdr->sec); llsec_geniv(iv, dev_addr, &hdr->sec);
...@@ -849,7 +849,7 @@ llsec_do_decrypt_unauth(struct sk_buff *skb, const struct mac802154_llsec *sec, ...@@ -849,7 +849,7 @@ llsec_do_decrypt_unauth(struct sk_buff *skb, const struct mac802154_llsec *sec,
sg_init_one(&src, data, datalen); sg_init_one(&src, data, datalen);
skcipher_request_set_tfm(req, key->tfm0); skcipher_request_set_sync_tfm(req, key->tfm0);
skcipher_request_set_callback(req, 0, NULL, NULL); skcipher_request_set_callback(req, 0, NULL, NULL);
skcipher_request_set_crypt(req, &src, &src, datalen, iv); skcipher_request_set_crypt(req, &src, &src, datalen, iv);
......
...@@ -29,7 +29,7 @@ struct mac802154_llsec_key { ...@@ -29,7 +29,7 @@ struct mac802154_llsec_key {
/* one tfm for each authsize (4/8/16) */ /* one tfm for each authsize (4/8/16) */
struct crypto_aead *tfm[3]; struct crypto_aead *tfm[3];
struct crypto_skcipher *tfm0; struct crypto_sync_skcipher *tfm0;
struct kref ref; struct kref ref;
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册