Received: by 10.213.65.68 with SMTP id h4csp880885imn; Sat, 7 Apr 2018 11:44:33 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+W7WWRnoOHzh/1091n2X8IqBsAioYikbluLjk30o6qwx0bfR9rHLbcWOR0QKxh79SPP86P X-Received: by 10.99.179.3 with SMTP id i3mr20854936pgf.434.1523126673696; 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=AU7ovWL1h9KvpznrR2dBP/Ege9lZLvWtG8mQhpTovrhlbMbM1m0RsZqxdh3Onz/Yw9 4f591OUTJZizo8PO8ntuO6Z10WOkUdyA3O6mrxtyKBhd4VndvbAB4x0QBCEQOI6uuB1M e+20Ol70HenqwpzUdQZRccvS2uYuJuGk7ZzNZDh2KG9I45uCIbguQ6xBv5qShJjPV7EE m0wnli5ha96NxlcKi+slY8YE9pvT/G0tDKXyFJJ3ORXHDKO+i2wcohTpRj2t5ukcT3iW aNIO4FtfDXBDg8VYSwPA9+IuGXZANtMXrznqt5gs+IFGtmeWc9aszNs4FuBZ0jaPv/dm ah9A== 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=oZJHlz74leLbB95syiNmkrgCZhugYvoNKD0PdVRJfUI=; b=PdYtpQOB29+MeVxbbBkLaselQF3JrE609//K1OXpmdiTLa/RNAN0mBY2ux95hMy90L s/xOCvycTpQnRZ1pPjM0ML9wtXHIFyKK2JkgF7dfbCgXNXrn8tzSMXf1NK/HfJC1tcTE Et+9Q9Kxh+a7CqR4o7dHXCDrnwa51CuiT4j7H8ThUrni2Cz4yXkJNF6lVdW8E4NMZhGw haYyZtAPpAkfA9F4q9h2RrjT3WKep7Y+OGSWcYYULT46cOXtby1ESR2xUCFjnPBVpNlF JfPtE+A379+FLtAVceMoJgHnH5MHDiRZ7d3xDYDxIAjit6U4IZLX0sFiYzTplZ1fT4fM b/9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=LTYSPFeE; 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 n76si4817154pfi.122.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=LTYSPFeE; 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 S1752391AbeDGSiq (ORCPT + 99 others); Sat, 7 Apr 2018 14:38:46 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:54126 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752191AbeDGSik (ORCPT ); Sat, 7 Apr 2018 14:38:40 -0400 Received: by mail-wm0-f66.google.com with SMTP id 66so3046145wmd.3; Sat, 07 Apr 2018 11:38:40 -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=oZJHlz74leLbB95syiNmkrgCZhugYvoNKD0PdVRJfUI=; b=LTYSPFeE9cfuZVF/qoPy1gom1rdJoEKa/tT6EtM2Joe1UHuXd/h/t5WNDnOTeIVoNr ZYPC41zW33909bAjJVLGUYlBHe8TNsAqoPRUz5wUNg6G3BWBTE0Pr5f6moWjIxp2hXe5 8hy6ToCDtw7fR/tPXePT5mFVaTv+hr6YEZa3w7oEMvNSEKZ0PCJ2u3/qfm6XW6fIqVyG 34hCsHhtFltcJMdme75W6ir6HnOdjUqQaIV+wZXrwpBzL0ABae9cZznRA1np1cyT5pt7 RlVKn90I6S6WZlv9gQ/h1ZNDmkOA6bVsw13IfuraqO75oEdHAm5MuTm2oIx+Kfv/GdT0 CO8g== 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=oZJHlz74leLbB95syiNmkrgCZhugYvoNKD0PdVRJfUI=; b=A857N8zPTsFv0hK2MVpuNESkoxaNaH7otBocMfHbu6i74f5tBx5kWNE0W4XBmPHa2+ S6bo/roLuK42v1uDOt+ZM9VDS48FT4k1SrP/Cz3Ezwh6eCnk38RdLbxUHj/7XBNarrcG Vvlkdo8EA0Eiunj26QaBJH5naFImAq6RtrMKfoa/TNXN389wzR/segGaa3g0c07JMrb7 YqnDIzWMi1U26rfJdQvQbub24z01QEHywl7dofiVsALZOLY/ihqHsSKbtbzzrll1S0bh wU3XbSpe1jRgVjt9+hjTTN8/cFLsK63xNNN350Eel7shRsviawXpSygOriVxPxSnGeMp OPAQ== X-Gm-Message-State: ALQs6tB5WB2dWBik4Zs0uqnBDk9dDdtUE/vLJlSQHO6V+jHw3DF8Hjhb 06vOvErbj91LT6yj4c27Miq9yoC9f9g= X-Received: by 10.28.234.207 with SMTP id g76mr17809015wmi.149.1523126319350; Sat, 07 Apr 2018 11:38:39 -0700 (PDT) Received: from localhost ([31.159.162.22]) by smtp.gmail.com with ESMTPSA id m184sm7135034wme.15.2018.04.07.11.38.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 07 Apr 2018 11:38:38 -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 2/6] crypto: ctr - avoid VLA use Date: Sat, 7 Apr 2018 20:38:19 +0200 Message-Id: <1523126303-23205-3-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 2 VLAs[1] by always allocating 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/ctr.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/crypto/ctr.c b/crypto/ctr.c index 854d924..ce62552 100644 --- a/crypto/ctr.c +++ b/crypto/ctr.c @@ -20,6 +20,7 @@ #include #include #include +#include "internal.h" struct crypto_ctr_ctx { struct crypto_cipher *child; @@ -58,7 +59,7 @@ static void crypto_ctr_crypt_final(struct blkcipher_walk *walk, unsigned int bsize = crypto_cipher_blocksize(tfm); unsigned long alignmask = crypto_cipher_alignmask(tfm); u8 *ctrblk = walk->iv; - u8 tmp[bsize + alignmask]; + u8 tmp[MAX_BLOCKSIZE + MAX_ALIGNMASK]; u8 *keystream = PTR_ALIGN(tmp + 0, alignmask + 1); u8 *src = walk->src.virt.addr; u8 *dst = walk->dst.virt.addr; @@ -106,7 +107,7 @@ static int crypto_ctr_crypt_inplace(struct blkcipher_walk *walk, unsigned int nbytes = walk->nbytes; u8 *ctrblk = walk->iv; u8 *src = walk->src.virt.addr; - u8 tmp[bsize + alignmask]; + u8 tmp[MAX_BLOCKSIZE + MAX_ALIGNMASK]; u8 *keystream = PTR_ALIGN(tmp + 0, alignmask + 1); do { @@ -206,6 +207,14 @@ static struct crypto_instance *crypto_ctr_alloc(struct rtattr **tb) if (alg->cra_blocksize < 4) goto out_put_alg; + /* Block size must be <= MAX_BLOCKSIZE. */ + if (alg->cra_blocksize > MAX_BLOCKSIZE) + goto out_put_alg; + + /* Alignmask must be <= MAX_ALIGNMASK. */ + if (alg->cra_alignmask > MAX_ALIGNMASK) + goto out_put_alg; + /* If this is false we'd fail the alignment of crypto_inc. */ if (alg->cra_blocksize % 4) goto out_put_alg; -- 1.9.1