From patchwork Mon Apr 9 13:54:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Salvatore Mesoraca X-Patchwork-Id: 10331375 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 33B926037F for ; Mon, 9 Apr 2018 13:55:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 269C628B57 for ; Mon, 9 Apr 2018 13:55:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B3D428B59; Mon, 9 Apr 2018 13:55:29 +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 49D4428B57 for ; Mon, 9 Apr 2018 13:55:28 +0000 (UTC) Received: (qmail 16030 invoked by uid 550); 9 Apr 2018 13:54:33 -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 15923 invoked from network); 9 Apr 2018 13:54:30 -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=tbVjcGKYXycmvL6dYVhUCexsZxkVk24PJDqpfmRLSDELco2sveYD6xUbk5L+MRmXx1 /GS7gDawP4kve3bpTsSR+Kk68PQbvQHhI5ouKbB2Q9M1K8QcKTXUexxqy5jYaNm2y6zc gam+tHCANlQaINSigG8NuWfSIovjMr8SZWPvPV4Xxe3h8zMD4O7+AkQsAyRB01M9i37a 936ZtQc0DIwAF6Un0ZIvKBRyFleRzty5+JRRKyZXQQcTGdaZWxrXwVeWniYVbfSV5UJL dPoMhDuylh0h/CHK5Ytv6Xs/iLVvjTDv0LM/gXXv0D/Yw7SVzN5E3pmBroVSzcmoPgTy i5ig== 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=JqHlzmBtzoNAhAQOpEgtkTya8MVfya7hPgT9Wbo5RaFs9xE74vLWq0OQSZp1EevXJn xx0fspNpf0rHBjSdtuPER86esCuvf/aidpVmnZVl6z6IY1+wYEEXQR7X/LzReHApuGB7 KxqszXflVeUeXZVKowdX2eNFlAX4XmKhFahl1W0fFkrGciSxEHD9ZQvuYTq9PpSZZk9s wfBoYc/olafz3siWpnCIRidsp4I6iMFlMxEQ8n1wMpInpGRZ8dXdaa2sqRSG+qneEnEQ 43+Zissil4ae5KoR3yX78pMEIBnar1ea72KCP6f7Q2NXpAmweDZcSdtDu+eE3um7lxVx XTQQ== X-Gm-Message-State: ALQs6tD2OKAUAttrTzapZHTpfB7vNSjrF0ahu/7iBkgrdt/wQWzOT9so xmuSXW/ANA1TtmJvSTlkzmk= X-Google-Smtp-Source: AIpwx4+f7MX+1iIZi+haaSO0XWvPJoAMzqj2QC9llUA4NDSjUaK9G2AcKrLoc5OFQwoSLQxfc1jt/A== X-Received: by 10.28.232.206 with SMTP id f75mr45476wmi.121.1523282059330; Mon, 09 Apr 2018 06:54:19 -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: Mon, 9 Apr 2018 15:54:02 +0200 Message-Id: <1523282044-22075-5-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 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;