Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp484211imm; Wed, 26 Sep 2018 01:54:59 -0700 (PDT) X-Google-Smtp-Source: ACcGV61vb+/bM1lBp9iB6hJfv8fnP3UvKH23WMZmFpq/kAregAJ8d98xZE/RRCNDcto2wDgN3fg/ X-Received: by 2002:a63:d00b:: with SMTP id z11-v6mr4775648pgf.317.1537952099334; Wed, 26 Sep 2018 01:54:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537952099; cv=none; d=google.com; s=arc-20160816; b=HP2HIMH18A/B78rxSBQcjBBVGknt7aHYXK7s+DhZJ+SV8I3XBaW7SU4DCUjzWwbOmA spu7Qg65vgJD5nkt1fOkY6EmMhptgxau/tAWiITHtDz197AQNY3cb2JLakPNN3b/gh5V xmEdSEt/aT6w+9GIHuA1ucUv0WBlBCevMdEhJWhHaIEJVlOBQXNwpJjpXMug234UKmeB GgihqBXzQmvAtyaqZH0KIu9T28ZvZ1hPuREdUWJfCwe/Sz5WwKdKeseQo/i9qoXXO3Lj mWYQUj+A6PU8nfTv6xc4ljav5kTMvq/OXIMAjh7N/RzPC3Gfyv4/NOINwmJSCNBxjozW u4Bw== 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 :in-reply-to:references:mime-version; bh=A6s0+ZNL7nKauaszPZVs6oJ75UHD81RARze2+MoySwc=; b=F0Ufunofp1MLy1uzoymHoW3pUe9KEDfrxbMOVl0Rpl+SOKOGzMdy8QjwB0IZ7yZL63 fRGRdAIEjhOVPqi6DeKEwvg6+j4LbhqzXS0mSsSZZDVkzmGVq1nwELn6MXfigFdhaf2Z t5GpgF3tVsfBbBWUlR/s/G+Bwcm6oqiFtrqXHcGWW/oKJUxLBewPEYW/8A/Kpcn8cyel ud/YWemTxxoNB9kYmTN/xoHwzomO90km1kUxLehGmgUkyIAUssw9IKsj5a1eFJailx2w 1XdFrhqeBjmNL7k3pJcsHQDLck8Hjz+UiOYqEcVxU3J1f/ZA9DMipjnXLujT/IEh9nXc BYSw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m1-v6si4550178plb.348.2018.09.26.01.54.44; Wed, 26 Sep 2018 01:54:59 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727706AbeIZPFz (ORCPT + 99 others); Wed, 26 Sep 2018 11:05:55 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:43831 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726404AbeIZPFz (ORCPT ); Wed, 26 Sep 2018 11:05:55 -0400 Received: by mail-lf1-f66.google.com with SMTP id x24-v6so22485700lfe.10; Wed, 26 Sep 2018 01:54:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=A6s0+ZNL7nKauaszPZVs6oJ75UHD81RARze2+MoySwc=; b=K/bXWjZZZKoOSFUpn4w9geIJ6r62B5OXwlbhOBPckjsl4atZL4iIbsAwHEk5Eyzkaw SiOi6RXqjCXItATpAi3hvBS9ooVAZhwbWJ5pTC4be36xPoTgIySfPoSyxHPLM8V8hjUt WpBKZEgNECVG2HxDKDLQIqmroDlVCA4j+EvcYGsM7nkU6O9L4EegdogZweylg9FNYFCk sAfIyXHOSqcUhH2333N0w26dMn+aguusuUj7mb5+Lj+ctbaSBmDBwF5qC4pa8X9qKkB8 ndYzxG05rln1qOlmqPK2PrHQ3cWoN9bTsE8mBsoS5MPA4pvM7HLZzseFLMPqNU+D9fq0 nmcA== X-Gm-Message-State: ABuFfoh6PrzmsZ6OvzCqjk0YKS26w2Rr5WETsgeoUqUlQKbNT1dJHZ/k d/UBjeYs7IadAjrS2q5VUsZhsXykOCIzs78IzTI= X-Received: by 2002:a19:1346:: with SMTP id j67-v6mr3459424lfi.93.1537952039712; Wed, 26 Sep 2018 01:53:59 -0700 (PDT) MIME-Version: 1.0 References: <20180807211843.47586-1-keescook@chromium.org> <20180807211843.47586-8-keescook@chromium.org> In-Reply-To: From: Arnd Bergmann Date: Wed, 26 Sep 2018 10:53:42 +0200 Message-ID: Subject: Re: [PATCH v8 7/9] crypto: qat: Remove VLA usage To: Ard Biesheuvel Cc: Kees Cook , Herbert Xu , Eric Biggers , Giovanni Cabiddu , Alasdair Kergon , Mike Snitzer , Tudor Ambarus , Andrew Morton , Thomas Gleixner , Geert Uytterhoeven , Will Deacon , Rasmus Villemoes , David Woodhouse , Matthew Wilcox , David Miller , "Gustavo A. R. Silva" , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , dm-devel@redhat.com, qat-linux@intel.com, Linux Kernel Mailing List 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 Wed, Sep 26, 2018 at 10:44 AM Ard Biesheuvel wrote: > > On Tue, 25 Sep 2018 at 18:12, Arnd Bergmann wrote: > > > > On Tue, Aug 7, 2018 at 11:18 PM Kees Cook wrote: > > > > > > In the quest to remove all stack VLA usage from the kernel[1], this uses > > > the new upper bound for the stack buffer. Also adds a sanity check. > > > > > > [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com > > > > > > Signed-off-by: Kees Cook > > > > After rebasing to linux-next, I now get a warning about this file: > > > > drivers/crypto/qat/qat_common/qat_algs.c: In function 'qat_alg_do_precomputes': > > drivers/crypto/qat/qat_common/qat_algs.c:257:1: error: the frame size > > of 1112 bytes is larger than 1024 bytes [-Werror=frame-larger-than=] > > > > I assume it was already possible to get into that state with the VLA, > > but it seems bad enough that I think we need to do something > > about it. > > > > The large stack variables add up to 1084 bytes, which fully explains > > how we got here: > > > > SHASH_DESC_ON_STACK(shash, ctx->hash_tfm); /* 360 */ > > struct sha1_state sha1; /* 92 */ > > struct sha256_state sha256; /* 104 */ > > struct sha512_state sha512; /* 208 */ > > char ipad[MAX_ALGAPI_BLOCKSIZE]; /* 160 */ > > char opad[MAX_ALGAPI_BLOCKSIZE]; /* 160 */ > > > > The question is what we can do about it. One simple step I've tried > > is to move the sha1/sha256/sha512 into a union, which saves around > > 200 bytes and should bring us (slightly) below the warning > > limit, but I suspect we can do better than that. Any ideas? > > > > All the processing takes place in the context of a setkey() operation, > which means only one such operation should be in flight per tfm at any > given time. So we could move all these pieces into the tfm context > struct instead. Something like the below [untested] (whitespace > mangling courtesy of Gmail) Ah, right, this is what I was hoping for. I assume we already guarantee that this context is never put on the stack somewhere else, right? Arnd