From patchwork Sat Apr 7 18:38:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Salvatore Mesoraca X-Patchwork-Id: 10328003 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 103DD60365 for ; Sat, 7 Apr 2018 18:40:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 011E9294D5 for ; Sat, 7 Apr 2018 18:40:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E69DC294E5; Sat, 7 Apr 2018 18:40:04 +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 19357294D5 for ; Sat, 7 Apr 2018 18:40:03 +0000 (UTC) Received: (qmail 12198 invoked by uid 550); 7 Apr 2018 18:39:02 -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 11988 invoked from network); 7 Apr 2018 18:38:53 -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=bvfZVgukrG4Uz/3K/kgiuiCeoBiYKZFn3z8Tr50BqHA=; b=CkE8ofFRyH7+mJ+Iym+nm+j+keHO7+LBHiFV6Fbyr0lFTjUvGFsSXpK9yvohJAVoSw riMw3EJcaE3b4/mSkvVQ87TX9DXRfRZS18F7dWTyPUDtE8sDL8Nd1mNcVZ3yNI3GYY1O V0qArxLhcCrgAYDIexfLNv0EhmJpn9TjSLWSbCzYKElBHNu04Bj9y6/z8Qt3St7q70xy LPGjR0i4JMe+p3OpROrdIWIRV4nn/qzJE76iuDl8+e3NgCvXzzOviD1R7l8py/JATLpE OblkrlZXTWdlH1c/jLf2+vhfW3+4r+yPFIjUIXfZighl3EkWrC+ugFOGqAShCnGeNauf RGPw== 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=bvfZVgukrG4Uz/3K/kgiuiCeoBiYKZFn3z8Tr50BqHA=; b=cZ1DAPLpuNFROVC3Cw/wd9ylTHLPwxcrMfdLP+6kPjL5nwqM6dYVsl3gACxpnuzXQ4 3Bs89DPGJqZDE8VFLFjEH0qPCsbTMVYtE/OHpxoc15TFsDQkBKs8b63F+F1fo44y18LI WEuBJGRYwUHAQ5cnUd2FAxO/PshiGIc4OZfQBWm7g+RucvMqc1gc32XWGpEyMLIwRjI5 Zs+zjrAZsZhJ4jKqMW1kTOcFcdNb9as8O/FhS6YUb25RlzZIrHgw6xfLNzCLNc0bwiXu PwIo8akpa3JOAusU1tkY1Es4wY9w2+DpTsXs/Icmc5l5ipcGx+mGUwIlziqQoG8Us/hV l5sA== X-Gm-Message-State: ALQs6tAqL1VdNIS4YwqLg7Y2TkM6AkTyTRwU6sxJ2WUc9QkoxTtenQ0h 1Og91HTOoYLwg3dZQX8p/uk= X-Google-Smtp-Source: AIpwx49MWY/02B5Zyqon4L+hb+yhcVxSYBtdzJ3GS/W6cBDJ9+ATTQsqdPQaisYCZ+CSBFzvR1iusw== X-Received: by 10.28.134.203 with SMTP id i194mr18787689wmd.114.1523126322675; Sat, 07 Apr 2018 11:38:42 -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 5/6] crypto: cts - avoid VLA use Date: Sat, 7 Apr 2018 20:38:22 +0200 Message-Id: <1523126303-23205-6-git-send-email-s.mesoraca16@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1523126303-23205-1-git-send-email-s.mesoraca16@gmail.com> References: <1523126303-23205-1-git-send-email-s.mesoraca16@gmail.com> X-Virus-Scanned: ClamAV using ClamSMTP We avoid 2 VLAs[1] by always allocating MAX_BLOCKSIZE*2 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/cts.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crypto/cts.c b/crypto/cts.c index 4773c18..12e6bd3 100644 --- a/crypto/cts.c +++ b/crypto/cts.c @@ -50,6 +50,7 @@ #include #include #include +#include "internal.h" struct crypto_cts_ctx { struct crypto_skcipher *child; @@ -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_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_BLOCKSIZE * 2] __aligned(__alignof__(u32)); struct scatterlist *sg; unsigned int offset; u8 *space; @@ -359,6 +360,9 @@ static int crypto_cts_create(struct crypto_template *tmpl, struct rtattr **tb) if (crypto_skcipher_alg_ivsize(alg) != alg->base.cra_blocksize) goto err_drop_spawn; + if (alg->base.cra_blocksize > MAX_BLOCKSIZE) + goto err_drop_spawn; + if (strncmp(alg->base.cra_name, "cbc(", 4)) goto err_drop_spawn;