Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp4347364imm; Mon, 25 Jun 2018 14:11:51 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLCjwoYQeHWgwy20ORAweextXxcCTwWqhdMuhWDnmAjXto5DpW8wqGEi30zog+RIK+Cmb1P X-Received: by 2002:a65:444d:: with SMTP id e13-v6mr3637159pgq.122.1529961111268; Mon, 25 Jun 2018 14:11:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529961111; cv=none; d=google.com; s=arc-20160816; b=ayKV3eRNRcT8TAoCOB6rTGBo2fIdZvvar/KSVgG799hQHiaS0OHq8coF8iifpho4ND SysJglTmXxEC4jv5hM8DrcXXu/duNaWmwMJZ0xNt5SXTNwY494b2exXZFFPzq6BnoPlD 0tWxMXCCZ8oD3tulrAn3L8yQo8R4E07h1eVWXwEjAJ2d0UkNy9Yw6aXzJK3vcTQ1PPrm of/uo+jjpqa/7Bns7C9fMYNLpONtH4+L1nqXs9JO8lJnN4IPEjZLtb3Zg34li1134zn7 WxTvmTMrscWSF0eOhBkCpD3Ptq6L8ysEAKBDZHaGbdxdcCII6u8bzb1MTjpK1j3+BnlX 5tKw== 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=7GPrKfdR5KhvOf/uCEjgoaiwKLxPMMvp9jyWVjCQ3Ug=; b=FULK0mMgqtSCSUbXADD/I46Fw5WGaR6oK1dB9BlI0WCTaeqbO/eURlyXCwxnDiOK6+ M0Qdac+rg4pSocTKJjM7dFKNObX07sMXc6EZByat+qmjW+55t+PRxZHEE83bKhDJFBz7 PywWzj6B3Nh92Z6JbWZJQrJw4SoYAKMTZfzF7cKPqYgEBc0KbfWA/MTq0H37P5EyN39I PQvWj+4n82dFcvQpDNWWh5oXROYmed96fVTGgKVjNvF2OPuH0y3XRBJgHQcFSz1OFK2o uNnQLwMVg96eO5DjtqlZ6n9DUP0GoceXhJ49tiv7OASzHR3nE9E5/4FMQx/cStdAUJKN EhnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="c/opmkDl"; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l17-v6si15394656pfi.179.2018.06.25.14.11.36; Mon, 25 Jun 2018 14:11:51 -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=@chromium.org header.s=google header.b="c/opmkDl"; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755612AbeFYVKw (ORCPT + 99 others); Mon, 25 Jun 2018 17:10:52 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:42787 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754719AbeFYVKp (ORCPT ); Mon, 25 Jun 2018 17:10:45 -0400 Received: by mail-pf0-f196.google.com with SMTP id w7-v6so7025453pfn.9 for ; Mon, 25 Jun 2018 14:10:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7GPrKfdR5KhvOf/uCEjgoaiwKLxPMMvp9jyWVjCQ3Ug=; b=c/opmkDlBkCwdHeoINUUIDnf0H5OhzoSsdrZCZ+UVNj9d+82i7JL0D4a1Yt1iQteqF 6q/YBN3JP3l/UXw89+xRqoXnP+UhBR09AUv/6J0JyWa/FAiAR4c9iBFz2ut9nUEYnhVb 8l+BdUNZYMOf2pToa1gWnyWjAR0ogQCvEup8E= 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=7GPrKfdR5KhvOf/uCEjgoaiwKLxPMMvp9jyWVjCQ3Ug=; b=OkEehMms116J5p/fBVfGsX5UYEV6FqcBmt8e+q8V4tePsRmOVPAoqnJKF/qPJ7lnm2 jttw+oWKRgaZEQ9M0aIus34BjAU/d3ibNem83YrClTYQB5qTlGfjrfnRxHAPtV+K4kjW Fg6Jh4hjI+CowhO6ziuIbQgkpKTyNpJ02qKLRISK8XMSrn+BswCNlC1gH6hhL8+YYvTx YAXHnwbod0o8SAOz68lPaCjt4gxCb9gPqHEMEocR9Kw99gnFU8XtwVKtF4UfQhkElZrl knc2epr8t4QcreS747pu0ei4R0wLQ2AE9GhYBGD0E+xUrrSacPl1HEBO1FXvw+VqGj1c ZdvA== X-Gm-Message-State: APt69E3DJ/eD33sIaoq3oX+OiRSS1HKbQnSZVUTgQOF0dxsGiP16UryL f9sycGa9lIB5L9583vQr9aOcGQ== X-Received: by 2002:a62:23d5:: with SMTP id q82-v6mr7229486pfj.1.1529961044699; Mon, 25 Jun 2018 14:10:44 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id x8-v6sm32474744pfa.87.2018.06.25.14.10.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Jun 2018 14:10:41 -0700 (PDT) From: Kees Cook To: Herbert Xu Cc: Kees Cook , "David S. Miller" , linux-crypto@vger.kernel.org, "Gustavo A. R. Silva" , Arnd Bergmann , Eric Biggers , Alasdair Kergon , Giovanni Cabiddu , Lars Persson , Mike Snitzer , Rabin Vincent , Tim Chen , qat-linux@intel.com, dm-devel@redhat.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 05/11] crypto: ahash: Remove VLA usage Date: Mon, 25 Jun 2018 14:10:20 -0700 Message-Id: <20180625211026.15819-6-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180625211026.15819-1-keescook@chromium.org> References: <20180625211026.15819-1-keescook@chromium.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the quest to remove all stack VLA usage from the kernel[1], this introduces max size macros for ahash, as already done for shash, and adjust the crypto user to max state size. [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Cc: Herbert Xu Cc: "David S. Miller" Cc: linux-crypto@vger.kernel.org Signed-off-by: Kees Cook --- crypto/ahash.c | 4 ++-- crypto/algif_hash.c | 2 +- include/crypto/hash.h | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crypto/ahash.c b/crypto/ahash.c index a64c143165b1..6435bdbe42fd 100644 --- a/crypto/ahash.c +++ b/crypto/ahash.c @@ -550,8 +550,8 @@ static int ahash_prepare_alg(struct ahash_alg *alg) { struct crypto_alg *base = &alg->halg.base; - if (alg->halg.digestsize > PAGE_SIZE / 8 || - alg->halg.statesize > PAGE_SIZE / 8 || + if (alg->halg.digestsize > AHASH_MAX_DIGESTSIZE || + alg->halg.statesize > AHASH_MAX_STATESIZE || alg->halg.statesize == 0) return -EINVAL; diff --git a/crypto/algif_hash.c b/crypto/algif_hash.c index bfcf595fd8f9..8974ee8ebead 100644 --- a/crypto/algif_hash.c +++ b/crypto/algif_hash.c @@ -239,7 +239,7 @@ static int hash_accept(struct socket *sock, struct socket *newsock, int flags, struct alg_sock *ask = alg_sk(sk); struct hash_ctx *ctx = ask->private; struct ahash_request *req = &ctx->req; - char state[crypto_ahash_statesize(crypto_ahash_reqtfm(req)) ? : 1]; + char state[AHASH_MAX_STATESIZE]; struct sock *sk2; struct alg_sock *ask2; struct hash_ctx *ctx2; diff --git a/include/crypto/hash.h b/include/crypto/hash.h index 804e87a9510e..5d79e2f0936e 100644 --- a/include/crypto/hash.h +++ b/include/crypto/hash.h @@ -64,6 +64,9 @@ struct ahash_request { void *__ctx[] CRYPTO_MINALIGN_ATTR; }; +#define AHASH_MAX_DIGESTSIZE 512 +#define AHASH_MAX_STATESIZE 512 + #define AHASH_REQUEST_ON_STACK(name, ahash) \ char __##name##_desc[sizeof(struct ahash_request) + \ crypto_ahash_reqsize(ahash)] CRYPTO_MINALIGN_ATTR; \ -- 2.17.1