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

wusb: 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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Felipe Balbi <felipe.balbi@linux.intel.com>
Cc: Johan Hovold <johan@kernel.org>
Cc: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
Cc: linux-usb@vger.kernel.org
Signed-off-by: NKees Cook <keescook@chromium.org>
Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
上级 69d826fa
...@@ -189,7 +189,7 @@ struct wusb_mac_scratch { ...@@ -189,7 +189,7 @@ struct wusb_mac_scratch {
* NOTE: blen is not aligned to a block size, we'll pad zeros, that's * NOTE: blen is not aligned to a block size, we'll pad zeros, that's
* what sg[4] is for. Maybe there is a smarter way to do this. * what sg[4] is for. Maybe there is a smarter way to do this.
*/ */
static int wusb_ccm_mac(struct crypto_skcipher *tfm_cbc, static int wusb_ccm_mac(struct crypto_sync_skcipher *tfm_cbc,
struct crypto_cipher *tfm_aes, struct crypto_cipher *tfm_aes,
struct wusb_mac_scratch *scratch, struct wusb_mac_scratch *scratch,
void *mic, void *mic,
...@@ -198,7 +198,7 @@ static int wusb_ccm_mac(struct crypto_skcipher *tfm_cbc, ...@@ -198,7 +198,7 @@ static int wusb_ccm_mac(struct crypto_skcipher *tfm_cbc,
size_t blen) size_t blen)
{ {
int result = 0; int result = 0;
SKCIPHER_REQUEST_ON_STACK(req, tfm_cbc); SYNC_SKCIPHER_REQUEST_ON_STACK(req, tfm_cbc);
struct scatterlist sg[4], sg_dst; struct scatterlist sg[4], sg_dst;
void *dst_buf; void *dst_buf;
size_t dst_size; size_t dst_size;
...@@ -224,7 +224,7 @@ static int wusb_ccm_mac(struct crypto_skcipher *tfm_cbc, ...@@ -224,7 +224,7 @@ static int wusb_ccm_mac(struct crypto_skcipher *tfm_cbc,
if (!dst_buf) if (!dst_buf)
goto error_dst_buf; goto error_dst_buf;
iv = kzalloc(crypto_skcipher_ivsize(tfm_cbc), GFP_KERNEL); iv = kzalloc(crypto_sync_skcipher_ivsize(tfm_cbc), GFP_KERNEL);
if (!iv) if (!iv)
goto error_iv; goto error_iv;
...@@ -251,7 +251,7 @@ static int wusb_ccm_mac(struct crypto_skcipher *tfm_cbc, ...@@ -251,7 +251,7 @@ static int wusb_ccm_mac(struct crypto_skcipher *tfm_cbc,
sg_set_page(&sg[3], ZERO_PAGE(0), zero_padding, 0); sg_set_page(&sg[3], ZERO_PAGE(0), zero_padding, 0);
sg_init_one(&sg_dst, dst_buf, dst_size); sg_init_one(&sg_dst, dst_buf, dst_size);
skcipher_request_set_tfm(req, tfm_cbc); skcipher_request_set_sync_tfm(req, tfm_cbc);
skcipher_request_set_callback(req, 0, NULL, NULL); skcipher_request_set_callback(req, 0, NULL, NULL);
skcipher_request_set_crypt(req, sg, &sg_dst, dst_size, iv); skcipher_request_set_crypt(req, sg, &sg_dst, dst_size, iv);
result = crypto_skcipher_encrypt(req); result = crypto_skcipher_encrypt(req);
...@@ -298,19 +298,19 @@ ssize_t wusb_prf(void *out, size_t out_size, ...@@ -298,19 +298,19 @@ ssize_t wusb_prf(void *out, size_t out_size,
{ {
ssize_t result, bytes = 0, bitr; ssize_t result, bytes = 0, bitr;
struct aes_ccm_nonce n = *_n; struct aes_ccm_nonce n = *_n;
struct crypto_skcipher *tfm_cbc; struct crypto_sync_skcipher *tfm_cbc;
struct crypto_cipher *tfm_aes; struct crypto_cipher *tfm_aes;
struct wusb_mac_scratch *scratch; struct wusb_mac_scratch *scratch;
u64 sfn = 0; u64 sfn = 0;
__le64 sfn_le; __le64 sfn_le;
tfm_cbc = crypto_alloc_skcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC); tfm_cbc = crypto_alloc_sync_skcipher("cbc(aes)", 0, 0);
if (IS_ERR(tfm_cbc)) { if (IS_ERR(tfm_cbc)) {
result = PTR_ERR(tfm_cbc); result = PTR_ERR(tfm_cbc);
printk(KERN_ERR "E: can't load CBC(AES): %d\n", (int)result); printk(KERN_ERR "E: can't load CBC(AES): %d\n", (int)result);
goto error_alloc_cbc; goto error_alloc_cbc;
} }
result = crypto_skcipher_setkey(tfm_cbc, key, 16); result = crypto_sync_skcipher_setkey(tfm_cbc, key, 16);
if (result < 0) { if (result < 0) {
printk(KERN_ERR "E: can't set CBC key: %d\n", (int)result); printk(KERN_ERR "E: can't set CBC key: %d\n", (int)result);
goto error_setkey_cbc; goto error_setkey_cbc;
...@@ -351,7 +351,7 @@ ssize_t wusb_prf(void *out, size_t out_size, ...@@ -351,7 +351,7 @@ ssize_t wusb_prf(void *out, size_t out_size,
crypto_free_cipher(tfm_aes); crypto_free_cipher(tfm_aes);
error_alloc_aes: error_alloc_aes:
error_setkey_cbc: error_setkey_cbc:
crypto_free_skcipher(tfm_cbc); crypto_free_sync_skcipher(tfm_cbc);
error_alloc_cbc: error_alloc_cbc:
return result; return result;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册