From patchwork Mon Apr 9 13:54:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Salvatore Mesoraca X-Patchwork-Id: 10331389 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 5249E60236 for ; Mon, 9 Apr 2018 13:55:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 44C4328B58 for ; Mon, 9 Apr 2018 13:55:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3950128B5D; Mon, 9 Apr 2018 13:55:48 +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 6132328B59 for ; Mon, 9 Apr 2018 13:55:47 +0000 (UTC) Received: (qmail 17472 invoked by uid 550); 9 Apr 2018 13:54:45 -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 16028 invoked from network); 9 Apr 2018 13:54:32 -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=6NB0vqSoUgWTZAcA6cfxu0y92CQriqdtNfdKQsTwrqs=; b=Tbp/m8cHnpD1KYJ+j9gqMIiTtAQiI69Cv3DHJ7rQZ80gRqdSVKR2nBpI1iNtYrswvU JIzF85MT4vjSSqHkHCwjKte/PRzjkExTT63znXUwRsTE0B37dLeP17iMd4n8Wr0k1/49 tiumMGqwafxvt3/V45iK2A68ljbSIbW7VBxgmzqajA0bLTKfzMi+PF5dFjs5AtwGsxcm iYdo2/M41j+QTmJuuYzmQfRQD8Dl5X2KKOvg1tfZjrlosSp0Xis0DGEazeW4rqXYmuMb WuIsdw7JH5U4Sij78oZlzruWERynLvmndbDvVy/ZKFZvdcEenVxOtnI55ngWRJ91lOYu 8k8g== 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=6NB0vqSoUgWTZAcA6cfxu0y92CQriqdtNfdKQsTwrqs=; b=CSEB5JQh1fv/vi0/soxcFODO1tQezaRT6IMYK2rNWFJaIMyIJLJtCF9V7R9nk/d/g9 d3PR8HkRR+jFPiGJ09YDPRTdgq+L+a31446Zy3LAjIdZLyR2sv4o4C2GlM9z6ZfjlkZN jl6T1/XJbMPgCrwK4iGj4kCtnjjV67gMtd56jJtTi7E+o9qQi7FlABLrH/zLFUb+CgG7 sLgJtOPiSnABleS4jF1VyjUMaUUAMkPO7H6UumzGK3StZ8mWm83x2wWF/VUUPkkbqv8p K0EykoZuaWsSTH3VX6GNWIHEc8rvsDLR4/5isF2EtBRp+t2pyPDwV2bhJYnXqdQmYb2R mfdQ== X-Gm-Message-State: AElRT7FAFADRMqt3ZzBBpz/JyUKaJMMRftcAR2HWvwwxA0eJFXyhRmNf z5AxGugHoOHpHAYUe/65sWc= X-Google-Smtp-Source: AIpwx4+7RalPr41cE8WzW998fl9qB3ZHyNwVHPn9R9gQiYulhqeaAKg3nbFBs8sv4PTucq3oTN5NZQ== X-Received: by 10.223.189.11 with SMTP id j11mr28269358wrh.49.1523282061439; Mon, 09 Apr 2018 06:54:21 -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 6/6] crypto: cfb - avoid VLA use Date: Mon, 9 Apr 2018 15:54:04 +0200 Message-Id: <1523282044-22075-7-git-send-email-s.mesoraca16@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1523282044-22075-1-git-send-email-s.mesoraca16@gmail.com> References: <1523282044-22075-1-git-send-email-s.mesoraca16@gmail.com> X-Virus-Scanned: ClamAV using ClamSMTP We avoid 3 VLAs[1] by always allocating MAX_BLOCKSIZE bytes or, when needed for alignement, MAX_BLOCKSIZE + MAX_ALIGNMASK bytes. We also check the selected cipher at instance creation time, if it doesn't comply with these limits, the creation will fail. [1] http://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Signed-off-by: Salvatore Mesoraca --- crypto/cfb.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/crypto/cfb.c b/crypto/cfb.c index 94ee39b..f500816 100644 --- a/crypto/cfb.c +++ b/crypto/cfb.c @@ -28,6 +28,7 @@ #include #include #include +#include "internal.h" struct crypto_cfb_ctx { struct crypto_cipher *child; @@ -53,9 +54,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_BLOCKSIZE + MAX_ALIGNMASK]; u8 *stream = PTR_ALIGN(tmp + 0, alignmask + 1); u8 *src = walk->src.virt.addr; u8 *dst = walk->dst.virt.addr; @@ -94,7 +94,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_BLOCKSIZE]; do { crypto_cfb_encrypt_one(tfm, iv, tmp); @@ -164,7 +164,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_BLOCKSIZE]; do { crypto_cfb_encrypt_one(tfm, iv, tmp); @@ -295,6 +295,12 @@ static int crypto_cfb_create(struct crypto_template *tmpl, struct rtattr **tb) if (err) goto err_drop_spawn; + err = -EINVAL; + if (alg->cra_blocksize > MAX_BLOCKSIZE) + goto err_drop_spawn; + if (alg->cra_alignmask > MAX_ALIGNMASK) + goto err_drop_spawn; + inst->alg.base.cra_priority = alg->cra_priority; /* we're a stream cipher independend of the crypto cra_blocksize */ inst->alg.base.cra_blocksize = 1;