From patchwork Mon Apr 9 13:54:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Salvatore Mesoraca X-Patchwork-Id: 10331379 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 6B3F36037F for ; Mon, 9 Apr 2018 13:55:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F37828B57 for ; Mon, 9 Apr 2018 13:55:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 53B5F28B59; Mon, 9 Apr 2018 13:55:38 +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 5D79A28B57 for ; Mon, 9 Apr 2018 13:55:37 +0000 (UTC) Received: (qmail 16265 invoked by uid 550); 9 Apr 2018 13:54:43 -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 15961 invoked from network); 9 Apr 2018 13:54:31 -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=aCA0tdrK7gKKHGaOm7k9v+Op4jZ//ONvLpAucd8QDKaj5g6Kt0RajmMNlIVR9A2yxy a6Sr8cPwUkMUTONXtKpCBm56V6MzHNHstIbvoWS8FWmd+yuVdiDn6LqNIJISV4WYRiUh 6d/rSBDWA/VMcs64gPkDF3LZeMbsxuxToR5eQ6ycoipwEnBJ4PvFaUtYtiBwvrao8k0R uIGKHPi9FbyBJBZAWTDLOCOAknQSGSnnoifS4Qq/fCjqh3ub8bdCebeZbtfy4cW1SNJA vk4YVNOyLnxTpXS9zmRVaK86XpHPmKG5xalf9MQ58jja39dLJcHTOG83mb8vc2oWYHKU oQxg== 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=MsYmuwzZZBmTf5xyulr9YazU4Bf/X5/QK0dIlw25Ff/118UeLs7cXl7jrZ55KmY1Vj gOB4QK3lcC05pKsbSGE3kclCEl+7CiiOafhXiMUJ3RlHMHrzSmbLtT0ALfAY5H9iIzmU lieFvAtWXy1Bap/qjTK92forq7qQHFPK25y2QbCdeecFhwmKs9kWcAaHcJ08APpd8++x q3SH6mLFHPXiNM8rVrHju/dQWrLlya1FWPisgC+ADhjPTsIjNdziaC//Y5g8abwR2z4S NOzogxuL0jZn7fSn3/4e5RtyESZiDtNu3iSzkDHgxPHzQ5DZBoxGFif0Vmir+aiBRrzg M3kg== X-Gm-Message-State: ALQs6tAXXUuyV6YimImn6OmlPpeBVCspHDq6jKrqhvUAQm9RiOSRx+EM 3XKIo7VZRrTPSEppujH8oZQ= X-Google-Smtp-Source: AIpwx49SbMyUAXO8KmEAUfZmeASL61vRSGYRD3BVpdZAoaaI8gvlJxYpxdcZnL77oIkd2dBgD/LHXw== X-Received: by 10.28.18.199 with SMTP id 190mr84178wms.50.1523282060403; Mon, 09 Apr 2018 06:54:20 -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: Mon, 9 Apr 2018 15:54:03 +0200 Message-Id: <1523282044-22075-6-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 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;