Skip to content

Commit 6650c4d

Browse files
smesoherbertx
authored andcommitted
crypto: remove several VLAs
We avoid various VLAs[1] by using constant expressions for block size and alignment mask. [1] http://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Signed-off-by: Salvatore Mesoraca <s.mesoraca16@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 13c935b commit 6650c4d

5 files changed

Lines changed: 13 additions & 11 deletions

File tree

‎crypto/cfb.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ static void crypto_cfb_encrypt_one(struct crypto_skcipher *tfm,
5353
static void crypto_cfb_final(struct skcipher_walk *walk,
5454
struct crypto_skcipher *tfm)
5555
{
56-
const unsigned int bsize = crypto_cfb_bsize(tfm);
5756
const unsigned long alignmask = crypto_skcipher_alignmask(tfm);
58-
u8 tmp[bsize + alignmask];
57+
u8 tmp[MAX_CIPHER_BLOCKSIZE + MAX_CIPHER_ALIGNMASK];
5958
u8 *stream = PTR_ALIGN(tmp + 0, alignmask + 1);
6059
u8 *src = walk->src.virt.addr;
6160
u8 *dst = walk->dst.virt.addr;
@@ -94,7 +93,7 @@ static int crypto_cfb_encrypt_inplace(struct skcipher_walk *walk,
9493
unsigned int nbytes = walk->nbytes;
9594
u8 *src = walk->src.virt.addr;
9695
u8 *iv = walk->iv;
97-
u8 tmp[bsize];
96+
u8 tmp[MAX_CIPHER_BLOCKSIZE];
9897

9998
do {
10099
crypto_cfb_encrypt_one(tfm, iv, tmp);
@@ -164,7 +163,7 @@ static int crypto_cfb_decrypt_inplace(struct skcipher_walk *walk,
164163
unsigned int nbytes = walk->nbytes;
165164
u8 *src = walk->src.virt.addr;
166165
u8 *iv = walk->iv;
167-
u8 tmp[bsize];
166+
u8 tmp[MAX_CIPHER_BLOCKSIZE];
168167

169168
do {
170169
crypto_cfb_encrypt_one(tfm, iv, tmp);

‎crypto/cipher.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*
1414
*/
1515

16+
#include <crypto/algapi.h>
1617
#include <linux/kernel.h>
1718
#include <linux/crypto.h>
1819
#include <linux/errno.h>
@@ -67,7 +68,7 @@ static void cipher_crypt_unaligned(void (*fn)(struct crypto_tfm *, u8 *,
6768
{
6869
unsigned long alignmask = crypto_tfm_alg_alignmask(tfm);
6970
unsigned int size = crypto_tfm_alg_blocksize(tfm);
70-
u8 buffer[size + alignmask];
71+
u8 buffer[MAX_CIPHER_BLOCKSIZE + MAX_CIPHER_ALIGNMASK];
7172
u8 *tmp = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
7273

7374
memcpy(tmp, src, size);

‎crypto/ctr.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static void crypto_ctr_crypt_final(struct blkcipher_walk *walk,
5858
unsigned int bsize = crypto_cipher_blocksize(tfm);
5959
unsigned long alignmask = crypto_cipher_alignmask(tfm);
6060
u8 *ctrblk = walk->iv;
61-
u8 tmp[bsize + alignmask];
61+
u8 tmp[MAX_CIPHER_BLOCKSIZE + MAX_CIPHER_ALIGNMASK];
6262
u8 *keystream = PTR_ALIGN(tmp + 0, alignmask + 1);
6363
u8 *src = walk->src.virt.addr;
6464
u8 *dst = walk->dst.virt.addr;
@@ -106,7 +106,7 @@ static int crypto_ctr_crypt_inplace(struct blkcipher_walk *walk,
106106
unsigned int nbytes = walk->nbytes;
107107
u8 *ctrblk = walk->iv;
108108
u8 *src = walk->src.virt.addr;
109-
u8 tmp[bsize + alignmask];
109+
u8 tmp[MAX_CIPHER_BLOCKSIZE + MAX_CIPHER_ALIGNMASK];
110110
u8 *keystream = PTR_ALIGN(tmp + 0, alignmask + 1);
111111

112112
do {

‎crypto/cts.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
* rfc3962 includes errata information in its Appendix A.
4141
*/
4242

43+
#include <crypto/algapi.h>
4344
#include <crypto/internal/skcipher.h>
4445
#include <linux/err.h>
4546
#include <linux/init.h>
@@ -104,7 +105,7 @@ static int cts_cbc_encrypt(struct skcipher_request *req)
104105
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
105106
struct skcipher_request *subreq = &rctx->subreq;
106107
int bsize = crypto_skcipher_blocksize(tfm);
107-
u8 d[bsize * 2] __aligned(__alignof__(u32));
108+
u8 d[MAX_CIPHER_BLOCKSIZE * 2] __aligned(__alignof__(u32));
108109
struct scatterlist *sg;
109110
unsigned int offset;
110111
int lastn;
@@ -183,7 +184,7 @@ static int cts_cbc_decrypt(struct skcipher_request *req)
183184
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
184185
struct skcipher_request *subreq = &rctx->subreq;
185186
int bsize = crypto_skcipher_blocksize(tfm);
186-
u8 d[bsize * 2] __aligned(__alignof__(u32));
187+
u8 d[MAX_CIPHER_BLOCKSIZE * 2] __aligned(__alignof__(u32));
187188
struct scatterlist *sg;
188189
unsigned int offset;
189190
u8 *space;

‎crypto/pcbc.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*
1515
*/
1616

17+
#include <crypto/algapi.h>
1718
#include <crypto/internal/skcipher.h>
1819
#include <linux/err.h>
1920
#include <linux/init.h>
@@ -72,7 +73,7 @@ static int crypto_pcbc_encrypt_inplace(struct skcipher_request *req,
7273
unsigned int nbytes = walk->nbytes;
7374
u8 *src = walk->src.virt.addr;
7475
u8 *iv = walk->iv;
75-
u8 tmpbuf[bsize];
76+
u8 tmpbuf[MAX_CIPHER_BLOCKSIZE];
7677

7778
do {
7879
memcpy(tmpbuf, src, bsize);
@@ -144,7 +145,7 @@ static int crypto_pcbc_decrypt_inplace(struct skcipher_request *req,
144145
unsigned int nbytes = walk->nbytes;
145146
u8 *src = walk->src.virt.addr;
146147
u8 *iv = walk->iv;
147-
u8 tmpbuf[bsize] __aligned(__alignof__(u32));
148+
u8 tmpbuf[MAX_CIPHER_BLOCKSIZE] __aligned(__alignof__(u32));
148149

149150
do {
150151
memcpy(tmpbuf, src, bsize);

0 commit comments

Comments
 (0)