From patchwork Sat Apr 7 18:38:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Salvatore Mesoraca X-Patchwork-Id: 10327999 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 9310860365 for ; Sat, 7 Apr 2018 18:39:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 83973294D5 for ; Sat, 7 Apr 2018 18:39:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 76AA9294E1; Sat, 7 Apr 2018 18:39:51 +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 A4C0F294D5 for ; Sat, 7 Apr 2018 18:39:50 +0000 (UTC) Received: (qmail 12078 invoked by uid 550); 7 Apr 2018 18:38:58 -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 11959 invoked from network); 7 Apr 2018 18:38:52 -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=otcFk/LhYCI6+Eka1h1DNCCDW9Ubad/bpWI6UKakoZM=; b=IF08NNkU/0E5Yl4pZVK69mQSgCjiFOrFLz4VjcdIe6gLEqwWNKbdZx2kUeKMWJQ41V 7wV+SeNztEGSebiTqtxTt00QwLOR4eEtvOV33i7L7KTC7kW6peNOADIXKbCN5lNLARYo boIllw7tAZq4mHIGCu8t2ILCK3lab3MftGc3XNWaNb6vRhqSZkWyLSI3N3bEGqeOYCvm SDwiAeVHtNWpJ7XHs3w2hv9mM+GN4ZN+mhIcjgVKT7zc+mdNqdZh+B5ttxi82d5Js+ix 1aX6oK8zzOFpnj4YpB/K/5eb9Y9X1tMG9l+B0zK4yhpj1YBJBPO56fQ5+d2YGTkcPOiH szew== 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=otcFk/LhYCI6+Eka1h1DNCCDW9Ubad/bpWI6UKakoZM=; b=eQwxewY0/7O116p9saRb5/Bo0o569RYx1mXtFk9J54x71WeFum+du9MlV6jFVBN2Tz RAtf74HmjV3E355h/47JsSr4/FRXBSAEpwAHHeE+XlCgDTy8n4w8v1n32gaWWFc7VRTw m2I7qDbIFxkLH/JKB27FUa8VkouIQaNfQfecRK9PQGsf0dkkvJMTgxzDNnw1YajKq9vJ 9KLcsmWuhEwXh4FyytPGDQ7nNWfzWqI0dFvXc7oMjSoncfY+SvWg5zcbwZV7tPnn4Ait Wj9Aq8i7XuGbOuR01N1W/SldSrB5TlIxsgK7BFvqEP9WUqj6YAQa0tCIPHIL6uXJbbQI 3jxA== X-Gm-Message-State: ALQs6tBQ/X2gHbkJKyH9Xy3aGmNMRNemIj9achWgL5HCL97/7a3Mc12+ lGl/II7gvcZpX/Dei9Xfy60= X-Google-Smtp-Source: AIpwx4+WS0BHXSwmiU9iNbLQDAm/EG/nbIV382vBWPRogZyDKsITsA81hFtHBK/K46EFdpx1kW/iVw== X-Received: by 10.28.207.201 with SMTP id f192mr15343702wmg.148.1523126321532; Sat, 07 Apr 2018 11:38:41 -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 4/6] crypto: pcbc - avoid VLA use Date: Sat, 7 Apr 2018 20:38:21 +0200 Message-Id: <1523126303-23205-5-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 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/pcbc.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crypto/pcbc.c b/crypto/pcbc.c index d9e45a9..797da2f 100644 --- a/crypto/pcbc.c +++ b/crypto/pcbc.c @@ -21,6 +21,7 @@ #include #include #include +#include "internal.h" struct crypto_pcbc_ctx { struct crypto_cipher *child; @@ -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_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_BLOCKSIZE] __aligned(__alignof__(u32)); do { memcpy(tmpbuf, src, bsize); @@ -251,6 +252,10 @@ static int crypto_pcbc_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; + inst->alg.base.cra_flags = alg->cra_flags & CRYPTO_ALG_INTERNAL; inst->alg.base.cra_priority = alg->cra_priority; inst->alg.base.cra_blocksize = alg->cra_blocksize;