Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3572156imm; Wed, 5 Sep 2018 02:20:06 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbNnzJewIH1qb9iUQ5yLX1k0vNemaj9XfEZjettzZuBLbLsPAnE6s9J/5C5zzF27zVkrra+ X-Received: by 2002:a63:2150:: with SMTP id s16-v6mr35664621pgm.267.1536139206424; Wed, 05 Sep 2018 02:20:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536139206; cv=none; d=google.com; s=arc-20160816; b=02SkPJ3B/RAExt6i7pysd0XTYbPANPnSLaWUaoBt1pLB/k+a90AybJK30oux1KRdvr arAFgrfNOV8nXwDJMTqrjZCDlXHlrwNc3gKgulY03WdJkrRubcdwfxcva4B/MQLuRVop oQd32aripD8ekHIQ1aJzgprcwBWeJWK7ZX8wwWrX60RJ86gmh6CfAerFg3DU2IDRujn/ zb9OlMhxJ4OKp8IxtiUYzxXocSy0U/+Fhmlrw9wcGSTyCw7QNlmqMhxVs2v3j3Ha53p6 clqms6UTg3A/ye7kKGmAhZmZl7TErhy9tA4TZOEUnZHlRn6R5YpNQJEhle+cX9KLsTJt bSwg== 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; bh=/kmiQGk9OCyxH/PSMCRPEP5L1pOrph9HrPJQdBJjVYA=; b=hvxcbFhjqF8+o1BAApVq3otXMWOlr+Gcw/iNYOZultHqi64qHu/p2XE8I6L22CQJan WJq3j2EGCRyjJWBVgSbkUpqyRa6CHc1PkquC0NrsZyFmCZGaDTzwAkmGxslVT3YODT8G GPVjuuceuvVRfE8j8Yc0oMuHf778GwZPbUxi8eHqtQrp370cLuCUExI8P/dml/C/nt8R 1A7gxKoGO/6slDV1UnvErWeoERIL6XLJsvNdaWjR/9KjWXmqnDF0Qb65k1ktSTwKj5xz HjGbHYcPs4UaLIKtR3atekRLW0ZxkWhvOZbQw4tpinoZS9VTX4cl1r6zkeTrbYZl6FDF zsAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZoeMe3xu; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si1534050pfu.79.2018.09.05.02.19.51; Wed, 05 Sep 2018 02:20:06 -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=@linaro.org header.s=google header.b=ZoeMe3xu; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728309AbeIENrZ (ORCPT + 99 others); Wed, 5 Sep 2018 09:47:25 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:51631 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726035AbeIENrY (ORCPT ); Wed, 5 Sep 2018 09:47:24 -0400 Received: by mail-it0-f68.google.com with SMTP id e14-v6so8949422itf.1 for ; Wed, 05 Sep 2018 02:18:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=/kmiQGk9OCyxH/PSMCRPEP5L1pOrph9HrPJQdBJjVYA=; b=ZoeMe3xufJpJ1tb7gn0v+O+pZS6pGLwPxDoCnweK6R2rpWiajaubPafWGY48aQiRZB bTTn9rYXQLzISz4lCmWkp9hS68X6gpIS5rku3vuch3rDtL209cfeAOJcSOPwZRO0ILpX yJoWipY8MecL5db7t3My4ie70z0izqdqghfLE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=/kmiQGk9OCyxH/PSMCRPEP5L1pOrph9HrPJQdBJjVYA=; b=NqzYzN71BQjP9yP4uxVK0SmtOE+MnnKtpOf/TYNQse7piY4ykJdur+DNTqLsuGBEKs 6uafA0AVmK39sEQeYk156BAG1u9qe9r7pV8YG3hKQBHLPwPtl7rMC/IqHIbRiHpO+ftS WjrsUy6aLJD+fHprN4u70VbWEcPwd36j10iHiNppNRqpaOyTjEr/VQot+7GQOYjb2gGL 1OBrG0M9S5tI1nDsa625Yy1h+L3amOw0pgbUJ9zyIGMaQ50oz5kHDfP/r3vh8ZGFOYoc zdal9xhkHqnf7irjp89B0kJah1WLLdYtblw4+yLjKanwgwoA2D15OhcMFLaUqwPcpgjm Rgsg== X-Gm-Message-State: APzg51BqUK9vaYSlH27d6/U2JOd0jvYeY4Yw1pSBl/np8ma9rEbnRTE5 4xr5q44W5/W9Gr/R28FdVTS8yrVRaqaXl6nmQlJ8KQ== X-Received: by 2002:a24:3046:: with SMTP id q67-v6mr3231500itq.9.1536139086156; Wed, 05 Sep 2018 02:18:06 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:1c06:0:0:0:0:0 with HTTP; Wed, 5 Sep 2018 02:18:05 -0700 (PDT) In-Reply-To: <20180904181629.20712-3-keescook@chromium.org> References: <20180904181629.20712-1-keescook@chromium.org> <20180904181629.20712-3-keescook@chromium.org> From: Ard Biesheuvel Date: Wed, 5 Sep 2018 11:18:05 +0200 Message-ID: Subject: Re: [PATCH 2/2] crypto: skcipher: Remove VLA usage for SKCIPHER_REQUEST_ON_STACK To: Kees Cook Cc: Herbert Xu , Eric Biggers , Gilad Ben-Yossef , Antoine Tenart , Boris Brezillon , Arnaud Ebalard , Corentin Labbe , Maxime Ripard , Chen-Yu Tsai , Christian Lamparter , Philippe Ombredanne , Jonathan Cameron , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , Linux Kernel Mailing List , linux-arm-kernel 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 4 September 2018 at 20:16, Kees Cook wrote: > In the quest to remove all stack VLA usage from the kernel[1], this > caps the skcipher request size similar to other limits and adds a sanity > check at registration. Looking at instrumented tcrypt output, the largest > is for lrw: > > crypt: testing lrw(aes) > crypto_skcipher_set_reqsize: 8 > crypto_skcipher_set_reqsize: 88 > crypto_skcipher_set_reqsize: 472 > Are you sure this is a representative sampling? I haven't double checked myself, but we have plenty of drivers for peripherals in drivers/crypto that implement block ciphers, and they would not turn up in tcrypt unless you are running on a platform that provides the hardware in question. > [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com > > Signed-off-by: Kees Cook > --- > include/crypto/internal/skcipher.h | 3 +++ > include/crypto/skcipher.h | 4 +++- > 2 files changed, 6 insertions(+), 1 deletion(-) > > diff --git a/include/crypto/internal/skcipher.h b/include/crypto/internal/skcipher.h > index d2926ecae2ac..6da811c0747e 100644 > --- a/include/crypto/internal/skcipher.h > +++ b/include/crypto/internal/skcipher.h > @@ -130,6 +130,9 @@ static inline struct crypto_skcipher *crypto_spawn_skcipher( > static inline int crypto_skcipher_set_reqsize( > struct crypto_skcipher *skcipher, unsigned int reqsize) > { > + if (WARN_ON(reqsize > SKCIPHER_MAX_REQSIZE)) > + return -EINVAL; > + > skcipher->reqsize = reqsize; > > return 0; > diff --git a/include/crypto/skcipher.h b/include/crypto/skcipher.h > index 2f327f090c3e..c48e194438cf 100644 > --- a/include/crypto/skcipher.h > +++ b/include/crypto/skcipher.h > @@ -139,9 +139,11 @@ struct skcipher_alg { > struct crypto_alg base; > }; > > +#define SKCIPHER_MAX_REQSIZE 472 > + > #define SKCIPHER_REQUEST_ON_STACK(name, tfm) \ > char __##name##_desc[sizeof(struct skcipher_request) + \ > - crypto_skcipher_reqsize(tfm)] CRYPTO_MINALIGN_ATTR; \ > + SKCIPHER_MAX_REQSIZE] CRYPTO_MINALIGN_ATTR; \ > struct skcipher_request *name = (void *)__##name##_desc > > /** > -- > 2.17.1 >