Received: by 10.213.65.68 with SMTP id h4csp880884imn; Sat, 7 Apr 2018 11:44:33 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/A0oTz9ZbaCj+jMl06pWMRsf3zZEuN3q1koAUTqoWlvHPJGpQzBdc8MkVWYMr2FLtAhZmM X-Received: by 10.98.181.20 with SMTP id y20mr12574118pfe.102.1523126673690; Sat, 07 Apr 2018 11:44:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523126673; cv=none; d=google.com; s=arc-20160816; b=k80apEyyC5GzxL8+GhqOZERCKMMmCGweKUqBAX64djimSnUNROikaY1X9+PPbLeSJE IOuxRI4uOehtrsUIBsilXdClUs6KIGEhH+ffizcpEFEyKhtLa5Q/RhoqSBqGLj9YRuNq +1Ngu4qDmMJws2A/jEMmwzTGPpNVxaGTNMsTp76n9G9+Ub5SNdp6xmfPIKW+XKoVhJy8 kLpvjF+cHFZgesgxk0IEuVYp7BxTXJGei8m17DpUPVZ6N8nWPawj04grQsb+F86YBLo0 GMGZpKl3yJYoALLXhDuz1YU+tMHWDNXzPnGkSmGutL4bU5rYxPsGU7Mm+LSrNLWTNZ4x nrgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=6NB0vqSoUgWTZAcA6cfxu0y92CQriqdtNfdKQsTwrqs=; b=WB64Cr75jLfhjPxBdBCbnmkui2Oz89dwRCoELMvP8PC6wJ1eDLg4yoW5+QI2d1v33v EcWiTuNO3EYJIU3DPy4qw1JzZU2Ov07aL+54w78sPvq+r7CzJ5rXZE7xEXxUGBAE6Evy ncEkkNZ+ooFnRfrlCZUN0yLdcnXk8Pl+wRTzKX039NkUQl/Rq0x9pD+DPawsPFnVGeWa 3prouUa1NtEXweR9OtsG4mYLVi1965QWv7twmzjHwf31mbMmZhgkHZ9CuyXE7rGw2go3 2awQ/mzGVGY03vn+ZDf96no7BLGYmGavFk/9fHgjKR5el7bq/mVny5nU8Z93J+wis3wv jmDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BNZY2eJb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n11-v6si10259071pls.699.2018.04.07.11.43.27; Sat, 07 Apr 2018 11:44:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BNZY2eJb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752467AbeDGSjC (ORCPT + 99 others); Sat, 7 Apr 2018 14:39:02 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:33784 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752320AbeDGSip (ORCPT ); Sat, 7 Apr 2018 14:38:45 -0400 Received: by mail-wm0-f68.google.com with SMTP id o23so11749263wmf.0; Sat, 07 Apr 2018 11:38:44 -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=6NB0vqSoUgWTZAcA6cfxu0y92CQriqdtNfdKQsTwrqs=; b=BNZY2eJbn/ndsWGm/hOLc1k3/6gl+VP2SIWtf1LM3c6tZvxxsmwCS+gg4r1WHrcCab J6ti7wHfRjyChR2WiU2tfPWVHe4EZrEPMURTFeQgcLhXpQGnP5Zo/q2VrwwJyjCB0Ldu nVmqo1QNNyI9rB/4GG4fcTcayT9londCZJKvk3rDRas5JladMuvcP4H0NdPyC/zMk7U/ tGjST4vVVFR+43iWByVdJEYZRSxxBkxhlJfjLZo2LUkOAmxYuRm3Rgat/wx2PGxYwTe1 MVUPP1Pa+pOPHEsUMjzNuy2AgbL9KI1mzxy6JJA93dE2tUgTPJnWdfXE6+k/DPRR8IFK hS0w== 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=6NB0vqSoUgWTZAcA6cfxu0y92CQriqdtNfdKQsTwrqs=; b=nXXulKTzm4SXqQ7C9rL9BVjhNqNKKV7pPV7iWQJnKff0qSsACoy5cgAhoIuCGR7Yjb /+ASactyXiP14LDvns2sZ8QLfENKtrrM9GvsG1LRg+18ec/UkBHmj6UgU4EQus/+fDla Of7ek6I8qScc2ZgN8/DqHkmWpYNGm/31U4R1TsUTHfX4CyRzfWj2ba9Hh+oidMBSzpeY HcSJKo5qLsHXDzpeLE4H/KME9oYWphzIc65OHBhR7fiD9hb8khG4sZrYqM2FxR5cH/ll ksy2HreH9374LvavbXx2gVNJA1uln5p7br/7zpO8yKpdu6696415kxbkSoZFOnWZBLWT C2Zw== X-Gm-Message-State: ALQs6tCikHL/fy6j/FxGc1PXz33LIJsp1K1ETGQDQrqt5fw4QZ3GoNi9 /+mBie0Mtry1c1mdMxHZQN/cKOGayvYULQ== X-Received: by 10.28.15.15 with SMTP id 15mr13336120wmp.60.1523126323793; Sat, 07 Apr 2018 11:38:43 -0700 (PDT) Received: from localhost ([31.159.162.22]) by smtp.gmail.com with ESMTPSA id m184sm7135034wme.15.2018.04.07.11.38.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 07 Apr 2018 11:38:43 -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 6/6] crypto: cfb - avoid VLA use Date: Sat, 7 Apr 2018 20:38:23 +0200 Message-Id: <1523126303-23205-7-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We avoid 3 VLAs[1] by always allocating MAX_BLOCKSIZE bytes or, when needed for alignement, MAX_BLOCKSIZE + MAX_ALIGNMASK 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/cfb.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/crypto/cfb.c b/crypto/cfb.c index 94ee39b..f500816 100644 --- a/crypto/cfb.c +++ b/crypto/cfb.c @@ -28,6 +28,7 @@ #include #include #include +#include "internal.h" struct crypto_cfb_ctx { struct crypto_cipher *child; @@ -53,9 +54,8 @@ static void crypto_cfb_encrypt_one(struct crypto_skcipher *tfm, static void crypto_cfb_final(struct skcipher_walk *walk, struct crypto_skcipher *tfm) { - const unsigned int bsize = crypto_cfb_bsize(tfm); const unsigned long alignmask = crypto_skcipher_alignmask(tfm); - u8 tmp[bsize + alignmask]; + u8 tmp[MAX_BLOCKSIZE + MAX_ALIGNMASK]; u8 *stream = PTR_ALIGN(tmp + 0, alignmask + 1); u8 *src = walk->src.virt.addr; u8 *dst = walk->dst.virt.addr; @@ -94,7 +94,7 @@ static int crypto_cfb_encrypt_inplace(struct skcipher_walk *walk, unsigned int nbytes = walk->nbytes; u8 *src = walk->src.virt.addr; u8 *iv = walk->iv; - u8 tmp[bsize]; + u8 tmp[MAX_BLOCKSIZE]; do { crypto_cfb_encrypt_one(tfm, iv, tmp); @@ -164,7 +164,7 @@ static int crypto_cfb_decrypt_inplace(struct skcipher_walk *walk, unsigned int nbytes = walk->nbytes; u8 *src = walk->src.virt.addr; u8 *iv = walk->iv; - u8 tmp[bsize]; + u8 tmp[MAX_BLOCKSIZE]; do { crypto_cfb_encrypt_one(tfm, iv, tmp); @@ -295,6 +295,12 @@ static int crypto_cfb_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; + if (alg->cra_alignmask > MAX_ALIGNMASK) + goto err_drop_spawn; + inst->alg.base.cra_priority = alg->cra_priority; /* we're a stream cipher independend of the crypto cra_blocksize */ inst->alg.base.cra_blocksize = 1; -- 1.9.1