From patchwork Mon Apr 9 13:54:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Salvatore Mesoraca X-Patchwork-Id: 10331399 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 905C460236 for ; Mon, 9 Apr 2018 13:56:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 839DF28B58 for ; Mon, 9 Apr 2018 13:56:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7800728B5E; Mon, 9 Apr 2018 13:56:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 4E14728B58 for ; Mon, 9 Apr 2018 13:56:20 +0000 (UTC) Received: (qmail 21687 invoked by uid 550); 9 Apr 2018 13:55:13 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 21632 invoked from network); 9 Apr 2018 13:55:10 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RWBe+SKvaMr/0BySL20eOL4F3V+JXex2sjdjz+vDMd8=; b=FQpVDkDIZ6jRI4uCc4SpRRcUyoVgGrRWyHcM+42LM6/zk1geBPFG0xX7Y5BnMVPag5 8YUEyokW64jAKjseo9K592omKGBnP7w1cdKk9dxrE3UpKH9tC/nrBRwo3FyPYnnZgPXm 8YWKTVUea8ugTDp/EjbkYuKZY1vruFfo3gFNfdCAJR7nkCb7TldLdDEisu5cN68y5BtX PFClN22AXG2uUEk6ZxKRtzH52AevsIXoVfK1g3/rOy1qHieA0OT+HAX/xDNBF7aZD+pb i/LU7YonvKh/CBcvXOFQ2iuo9Ss1GyT7MSP1KjYR7ENx5vTJbvaRyRd4NFXipEy/F6HX xNfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=RWBe+SKvaMr/0BySL20eOL4F3V+JXex2sjdjz+vDMd8=; b=NOo2aGpptfZfpAas8hZnc4u+JSq+WRC8eZm/iHqNVtEcjpnePR3sHZDqnYsPwVZtht PRjCbpqcCa+WAaEECjqPyzc9m/eTRqtrcpn4dR52y2h7P9VMRjUDLhDDwgNyKYezFd02 Dx9HURhoE7p+SwbTQxCOuoJ+xYq/8wQt2ZZFvnRa9m6MxPQX1MwwNas2QO7vtV8eAn/W FaVhwtL79zy8ptXKNaPKuvWOn57pHH9geb/0CxW5Xse7xwPrKfPk36SmFws9XolPkmV7 wqNCFNpHzbVc6tQFI/I+Q+TLojm9iySqcNM6BzJsA3zVwXKzxd3ZtEaHob9/wm9Pq9NP rkPA== X-Gm-Message-State: ALQs6tAyTG+DIipNVORNm16LwCPYe2KpE/3BTXNM270Rrs6q1bsX2pwq lOdgUHovQQd1VfGq6Ps5ghoRiWYTJZLLzw== X-Google-Smtp-Source: AIpwx48Tb2qBsl5K5MD3zZ8DYyvzTLRmm6LNZ20HXJttvSyvgu/0EcTAwunxm7AdA+a7iQESZ+RHvw== X-Received: by 10.28.126.145 with SMTP id z139mr80521wmc.18.1523282099299; Mon, 09 Apr 2018 06:54:59 -0700 (PDT) From: Salvatore Mesoraca To: linux-kernel@vger.kernel.org Cc: kernel-hardening@lists.openwall.com, linux-crypto@vger.kernel.org, "David S. Miller" , Herbert Xu , Kees Cook , Salvatore Mesoraca , Eric Biggers , Laura Abbott Subject: [PATCH v2 2/2] crypto: remove several VLAs Date: Mon, 9 Apr 2018 15:54:47 +0200 Message-Id: <1523282087-22128-3-git-send-email-s.mesoraca16@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1523282087-22128-1-git-send-email-s.mesoraca16@gmail.com> References: <1523282087-22128-1-git-send-email-s.mesoraca16@gmail.com> X-Virus-Scanned: ClamAV using ClamSMTP 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 --- crypto/cfb.c | 7 +++---- crypto/cipher.c | 3 ++- crypto/ctr.c | 4 ++-- crypto/cts.c | 5 +++-- crypto/pcbc.c | 5 +++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/crypto/cfb.c b/crypto/cfb.c index 94ee39b..a0d68c0 100644 --- a/crypto/cfb.c +++ b/crypto/cfb.c @@ -53,9 +53,8 @@ static void crypto_cfb_encrypt_one(struct crypto_skcipher *tfm, static void crypto_cfb_final(struct skcipher_walk *walk, struct crypto_skcipher *tfm) { - const unsigned int bsize = crypto_cfb_bsize(tfm); const unsigned long alignmask = crypto_skcipher_alignmask(tfm); - u8 tmp[bsize + alignmask]; + u8 tmp[MAX_CIPHER_BLOCKSIZE + MAX_CIPHER_ALIGNMASK]; u8 *stream = PTR_ALIGN(tmp + 0, alignmask + 1); u8 *src = walk->src.virt.addr; u8 *dst = walk->dst.virt.addr; @@ -94,7 +93,7 @@ static int crypto_cfb_encrypt_inplace(struct skcipher_walk *walk, unsigned int nbytes = walk->nbytes; u8 *src = walk->src.virt.addr; u8 *iv = walk->iv; - u8 tmp[bsize]; + u8 tmp[MAX_CIPHER_BLOCKSIZE]; do { crypto_cfb_encrypt_one(tfm, iv, tmp); @@ -164,7 +163,7 @@ static int crypto_cfb_decrypt_inplace(struct skcipher_walk *walk, unsigned int nbytes = walk->nbytes; u8 *src = walk->src.virt.addr; u8 *iv = walk->iv; - u8 tmp[bsize]; + u8 tmp[MAX_CIPHER_BLOCKSIZE]; do { crypto_cfb_encrypt_one(tfm, iv, tmp); diff --git a/crypto/cipher.c b/crypto/cipher.c index 94fa355..57836c3 100644 --- a/crypto/cipher.c +++ b/crypto/cipher.c @@ -13,6 +13,7 @@ * */ +#include #include #include #include @@ -67,7 +68,7 @@ static void cipher_crypt_unaligned(void (*fn)(struct crypto_tfm *, u8 *, { unsigned long alignmask = crypto_tfm_alg_alignmask(tfm); unsigned int size = crypto_tfm_alg_blocksize(tfm); - u8 buffer[size + alignmask]; + u8 buffer[MAX_CIPHER_BLOCKSIZE + MAX_CIPHER_ALIGNMASK]; u8 *tmp = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1); memcpy(tmp, src, size); diff --git a/crypto/ctr.c b/crypto/ctr.c index 854d924..435b75b 100644 --- a/crypto/ctr.c +++ b/crypto/ctr.c @@ -58,7 +58,7 @@ static void crypto_ctr_crypt_final(struct blkcipher_walk *walk, unsigned int bsize = crypto_cipher_blocksize(tfm); unsigned long alignmask = crypto_cipher_alignmask(tfm); u8 *ctrblk = walk->iv; - u8 tmp[bsize + alignmask]; + u8 tmp[MAX_CIPHER_BLOCKSIZE + MAX_CIPHER_ALIGNMASK]; u8 *keystream = PTR_ALIGN(tmp + 0, alignmask + 1); u8 *src = walk->src.virt.addr; u8 *dst = walk->dst.virt.addr; @@ -106,7 +106,7 @@ static int crypto_ctr_crypt_inplace(struct blkcipher_walk *walk, unsigned int nbytes = walk->nbytes; u8 *ctrblk = walk->iv; u8 *src = walk->src.virt.addr; - u8 tmp[bsize + alignmask]; + u8 tmp[MAX_CIPHER_BLOCKSIZE + MAX_CIPHER_ALIGNMASK]; u8 *keystream = PTR_ALIGN(tmp + 0, alignmask + 1); do { diff --git a/crypto/cts.c b/crypto/cts.c index 4773c18..4e28d83 100644 --- a/crypto/cts.c +++ b/crypto/cts.c @@ -40,6 +40,7 @@ * rfc3962 includes errata information in its Appendix A. */ +#include #include #include #include @@ -104,7 +105,7 @@ static int cts_cbc_encrypt(struct skcipher_request *req) struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); struct skcipher_request *subreq = &rctx->subreq; int bsize = crypto_skcipher_blocksize(tfm); - u8 d[bsize * 2] __aligned(__alignof__(u32)); + u8 d[MAX_CIPHER_BLOCKSIZE * 2] __aligned(__alignof__(u32)); struct scatterlist *sg; unsigned int offset; int lastn; @@ -183,7 +184,7 @@ static int cts_cbc_decrypt(struct skcipher_request *req) struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); struct skcipher_request *subreq = &rctx->subreq; int bsize = crypto_skcipher_blocksize(tfm); - u8 d[bsize * 2] __aligned(__alignof__(u32)); + u8 d[MAX_CIPHER_BLOCKSIZE * 2] __aligned(__alignof__(u32)); struct scatterlist *sg; unsigned int offset; u8 *space; diff --git a/crypto/pcbc.c b/crypto/pcbc.c index d9e45a9..ef802f6 100644 --- a/crypto/pcbc.c +++ b/crypto/pcbc.c @@ -14,6 +14,7 @@ * */ +#include #include #include #include @@ -72,7 +73,7 @@ static int crypto_pcbc_encrypt_inplace(struct skcipher_request *req, unsigned int nbytes = walk->nbytes; u8 *src = walk->src.virt.addr; u8 *iv = walk->iv; - u8 tmpbuf[bsize]; + u8 tmpbuf[MAX_CIPHER_BLOCKSIZE]; do { memcpy(tmpbuf, src, bsize); @@ -144,7 +145,7 @@ static int crypto_pcbc_decrypt_inplace(struct skcipher_request *req, unsigned int nbytes = walk->nbytes; u8 *src = walk->src.virt.addr; u8 *iv = walk->iv; - u8 tmpbuf[bsize] __aligned(__alignof__(u32)); + u8 tmpbuf[MAX_CIPHER_BLOCKSIZE] __aligned(__alignof__(u32)); do { memcpy(tmpbuf, src, bsize);