Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp420983imm; Thu, 28 Jun 2018 23:34:05 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLsRwwcri8whjkemAdm2PQHtL9FMCbNd4SOknXJnHQhxhXfsBPYmS00ZI4tSCiGpjZVpE/5 X-Received: by 2002:a17:902:1007:: with SMTP id b7-v6mr13372963pla.277.1530254045416; Thu, 28 Jun 2018 23:34:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530254045; cv=none; d=google.com; s=arc-20160816; b=tugJgBaR9gFkm6AFz6tM7O0zYhVj4T7U3N8U9lhmpnQQoS5nwW0DSxpTdKwFF35pwd QMKIuGurfZg5mbZRau2jDdcD3GMXUdIEeXwePNy+gRQ5rFzDRh0owMIdQLcP8z/+pB/I gmFQqF1U8F7MpG9BqFAOLmDHBHMkkrxusmUw8s3nMEBmVSS3vbqdWt6waxGQfMX3GdkU qD5X+/URFIvK8548CCMXqvunt+bAUfDd3RrQsrGk/L7Rj/16M6QaQWUZijdvvYGr0ho8 /pJgh3ogFJ0R2+zCgsUfrRkysH9hQjXnoFWxbXR2156lpsgXSKNPsu5BimwRdTwaJWwr 70tQ== 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=OPrbhpf+OtJBDX2eteghpLvngwKyDU3zwKMrVHOinl0=; b=swR8t1Gn17tvE1Pn8aj3ynpEsRo5Mtiz/ug1UkZg9Qlsfwrju56c0eqL5xg4oen/JJ MSLzDHdr3p2P6MO3MbWfOunG145Wq6oQpno4SR198Q7Q+nY6ydfL2MJzs2AkKZzS+Mu6 7fO0n/z37FEF2CLdFfifrHxkRs+pGwMLcQtW+viOtIUTJcSn+KuB/5hVJb2i+bYO5CSm tDVIlB0YbwxQ/0veUTDYPxB1uyN+h0tEDyFexD6hQOacxCr0ouTdZExis1ysAmK6Imb9 DO5pQ6+n9Kh0HSW5gtupbT+PAtS3fGak7wQExQXe2dfiIBJPZLK2JsbVjNm2SpHGtAXM S1+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iE927FQL; 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 c3-v6si8447091pld.87.2018.06.28.23.33.51; Thu, 28 Jun 2018 23:34:05 -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=iE927FQL; 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 S1030353AbeF2A3w (ORCPT + 99 others); Thu, 28 Jun 2018 20:29:52 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:34676 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934370AbeF2A24 (ORCPT ); Thu, 28 Jun 2018 20:28:56 -0400 Received: by mail-pl0-f66.google.com with SMTP id z9-v6so3564333plo.1 for ; Thu, 28 Jun 2018 17:28:56 -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=OPrbhpf+OtJBDX2eteghpLvngwKyDU3zwKMrVHOinl0=; b=iE927FQLC/dtuYydLTtjp16Fy5TCCWYrfPl2Mb/N3NlnlctG0thJWdzO9v/u7mpBDg Fv1tYqWu/YbdNkwIZabAgIIDNoIsFDL7IxVBL2EJBg4qQhbtclFKBc0Ib2HrwhHbT30R 5u0y0+ESiMR3J60jXiHYCO2crm/bkSoudMwuQ= 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=OPrbhpf+OtJBDX2eteghpLvngwKyDU3zwKMrVHOinl0=; b=X8O13tnLYKbtBMMFf4NgzjURO162BZSwmZI04PfaMyblaSPCzQDKdVfSphg2mudrgS TEaRBfTblTfKNWNl2dDBUal1GZwZLAo+UwNAvjNKvuL1cwuImSIlMvm/X+CrK7jw+XxW LvAnauETU0ep+iw/HCMHpP8Ou7De4tyBTrh6EiV5Jufuk5opiiAUWPtrTNk6z2QvSsc9 Kx2qOKARq/RGkdSfQhxaU/WhzlBpF/tnEctgzpx85Okw6s+T1r7vt4EUdqcqMIut4yeD XmzmVKn5GmLkDVusMiphkYPphDA7uLcwtxKQ05z4s9ZWd8IUfPkX/Czm8IOFyRwVWVMY BmWQ== X-Gm-Message-State: APt69E1dYH1BhTxzoz7oQEqfQTtDJOqsBJcJr1uSIyKV1cTIpNegN5Mo OVXsfJw9Y+hMusiG5/A6abWWpg== X-Received: by 2002:a17:902:bcc3:: with SMTP id o3-v6mr12442696pls.336.1530232135778; Thu, 28 Jun 2018 17:28:55 -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 v13-v6sm17327904pfa.131.2018.06.28.17.28.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Jun 2018 17:28:53 -0700 (PDT) From: Kees Cook To: Herbert Xu Cc: Kees Cook , "Gustavo A. R. Silva" , Arnd Bergmann , Eric Biggers , Alasdair Kergon , Giovanni Cabiddu , Lars Persson , Mike Snitzer , Rabin Vincent , Tim Chen , "David S. Miller" , linux-crypto@vger.kernel.org, qat-linux@intel.com, dm-devel@redhat.com, linux-kernel@vger.kernel.org Subject: [PATCH v3 5/9] crypto: ahash: Remove VLA usage Date: Thu, 28 Jun 2018 17:28:39 -0700 Message-Id: <20180629002843.31095-6-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180629002843.31095-1-keescook@chromium.org> References: <20180629002843.31095-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 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