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: 10328001 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 415106020F for ; Sat, 7 Apr 2018 18:39:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 331CA294D5 for ; Sat, 7 Apr 2018 18:39:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2769B294E1; Sat, 7 Apr 2018 18:39:52 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA84C294D5 for ; Sat, 7 Apr 2018 18:39:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752564AbeDGSji (ORCPT ); Sat, 7 Apr 2018 14:39:38 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:35643 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752262AbeDGSin (ORCPT ); Sat, 7 Apr 2018 14:38:43 -0400 Received: by mail-wm0-f66.google.com with SMTP id r82so8498743wme.0; Sat, 07 Apr 2018 11:38:42 -0700 (PDT) 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=ZZJu0/C4rrpxsUgCb1iBdandhhf0cPRfe8J8Q/KASpZD7mbP5zsnDExGfv+kkEYWC5 csdtHhaNNp6eN46VCLXh9WelCjUBCBNAj92Di7wbeiWjNFrIlXTl8gg+0A5jInclTD8O 1T1vVPyi+NkYMCtUWoPAsREvXRNFErnkIVhi2EJtzu4l9h2R1WX6hVbFwt7PN/5ffg/o 1HM2mn4wSov8vHITF1ZL1wJ8eOQFzqfNbX2wiV7ZfQHeVytU7e6701oqmLcTPOss5YXk f59ehQVGDBMQ3eN+J3rgq5GN+BgHBNVOkFGeBuZLY/KfKVeZEOHhXM3svkqsWlAWWLy9 KM0Q== X-Gm-Message-State: ALQs6tD9xCQpf8N40nZu7uAD1hGjs0qsT7A5dBioLer6eDML0EEb6+mh YnCYD0Ov3P3T8tckoy2rXkdoO4pvOB0= 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) Received: from localhost ([31.159.162.22]) by smtp.gmail.com with ESMTPSA id m184sm7135034wme.15.2018.04.07.11.38.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); 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> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org 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;