Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp4448669imm; Mon, 25 Jun 2018 16:14:32 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIizcDmUntSKwX2X209uZGFgp/TgCOoWQkQ/XoY083Pp1Eodv1zTOuS7DJsLT22F1y641l4 X-Received: by 2002:a65:6688:: with SMTP id b8-v6mr12516237pgw.24.1529968472559; Mon, 25 Jun 2018 16:14:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529968472; cv=none; d=google.com; s=arc-20160816; b=hhkChh15q8S7YHOyxCRkmbCtZm9CJkmlGhraWJ5bgmM5GE0oJ+71F1zAMS04mhe/Xy UmTW4SEjxIm7GIDfKphKF97OBlnF4qeZlLSku+gs+sj09ZrCD2RewZOKPk49y42soAE+ SAa7VOVY0/pBFeXu/UL1dOTqu6EWUaEH+C7747DdWITaOh7gHWCMFIOx7ruaFC5I0fNt gTm41iTBI17xUEeslfSskbKxxclYBSQqCX9KVMe15yxnweW/xOXzSEZCrvYx2KNTmwIt 8L1hVULH/wx3lGTJEFkHpjw0mt/o2Sn95Z3DwEE4Pw5vRGwDtYw8c0kHbo44KGD7+mNy wK+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature:dkim-signature :arc-authentication-results; bh=2I/TSRshrHUJp/sKcK1TeJxvZIG63wO38KwuqhdzdqM=; b=aYniTxGVzC37bj/tOgiJrj+S1BzRyt0rOYKRx537dEfIyfXX4uS8o43GJONXcnLqCd GLlptfFZJltDelxDKu8mJwOMUJVGdM/9gGneS75ZAZoJe2ycZ0+dhgu8yvdInNOU4lkS GkmG9ojPS2Im9mWyWtaCtFmxFuhx5LRi+ugwcJUFWtrZeRYLjejXcRKmEnCh+HhKzris usMgUZ3LxtP0A9TqApzv5ClFIW1GWOHPnKBr6kI7d3VXaBueKTj434QvhYePaKLVX9G2 gf1C1QFKdxUpD/pp0yXfJcREAV9oFAFJes69OiNqySDQ4eGkII8yC24v9I4AXao7H2+Z N75A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=AT4BzfOt; dkim=fail header.i=@chromium.org header.s=google header.b="T/ixsBMe"; 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=fail (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 a1-v6si87259pgb.424.2018.06.25.16.14.17; Mon, 25 Jun 2018 16:14:32 -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=fail header.i=@google.com header.s=20161025 header.b=AT4BzfOt; dkim=fail header.i=@chromium.org header.s=google header.b="T/ixsBMe"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932275AbeFYXNf (ORCPT + 99 others); Mon, 25 Jun 2018 19:13:35 -0400 Received: from mail-yb0-f196.google.com ([209.85.213.196]:39042 "EHLO mail-yb0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752939AbeFYXNc (ORCPT ); Mon, 25 Jun 2018 19:13:32 -0400 Received: by mail-yb0-f196.google.com with SMTP id k127-v6so753512ybk.6 for ; Mon, 25 Jun 2018 16:13:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=2I/TSRshrHUJp/sKcK1TeJxvZIG63wO38KwuqhdzdqM=; b=AT4BzfOtTSj1SooXe/+N3QdTtOgmXphOhHdAMKZPjBuBRCE0j6pxdmnMJk59FC2B8+ 650E7jvJQW+lUyhMUR2sUKhR5ASmtAUtaG+QadgFk3ASstEMleISwyH3O383Q/hvUdlw elNH9df42llvkOnRl7k2MCRSmJqrHt4c+nicR8Gxg37CkYdoDfYs3eSnIyPZ1sZMq4t/ WpsqMtFIwe6jun1UML5zlpTum65hoHmoBTLVdUHjME4xmd+/NI+PNxy5jedgY6DoFkQd N20VVM9+fzx2x2Ad8N6svDRGoQedmjY572OD3bhv7pZpoe7PZAowb1La4hnSP02MAtDG j3eg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=2I/TSRshrHUJp/sKcK1TeJxvZIG63wO38KwuqhdzdqM=; b=T/ixsBMe1AuNcWd3JaJXxAXw96JmXyTmh4muUsLRqdnwJ4bwsjh1Hgm96tkToPiGg/ YSZBUa2GwITmjvQcUINvvfpQfvUzEeGdsCdbw5ECJAgY/xa5CExL3CWMd0MErCa69Zzr MFMtw4ibSgdsAV9KMiuZsGohuAZVb1GhHN234= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=2I/TSRshrHUJp/sKcK1TeJxvZIG63wO38KwuqhdzdqM=; b=ADwuuXSK/SJmsvwW6MrVN1q+ddLb5hDF4lKMiFvC9u1g0fD7of28i3UvKR3dKerP3F 66zQiXG9bACTA97hIMhyLQ4tmS93zBWZpH9081FUA38Fcl1BfDmd95NGD+fHcCm4388E XH+CRK7hRga5tZ00y5yxiNR6flMkBjuAZP0bMLKc6CUlkacbo0b0Kmu0NEYOMFTG0Do8 eW4Hyb+HweLWLPmfcC7sTNY/tsVKOt/t6JDlQpMg6uv1NX/Tya5TvFinQagef+CLvGW+ 0iLnrTJzJppf/5NniWDPgoZY2YliH9Ct5QRS5+zhd3ZxTLXvNL6WQzbCSHDVTNlMQ7B3 hrFg== X-Gm-Message-State: APt69E2HSowJ8zAo8wYJ24/NJufATm7G0dcB0kemuSdpzjaRtJQ72zmW rNryz9oNRDh0T+2cz1iojj+ImUrTst1LBLfhS0rvjw== X-Received: by 2002:a5b:b4e:: with SMTP id b14-v6mr7596340ybr.463.1529968411904; Mon, 25 Jun 2018 16:13:31 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a25:5f51:0:0:0:0:0 with HTTP; Mon, 25 Jun 2018 16:13:31 -0700 (PDT) In-Reply-To: <20180625225609.GA181665@gmail.com> References: <20180625211026.15819-1-keescook@chromium.org> <20180625211026.15819-11-keescook@chromium.org> <20180625225609.GA181665@gmail.com> From: Kees Cook Date: Mon, 25 Jun 2018 16:13:31 -0700 X-Google-Sender-Auth: lZz4HLcLOw5dCHXQdCTjtbWayFQ Message-ID: Subject: Re: [dm-devel] [PATCH v2 10/11] crypto: ahash: Remove VLA usage for AHASH_REQUEST_ON_STACK To: Eric Biggers 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 25, 2018 at 3:56 PM, Eric Biggers wrote: > On Mon, Jun 25, 2018 at 02:10:25PM -0700, Kees Cook wrote: >> 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. >> > > This isn't accounting for the cases where a hash algorithm is "wrapped" with > another one, which increases the request size. For example, "sha512_mb" ends up > with a request size of > > sizeof(struct ahash_request) + > sizeof(struct mcryptd_hash_request_ctx) + > sizeof(struct ahash_request) + > sizeof(struct sha512_hash_ctx) > > == 808 bytes, on x86_64 with CONFIG_DEBUG_SG enabled. > > (Note also that structure sizes can vary depending on the architecture > and the kernel config.) > > So, with the self-tests enabled your new BUG_ON() is hit on boot: Ugh, right. Wow, that _really_ gets big. Which are likely to wrap which others? Looks like software case plus hardware case? i.e. mcryptd_hash_request_ctx with artpec6_hash_request_context is the largest we could get? So: 80 + 80 + 200 + 664 ? Oh, hilarious. That comes exactly to 1024. :P So ... 1024? -Kees -- Kees Cook Pixel Security