From patchwork Tue Sep 4 18:16:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10587747 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 76DF3175A for ; Tue, 4 Sep 2018 18:16:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62C002985D for ; Tue, 4 Sep 2018 18:16:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 55FEF29C1F; Tue, 4 Sep 2018 18:16:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D81E62985D for ; Tue, 4 Sep 2018 18:16:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Y7q6kQ94QSqWEMP7j9d0Gftm6VTS7KrPkKtKIcLEecI=; b=uJuP9UErhfuQ+eW3cGXFYSrbJH 7+evmwH0H7llQ7f+GaTviUTAJUUGc7VnrBUMQYHzDzWcobOOecCpAxaysRYvgw+b3wyN430FJUx6o n/JbuOK+s0bcX+DcLyGWp/SaPW39gg8GOjM43s9TrSyK86R2SSYBjcto8Qxyf3fmX+Ng75SosszTB dvHtndbJIw3elospEV59qXazNYJ8qAQRLLHnuaxNIKkURiVe1JfOjXgeTaxiRxRrcTjZNHffJZRtN hEatpteJjJEwv4uSAPxmwjqLuO+51afdGf/B8XqUoBGAxRL2pnSwNiMcg33fLDwIuVngr69RLAWga ytJFfIXw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fxFsf-0000mq-95; Tue, 04 Sep 2018 18:16:49 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fxFsb-0000k9-FV for linux-arm-kernel@lists.infradead.org; Tue, 04 Sep 2018 18:16:47 +0000 Received: by mail-pl1-x642.google.com with SMTP id f6-v6so2016868plo.1 for ; Tue, 04 Sep 2018 11:16:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Grbq2zQ3A4RhONhGOZUwbxnQrSQ434BRDzK8+t1CT3o=; b=ThtCkZ2YkCZaLcEhmQ/Zr23+uw5rXcjk2HmjnCpWaiQIvxg13hkLbzdjgfEhbUn/VS KesgmKVo6v/JS1wbMSP6olTM9AOJEW9OnZQ1IzyfkVU9izj1FA/euGHLuooSpp6UR0if EN8fIByydxDx3Gu6VCAzBFpe2qp/cwtkiFyd0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Grbq2zQ3A4RhONhGOZUwbxnQrSQ434BRDzK8+t1CT3o=; b=ofzIYPHFgrEkQrGiaWeasbsX6wzV313WuQfLDYdpzMGezOYrifP/E4UxRycs63DplM 3FkRljhodaBAOpuTWkWUjZNAunImkhGa/+7dMyUb18RrK2+lDHqn7nn+s9Zjue3MauKa uCHI1Q32YA+p6mESv1ka+zNyEA3ZmTRNqn4HtuK/EG5ETg3JTKVZCsBQDvTUe6BiNEbU NfEFjAfiPVlrFUOEth4c6RVt8oIkYmbn/FoR0rKwZu6ZpuTEzJqmyUle2sMt3bHwEyZh 8XHGrJq/7jvGg2zffzBdhvTNBOZcETD6EuYYWyrrmULZERxPyO7QCy7T08WZJ4ziagrW 5UWw== X-Gm-Message-State: APzg51ATtM3RAlxaYZIEsZb3POZa+oD1dXj5emC5njwkQfy/rtV/smDM ijBU2N352gpiGeiYBaz+zzWIOQ== X-Google-Smtp-Source: ANB0VdZqhIyxgVgJ/wEoDsmFr44ZGNjpNJ2Fg7Mg6OTMFLfOQwhIwzN8isNxfWlaSEQ0CjFGhfoe2A== X-Received: by 2002:a17:902:8a92:: with SMTP id p18-v6mr34176720plo.148.1536084994102; Tue, 04 Sep 2018 11:16:34 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id r205-v6sm61545336pgr.11.2018.09.04.11.16.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Sep 2018 11:16:32 -0700 (PDT) From: Kees Cook To: Herbert Xu Subject: [PATCH 2/2] crypto: skcipher: Remove VLA usage for SKCIPHER_REQUEST_ON_STACK Date: Tue, 4 Sep 2018 11:16:29 -0700 Message-Id: <20180904181629.20712-3-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180904181629.20712-1-keescook@chromium.org> References: <20180904181629.20712-1-keescook@chromium.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180904_111645_518748_B0D4D8D1 X-CRM114-Status: GOOD ( 15.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maxime Ripard , Arnaud Ebalard , Kees Cook , Boris Brezillon , Antoine Tenart , Ard Biesheuvel , linux-kernel@vger.kernel.org, Gilad Ben-Yossef , Chen-Yu Tsai , Eric Biggers , linux-crypto@vger.kernel.org, Jonathan Cameron , Philippe Ombredanne , Corentin Labbe , linux-arm-kernel@lists.infradead.org, Christian Lamparter MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 [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 /**