Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3078622imm; Mon, 16 Jul 2018 21:24:33 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdOXeCFv5Q66SHBpEyv52GzlZoWjKYxiVjw6AUkppKqIGMXK5ZFckjh8tuyhfwIMVgsBBW1 X-Received: by 2002:a62:384:: with SMTP id 126-v6mr21059pfd.11.1531801473145; Mon, 16 Jul 2018 21:24:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531801473; cv=none; d=google.com; s=arc-20160816; b=HbMJmaYio+jov/HkJJ4Uty2bYxvg9DlxJfcLZiSRGjxwSC9vfoTu8XgJoY6PLwMsKi H03gRmVBJOsLoyqLYRwr9wCy3E1PvTWk3/MN1AQXr/xcX7pv+7S9F9aPAe+9C+j+bkoW zXEMWiNwxrtD3dsKe0PHRiUzzY5hs4hy6O2VBh5yO9RlriudlhvGHe+djorKktv8HQpJ 18JpdPQh1bvSEL94YZOIWokWaAAUE3IvTNJUr1S5Cdi70U/krDtoxVT/yNtlkszlH9ru 7ltW+r73fgZZGAor78dQ+++M7V5iQ7ppFB4R7Hk4Y06wvZ9YjxWrNUjbLXIrckm3FkJQ IulA== 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=E3HM8Tth/zRydJwOd6Lp6hlKsvHw6H8gx4o1bYaHJJ4=; b=MSsuYrtD4xh/988agnM0U2AM/ZT6/X6O6RUp+QwuHYHgo55qK4GSXZYgJzdxzUVIt3 7UUOOAGVFV8Upm+lQgV0McFU00VRhNNHsdyG65XHgSKDQG1Tjc1wRxGS9d8DKwUTcD6q sOFcMTn8Eus4NQZUHGqsI0PlxomOEGSnbK5k6y2sa04+HEOiuAHa6zKt/Z57zeG833/U U4FvRP1roGB1KaCBxoyhXgE3CAjf7UvbMKxfzpBBhZxOby/w+0OuksgkkmV7FjHm8+Fl nLcAgxKE2MHHKf2HR09ar6OCLJLqbO0xUycPM0LgW6q9k2emvJgTvaXlwaDmwEJc47iP iaBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=cPP0fTf5; 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 f9-v6si30811642plo.206.2018.07.16.21.24.18; Mon, 16 Jul 2018 21:24: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=@chromium.org header.s=google header.b=cPP0fTf5; 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 S1729651AbeGQExP (ORCPT + 99 others); Tue, 17 Jul 2018 00:53:15 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:37637 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729620AbeGQEwe (ORCPT ); Tue, 17 Jul 2018 00:52:34 -0400 Received: by mail-pg1-f193.google.com with SMTP id n7-v6so1514155pgq.4 for ; Mon, 16 Jul 2018 21:21:59 -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=E3HM8Tth/zRydJwOd6Lp6hlKsvHw6H8gx4o1bYaHJJ4=; b=cPP0fTf5plHseI4evj6xcwyRBM2F80MNLTiSR+WLYaVgfJ3JribBIXvb7IHjJsgS/K 5fZ/uAruUE27oZANxH1g7FPguL8iumDeFd7I97Apa2a0545xNy462UaeX0bwqvbHNckU vXqS55kxYI0kJVx6F8Puo2xVubns4T1+kOZW0= 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=E3HM8Tth/zRydJwOd6Lp6hlKsvHw6H8gx4o1bYaHJJ4=; b=ifrF9agkvvCqLKsT+rROjyv5lGl3Ke0JsWeS3tSkpKx14bD4ph+ClapNjawNtW7LGp /i4zafGyhfdZ6uZKHTX0ZhL2w/CtL6MXUU0Oi6HfdNC2xjPPmq7jxxKJGBEEBJCdosEj 0z2d9UIeKSqQBEicb5X4kFV+FStcau43QGqYJf1yEoQsMtfbiWyKxuzJhILvpV1dM/Nv 5DToXRXZ5EB7au/0fnerS5zwz4MLx8kTxZGkrNwVuQPB6pbgR01p/h1Ae7GC33lsp0R+ xl10k/V7PvMIuSqTsjaATZgxRshVPb9qH4S3XH6VitC78Sxls5PBUsoChoNAs9VywyUy Q2mw== X-Gm-Message-State: AOUpUlGL5CNdzMYBJ2pAlA3hqtJqeu/h77I3DjS+6xz8c6WbYJ0793hE 2b5aFTzV6D6EcAgA0W3LUb4gzw== X-Received: by 2002:a63:8749:: with SMTP id i70-v6mr18252098pge.325.1531801319343; Mon, 16 Jul 2018 21:21:59 -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 r87-v6sm86452111pfb.1.2018.07.16.21.21.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Jul 2018 21:21:58 -0700 (PDT) From: Kees Cook To: Herbert Xu Cc: Kees Cook , Arnd Bergmann , Eric Biggers , "Gustavo A. R. Silva" , Alasdair Kergon , Giovanni Cabiddu , Lars Persson , Mike Snitzer , Rabin Vincent , Tim Chen , linux-crypto@vger.kernel.org, qat-linux@intel.com, dm-devel@redhat.com, linux-kernel@vger.kernel.org Subject: [PATCH v5 05/11] crypto: ahash: Remove VLA usage Date: Mon, 16 Jul 2018 21:21:44 -0700 Message-Id: <20180717042150.37761-6-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180717042150.37761-1-keescook@chromium.org> References: <20180717042150.37761-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 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 ae14cc0e0cdb..4fcd0e2368cd 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