Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp4348524imm; Mon, 25 Jun 2018 14:13:03 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJmfHER0oDEK3Bpp7xqCLoRqTu18tNZWwQFPKrfNqinKA32vhi0WAX9AUfoQRUPFaElREYU X-Received: by 2002:a62:ec48:: with SMTP id k69-v6mr6045749pfh.85.1529961183028; Mon, 25 Jun 2018 14:13:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529961182; cv=none; d=google.com; s=arc-20160816; b=TBhICZO+1MFKxZ8fRtIcO9sX3isnsLMgY8ndhHH2U2UY9ZDl13qyYhI5FWvt1LL4BS gYXQk9enao5rV8rBTXuEyCd2QV6QhAFDRQhlnwPN0dIs4n/nsEguR5YN89xyJwVASv59 yiTf5a4yVUBOtRPEK2CmlSOzUuMGVH9mQ/HT6gv9QMTcYIVZKG2ZVj64/7RUgHpBJyvm 4aOUt/XW0V3vG+ti0PmiP0JOp4W5MRLTMZlIeSAvkTywnwIk/SSr3rP5aKQZUPYTci54 JdWq23kp50BFPHM0g8ZZRBxXUkF9X6gbZwSq5RZ8Non4BZ+mI2MYc0roWRfg2Pv8Pv9p 2DPQ== 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=vXuGUo3CgtLCxU0uXrhmKWqGXnPR9Lzs5ZkCBgfB/Rg=; b=wqNaIKgoKVBmxEMX5IWj39ZGJCoAnjZ+eE6GvpEtOg78d9AgmEVl2WKzMTBI9sd9bi HAu8L7nU60NtpEtcytRIu0olouNcSOfxQKMhBarvFyJ2Mpy2zU/Fg0zo3Ey2CUEU82KO GYR5+m26o+3aBFUc5BaMBaqG31YoE6haB8o44+FGZp4QoRztYpB98aZFPai1OGsEfxCO diaaR4pdv1tI7ik6wYXN9MEa8l6+a3NqcZ7whEa6T17CQ8NuqTLrqzFTGrNhnPgw2urV BjAWFBo6R8s8/NgDDiuWrj4BHMEe9Wgfe2RBwKCJCGaPzMY6B8+izPydSIctfIAKzJbm CgZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jhk+Gm3r; 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 k185-v6si12418104pgc.468.2018.06.25.14.12.48; Mon, 25 Jun 2018 14:13:02 -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=jhk+Gm3r; 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 S1755730AbeFYVLo (ORCPT + 99 others); Mon, 25 Jun 2018 17:11:44 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:45314 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755041AbeFYVKr (ORCPT ); Mon, 25 Jun 2018 17:10:47 -0400 Received: by mail-pl0-f65.google.com with SMTP id o18-v6so6713279pll.12 for ; Mon, 25 Jun 2018 14:10:47 -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=vXuGUo3CgtLCxU0uXrhmKWqGXnPR9Lzs5ZkCBgfB/Rg=; b=jhk+Gm3re/9Vs1IdGB9Ugw9VIGaTToLT8mKZotdUQNbDPHHx5WNQhy6rHy+eZuD3Uh KHwWLGi8k2VIG6+SaOpMFUTgYjG6el3E4udLtGGf7SrSXndZ7WCM6b1t9Xy4V+1K2ZLu pzR/2A9Wdntw70qDbOf35yrzXzD1oyhTgrtLc= 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=vXuGUo3CgtLCxU0uXrhmKWqGXnPR9Lzs5ZkCBgfB/Rg=; b=mJN8pD3MczuB3+lbiouxPWZDe3JZszrPKzJwwz78NBKUhuLbnwh2Vwqqx9oeue9l78 l8YHtyHRkJd0ledg4h1EOpCxUvB3AFSj9uqC0ljLeJLbZLZS3Bs8tKrka8PuVqpO18pC uRlG7j75ies/0eGUGVyHcWVFaRr3Cr7ZP9ezrjR6u86MCqSjQ0YFXkcIfwmlkQgU+CnI Evhm8OW+5czGuvOOxT9yUvbLly6MczVSoDKexBdYSKslml0lW/RYa0EbEtArDHL8smug cZ3hmNt52csSkPE0sQF4UY4WMX+JlsJRvhKs2HHVooZ0qJv2PFYYUy1MgHdemLCm3tfn +bbQ== X-Gm-Message-State: APt69E1Rw6adWGEqaY3tyDxfIkGRDXi1VhG+f0XWKOKsYhJCvr6TZThT PoIXoKx/xMT5bwh+/o1TFTXUoQ== X-Received: by 2002:a17:902:7686:: with SMTP id m6-v6mr14124701pll.340.1529961046800; Mon, 25 Jun 2018 14:10:46 -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 m21-v6sm19240237pgv.27.2018.06.25.14.10.39 (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" , Eric Biggers , Tim Chen , Rabin Vincent , Lars Persson , linux-crypto@vger.kernel.org, "Gustavo A. R. Silva" , Arnd Bergmann , Alasdair Kergon , Giovanni Cabiddu , Mike Snitzer , qat-linux@intel.com, dm-devel@redhat.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 10/11] crypto: ahash: Remove VLA usage for AHASH_REQUEST_ON_STACK Date: Mon, 25 Jun 2018 14:10:25 -0700 Message-Id: <20180625211026.15819-11-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 caps the ahash request size similar to the other limits and adds a sanity check at registration. Unfortunately, these reqsizes can be huge. Looking at all callers of crypto_ahash_set_reqsize(), the largest appears to be 664 bytes, based on a combination of manual inspection and pahole output: 4 dcp_sha_req_ctx 40 crypto4xx_ctx 52 hash_req_ctx 80 ahash_request 88 rk_ahash_rctx 104 sun4i_req_ctx 200 mcryptd_hash_request_ctx 216 safexcel_ahash_req 228 sha1_hash_ctx 228 sha256_hash_ctx 248 img_hash_request_ctx 252 mtk_sha_reqctx 276 sahara_sha_reqctx 304 mv_cesa_ahash_req 316 iproc_reqctx_s 320 caam_hash_state 320 qce_sha_reqctx 356 sha512_hash_ctx 384 ahash_req_ctx 400 chcr_ahash_req_ctx 416 stm32_hash_request_ctx 432 talitos_ahash_req_ctx 462 atmel_sha_reqctx 496 ccp_aes_cmac_req_ctx 616 ccp_sha_req_ctx 664 artpec6_hash_request_context So, this chooses 720 as a larger "round" number for the max. [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Cc: Herbert Xu Cc: "David S. Miller" Cc: Eric Biggers Cc: Tim Chen Cc: Rabin Vincent Cc: Lars Persson Cc: linux-crypto@vger.kernel.org Signed-off-by: Kees Cook --- include/crypto/hash.h | 3 ++- include/crypto/internal/hash.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/crypto/hash.h b/include/crypto/hash.h index 5d79e2f0936e..b550077c4767 100644 --- a/include/crypto/hash.h +++ b/include/crypto/hash.h @@ -66,10 +66,11 @@ struct ahash_request { #define AHASH_MAX_DIGESTSIZE 512 #define AHASH_MAX_STATESIZE 512 +#define AHASH_MAX_REQSIZE 720 #define AHASH_REQUEST_ON_STACK(name, ahash) \ char __##name##_desc[sizeof(struct ahash_request) + \ - crypto_ahash_reqsize(ahash)] CRYPTO_MINALIGN_ATTR; \ + AHASH_MAX_REQSIZE] CRYPTO_MINALIGN_ATTR; \ struct ahash_request *name = (void *)__##name##_desc /** diff --git a/include/crypto/internal/hash.h b/include/crypto/internal/hash.h index a0b0ad9d585e..d96ae5f52125 100644 --- a/include/crypto/internal/hash.h +++ b/include/crypto/internal/hash.h @@ -142,6 +142,7 @@ static inline struct ahash_alg *__crypto_ahash_alg(struct crypto_alg *alg) static inline void crypto_ahash_set_reqsize(struct crypto_ahash *tfm, unsigned int reqsize) { + BUG_ON(reqsize > AHASH_MAX_REQSIZE); tfm->reqsize = reqsize; } -- 2.17.1