From mboxrd@z Thu Jan 1 00:00:00 1970 From: Arnd Bergmann Subject: Re: [PATCH v8 7/9] crypto: qat: Remove VLA usage Date: Wed, 26 Sep 2018 10:53:42 +0200 Message-ID: References: <20180807211843.47586-1-keescook@chromium.org> <20180807211843.47586-8-keescook@chromium.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" 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@i To: Ard Biesheuvel Return-path: In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-crypto.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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97B67C43382 for ; Wed, 26 Sep 2018 08:54:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3EBB0204EC for ; Wed, 26 Sep 2018 08:54:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3EBB0204EC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arndb.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727741AbeIZPFz (ORCPT ); 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-Google-Smtp-Source: ACcGV60MHY9QOABRzTadUP7X+wOMtbpxWasRc5Y9aoKMLL6gHsD7XYGpfv/1QalbdZ5Je6Dw+TbrmBBzWJksxO/oWs0= 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