Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1400677imm; Wed, 20 Jun 2018 17:48:12 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIQFLDK8q1bxN/PqzVS9g9RjevAI/WHiAya6QSJtomDz/gY2I05sg/uqSyc+AdEOfviIbt2 X-Received: by 2002:a17:902:b20d:: with SMTP id t13-v6mr26392406plr.121.1529542092948; Wed, 20 Jun 2018 17:48:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529542092; cv=none; d=google.com; s=arc-20160816; b=ui01qp5PQJULWGNiY5BWYoiFe/3MBqBuaCs7Cb8yFHKfekhmZvdjvThVurnYEsRs4h F59/lajPqRu8vSJ87dwASKcOtbTscj+A3ymD36sfN3XdNLymefK8+/e9OV5ha6OUntIA Y68OXeMG3bY9ars5pLxhxqxrFvt+f4J0a6wdEEErYKVwfVrOK47hEx/pOEoWY/IuOanM x+pqrhCCoJnlHXyVe+58SrBYclyqD5Qj6Ni8Mepjc8881noVPG7FdjnLH1semO0PcPX3 IRDg3kFsbZzQOTAA8ZDAfkK6ERrdbHbJChlzvKe0g3+0KBe52iMtw9ht1msld3D1dg4z rqeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=YmfUs0oMycm2fIrTWEN593Jb7ubVDybFOSbgfOjOK6M=; b=jAPRF8XHi4FoN92/Glk6Uw3KvQo2eWLIsEuwIElWWVdWF6q0slb+yo802JbtCHgr+I El/QWkXuKUWikXSW1pbBjtY3aD5LNlQQSZZRY0JtJTrGJ5ymVmnguqUZk+0SfDmzmDO3 ypKXyTX5pJqNu5wTbQYoGcjqjwHy9tmZcv3ooY/P36fKcwn60wP2P72fdP6IRipUV/YU jja0gvZoRugjYLm5FnRN9BTOPx8B8Myy/U/foVPSKdNjxrI25apC8pnQN4XknQfU7MUJ nTIpupkLNhng98qmasmjRFJwsM3fxL+YzbxnxDr9EN6AQL/jxnT9R9hjrVajXnpNCcJJ 6sGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pmzkCKIH; 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 f2-v6si3023966pgu.457.2018.06.20.17.47.58; Wed, 20 Jun 2018 17:48:12 -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=pmzkCKIH; 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 S1754433AbeFUArU (ORCPT + 99 others); Wed, 20 Jun 2018 20:47:20 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:33254 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754099AbeFUArS (ORCPT ); Wed, 20 Jun 2018 20:47:18 -0400 Received: by mail-pl0-f67.google.com with SMTP id 6-v6so683893plb.0; Wed, 20 Jun 2018 17:47:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=YmfUs0oMycm2fIrTWEN593Jb7ubVDybFOSbgfOjOK6M=; b=pmzkCKIHUJTxFiN3vOb4YPXISo1Xe1Rjj8wS8nyFcygXiplc9w8J+DxlhVvUVUw67+ U3IOLJGvtyvgx0kQ8CmAEBXuOAopdTTp4qOV9PFZ3d/IsmsHyX4fXBpHf5psW3NxgBLe 01WFy6w4LW75NraArPjZ131UVxvqcqIU5ldPMyvH47MbgEy5MvxRnaKruD7neu4vLKtj 4zvKUHnlqst6akjCcgednSjOlDQNR3gpKjHOyHyNVb6e2b3x59lME5OItfBYPP5YCY5D rtPD2/cABb7i8NobZYCl/QXLJOTijARqCq5VFwRAhE9r3tjdBuZB3UssFjPu0n4RJL/l Y17A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=YmfUs0oMycm2fIrTWEN593Jb7ubVDybFOSbgfOjOK6M=; b=edwaEX0LjiwM5g6s2uwv/xgKT46K5XyG13sqav5EUdnrFXf9pjiwbofPYyHjFTsqvA aU/wEspgvDQDzx7WkaVYBcijPeRVffinQau0FW0bY3kU/NNYRr5P7RrEVF7Sfiw4VZv8 qBQwWduMdsLt9aao0CojCwEVpx3gG9mjFBO/bYJiR4GCnmPoB+Subu6yEQxj/NgbLCyJ oL90NDEA11Hw6h1K0kQPrbGLv3+WE5gDRKj+lrbsRbtotrMMbv4kJNFYStSkDkz2NX0K JT9xdvzh/Sx6X7VtGFyKKpoMQSUq9rPlSwuIt91tIzlFllHfR8IxBMnSL7xsbVG2+DaQ oRcQ== X-Gm-Message-State: APt69E1/QnFIZ51QPFE8z14/l7sDdtYtdclqSfqnjHmkajrI5TsSQWkz ojsZAAOMWmpT8z+2VRRV3do= X-Received: by 2002:a17:902:778e:: with SMTP id o14-v6mr25820016pll.214.1529542038034; Wed, 20 Jun 2018 17:47:18 -0700 (PDT) Received: from gmail.com ([2620:15c:17:3:dc28:5c82:b905:e8a8]) by smtp.gmail.com with ESMTPSA id j8-v6sm9507083pfe.84.2018.06.20.17.47.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Jun 2018 17:47:17 -0700 (PDT) Date: Wed, 20 Jun 2018 17:47:15 -0700 From: Eric Biggers To: Kees Cook Cc: Herbert Xu , Giovanni Cabiddu , Arnd Bergmann , Eric Biggers , Mike Snitzer , "Gustavo A. R. Silva" , qat-linux@intel.com, LKML , dm-devel@redhat.com, linux-crypto , Lars Persson , Tim Chen , "David S. Miller" , Alasdair Kergon , Rabin Vincent Subject: Re: [dm-devel] [PATCH 07/11] crypto: xcbc: Remove VLA usage Message-ID: <20180621004715.GI111712@gmail.com> References: <20180620190408.45104-1-keescook@chromium.org> <20180620190408.45104-8-keescook@chromium.org> <20180620234623.GE111712@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10+28 (db52f11e) (2018-06-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 20, 2018 at 05:10:04PM -0700, Kees Cook wrote: > On Wed, Jun 20, 2018 at 4:46 PM, Eric Biggers wrote: > > On Wed, Jun 20, 2018 at 12:04:04PM -0700, Kees Cook wrote: > >> In the quest to remove all stack VLA usage from the kernel[1], this uses > >> the maximum blocksize and adds a sanity check. > >> > >> [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com > >> > >> Signed-off-by: Kees Cook > >> --- > >> crypto/xcbc.c | 5 ++++- > >> 1 file changed, 4 insertions(+), 1 deletion(-) > >> > >> diff --git a/crypto/xcbc.c b/crypto/xcbc.c > >> index 25c75af50d3f..016481b1f3ba 100644 > >> --- a/crypto/xcbc.c > >> +++ b/crypto/xcbc.c > >> @@ -65,7 +65,10 @@ static int crypto_xcbc_digest_setkey(struct crypto_shash *parent, > >> int bs = crypto_shash_blocksize(parent); > >> u8 *consts = PTR_ALIGN(&ctx->ctx[0], alignmask + 1); > >> int err = 0; > >> - u8 key1[bs]; > >> + u8 key1[CRYPTO_ALG_MAX_BLOCKSIZE]; > >> + > >> + if (WARN_ON(bs > sizeof(key1))) > >> + return -EINVAL; > > > > Similarly, why not MAX_CIPHER_BLOCKSIZE? > > > > Also, xcbc_create() only allows a 16-byte block size, and you made the API > > enforce the maximum for algorithms anyway. So I think the extra check here > > isn't very worthwhile. > > Is the "parent" argument in crypto_xcbc_digest_setkey() always going > to be the "alg" from xcbc_create()? I couldn't convince myself that > was true. If it is, then yes, this VLA can trivially made to be 16, > but it seemed like they were separate instances... Yes, it's guaranteed to be an instance of "xcbc" which was created by xcbc_create(), so it will have 'cra_blocksize == 16'. So until someone actually tests and enables support in the "xcbc" template for other block sizes (if the XCBC specification allows them), it would also be fine to just '#define XCBC_BLOCK_SIZE 16' at the top of the file and use that everywhere that references the block size. Eric