Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1379746imm; Wed, 20 Jun 2018 17:15:59 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ5+gqrQqfLxumoF3A7A/S/OS9w2D/9HJho88B9/7jNF2mdCrSRl4Or+h1ulul3fwNxUpbW X-Received: by 2002:a62:a054:: with SMTP id r81-v6mr24790885pfe.10.1529540158979; Wed, 20 Jun 2018 17:15:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529540158; cv=none; d=google.com; s=arc-20160816; b=LHSpucBelzxbFwz3aCOPRMnSqk6mGbOqTGKV7suYhuCsRNEjrH2H8+JZJet64q1bwR UTEinAZAu/jhyk1u+2NLS+GlqmKH3CykO6X+9swuceUFfP/HfYpmxwxShZ0znS+I27Yc GQNOidXn8pQAu9Gb2pUDACCaftbwFSVNLx8FtZQwHqfJPAxXaFdbf4rd0fqMc8oqAIQl ADECWBNbDSERzxbaDtFDNUbLPspAEilUxR+Cc++/VFP+3CKqmu50wM8n2TC8PQR3Xm9t abYW1mnmfmTjbjAg32HcBRvmK+Ee37DyU9F9oQVi5IoBvDKKzdIM+TI5EMJc2vLjqcJJ c7DQ== 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=MPEb6HaVG+FCnZtxTALeJjvKiOS6SVXuhO4vjhjOumw=; b=VGrvociiWhFx7t5hlzKtZL8eQnZOQGREcogAyC4zL0YdefhU4IfvU0o2fTzIUvtWQV 1mSVNe8e05eDDyeI5znUML3qv3kNPvkzj71W7a0qyYK0Db/Xnu7iar9EVJO/8no2bqJx 40tAYH7/TadS1SkbAoFVXOAxv25TnmLppi/ph54/MEnBtG8x8/J6cYUq+6DcSjcZM0yb z4wCYsvRoeJMMZdLrNc5N21wmqyePt73Yp8eXbdEOUeOBHsAdKi0nk6hMcUYHxHLwZaL HKfcPHqZvEmi1uzequUX5yjKL7VatR+8LfHVTYLbLPAQQZl0PlBZZGr2BSiEQbzX0R05 ctdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=N9i6oRkp; dkim=fail header.i=@chromium.org header.s=google header.b=E5Y0Z7dB; 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 p33-v6si3352515pld.318.2018.06.20.17.15.44; Wed, 20 Jun 2018 17:15:58 -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=N9i6oRkp; dkim=fail header.i=@chromium.org header.s=google header.b=E5Y0Z7dB; 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 S933014AbeFUAPI (ORCPT + 99 others); Wed, 20 Jun 2018 20:15:08 -0400 Received: from mail-yb0-f193.google.com ([209.85.213.193]:44933 "EHLO mail-yb0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932552AbeFUAPH (ORCPT ); Wed, 20 Jun 2018 20:15:07 -0400 Received: by mail-yb0-f193.google.com with SMTP id w74-v6so525837ybe.11 for ; Wed, 20 Jun 2018 17:15:06 -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=MPEb6HaVG+FCnZtxTALeJjvKiOS6SVXuhO4vjhjOumw=; b=N9i6oRkpO/Jt63soS/kemWoXBSPilX9Una637S3fTnQUuXxNHnybubuh9DbnAmZxoh NhaVgS4p6P02OaB7Th51fBXu98BXPmCOi19Eegi9zfMAQ/sxUFnE7f8sPdXAaNNefSV+ TYSRbEYfTAxmWhDB0Ra0aDdJTGB2VqEtRfJ3GcURVAUtqOjSPYy+tHc+Rf0LJ/vM5WFC ug7rm6VNcq/2GVJyUNwghj9fZ80WgZvCslP5mPqeAua25q/adWg5B42k3Fs4FIEWsvU8 H0bSh7BnipzYWBfRNNfUe7R+bs/sE8oaJqFgHabNK0pigA+YsjtlAtNBlADqM8v/8GWg HPug== 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=MPEb6HaVG+FCnZtxTALeJjvKiOS6SVXuhO4vjhjOumw=; b=E5Y0Z7dBpsQkTgwDPCqvMc6SobIqZLn7t+p04vlCJhccoy7jIzTq8F3JPPJFGuHlgI xGlRylRJWJOsvUIeUaBHUCXQNDb6X35MO+0iJELDeqjR4bqNY+UZhnxcoQq+PCE5G2Ua 3DDcD53gGkx5Am3Ldprj3zKr93GKH7rL4n3As= 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=MPEb6HaVG+FCnZtxTALeJjvKiOS6SVXuhO4vjhjOumw=; b=ufbftGExlxVO0HQrp8vcznIMOj70DWZQ99J8JyU5p4y0BlW7jMWYVjzbe1qmrj1Pbm CVXJjVr0a/Ycwe3DEj/H/oICrKhE7Xayr+tzCPCRARQCnKoZ7YG4BQQ4ggIiEnqODEdF Akqha8aNoGKS2nTsScPwpC2N/bZKPg8qzmLL6aMIRzzWU4dwW5FYC2KFuu/kDFUYHe11 k+9HcAjfTlgtdLSZIiqDYzhqG4sE6RkMoMbfSKixMVr6BFxkxeTYa4zM6ST0s7f4yJcX chNaQrPatzywYSSmmLN99P4P8w5D1kYEtL/kEt5WK8GGC7NyaFZDPyAH3lypYGs/oF9B VQCQ== X-Gm-Message-State: APt69E2iXUvkJIdOUTyB9aOqrelKYv2Q8uvmTXxvpi1EM1Q2hd+sFktt KN4lYgvf6SNt9Cif/Wc2YdjirILGU4bcc6+xXWkEig== X-Received: by 2002:a25:f81e:: with SMTP id u30-v6mr9675674ybd.343.1529540106255; Wed, 20 Jun 2018 17:15:06 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a25:d6c5:0:0:0:0:0 with HTTP; Wed, 20 Jun 2018 17:15:05 -0700 (PDT) In-Reply-To: <20180620235721.GF111712@gmail.com> References: <20180620190408.45104-1-keescook@chromium.org> <20180620190408.45104-10-keescook@chromium.org> <20180620235721.GF111712@gmail.com> From: Kees Cook Date: Wed, 20 Jun 2018 17:15:05 -0700 X-Google-Sender-Auth: 8qHeARa-UcDUYGQH-J82OWex_bQ Message-ID: Subject: Re: [PATCH 09/11] crypto: shash: Remove VLA usage in unaligned hashing 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 Wed, Jun 20, 2018 at 4:57 PM, Eric Biggers wrote: > On Wed, Jun 20, 2018 at 12:04:06PM -0700, Kees Cook wrote: >> In the quest to remove all stack VLA usage from the kernel[1], this uses >> the newly defined max alignment to perform unaligned hashing to avoid >> VLAs, and drops the helper function while adding sanity checks on the >> resulting buffer sizes. >> >> [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com >> >> Signed-off-by: Kees Cook >> --- >> crypto/shash.c | 21 ++++++++++----------- >> 1 file changed, 10 insertions(+), 11 deletions(-) >> >> diff --git a/crypto/shash.c b/crypto/shash.c >> index ab6902c6dae7..1bb58209330a 100644 >> --- a/crypto/shash.c >> +++ b/crypto/shash.c >> @@ -73,13 +73,6 @@ int crypto_shash_setkey(struct crypto_shash *tfm, const u8 *key, >> } >> EXPORT_SYMBOL_GPL(crypto_shash_setkey); >> >> -static inline unsigned int shash_align_buffer_size(unsigned len, >> - unsigned long mask) >> -{ >> - typedef u8 __aligned_largest u8_aligned; >> - return len + (mask & ~(__alignof__(u8_aligned) - 1)); >> -} >> - >> static int shash_update_unaligned(struct shash_desc *desc, const u8 *data, >> unsigned int len) >> { >> @@ -88,11 +81,14 @@ static int shash_update_unaligned(struct shash_desc *desc, const u8 *data, >> unsigned long alignmask = crypto_shash_alignmask(tfm); >> unsigned int unaligned_len = alignmask + 1 - >> ((unsigned long)data & alignmask); >> - u8 ubuf[shash_align_buffer_size(unaligned_len, alignmask)] >> - __aligned_largest; >> + u8 ubuf[CRYPTO_ALG_MAX_ALIGNMASK] >> + __aligned(CRYPTO_ALG_MAX_ALIGNMASK + 1); >> u8 *buf = PTR_ALIGN(&ubuf[0], alignmask + 1); >> int err; > > Are you sure that __attribute__((aligned(64))) works correctly on stack > variables on all architectures? > > And if it is expected to work, then why is the buffer still aligned by hand on > the very next line? I really don't know -- the existing code was doing both the __align bit and the manual alignment, so I was trying to simplify it while removing the VLA. I'm totally open to suggestions here. BTW, these are also the only users of __aligned_largest() in the kernel, and the only use of unsized __attribute__((aligned)) -Kees -- Kees Cook Pixel Security