From patchwork Wed Sep 19 02:10:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10605191 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 D4C4515A6 for ; Wed, 19 Sep 2018 02:19:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C1EC32BFEB for ; Wed, 19 Sep 2018 02:19:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B569C2BFFF; Wed, 19 Sep 2018 02:19:43 +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=unavailable 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 5E27A2BFEB for ; Wed, 19 Sep 2018 02:19:43 +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=ihGq+vTwaOX8ttAUb25TP9dMStgUWphik9nG3/5m5VQ=; b=OCNv0qw/+P8ReUsMc98W2eq7Lg LX5djEBZITMBHV/CA7We0yOggG92dA7wCQ+/HeVQcL4hlTJd1XcCcOqt3+UN6DXLCjlzbJiYzCBqu ZHs2rkwTp2RYmlpK24C5nNSM5M/5ZalQsQ0fdLbJusLedofROSUZl6EaFQfrMtSDCtgI7TyWSajRq nRyL2vLI7i7PTFFl12PmDmid+e+OtrCoDHvJHU8P0GwY9Bq+7NpECbKRnzzIvlJOSs7UtcnFlljbw vibScUd6T1IXH4wxFnP5C4TL7eAuRrKIXQwlrrZnmr/3uMFolufnhzf71u4QkkVUwJ3CeBPQFnNpr DTDfOAEg==; 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 1g2S5a-0004Ou-Oj; Wed, 19 Sep 2018 02:19:38 +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 1g2S5X-0004Me-4b for linux-arm-kernel@lists.infradead.org; Wed, 19 Sep 2018 02:19:37 +0000 Received: by mail-pl1-x642.google.com with SMTP id f1-v6so1872450plt.4 for ; Tue, 18 Sep 2018 19:19:22 -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=raNi17qMsy3qz3vPZkj768GrqOCILiI6YaVltdqquAE=; b=A9DjIL3JTEHoLzAv2OHeypKei/INHBWQzqyqz6iiG4mq49wM7Y4eNEMqPpt0gksuLl thFtSZW5NcdJAk+PmxfC1n/UsAHOMY7Ma5XtHk3lHHUWg6QxkTYRnTFLtCFMFlYONZQh 1NjMex7X8q1okNQWm+deh+2LIMKYWxmXXWyAw= 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=raNi17qMsy3qz3vPZkj768GrqOCILiI6YaVltdqquAE=; b=MoTj5cKGxIzjE3MP+OtxSb3PrwRtBmD8Ner+j/wd5WkaNNbRm0q1vbwKuGidxIqfV+ C3eF3dbfKODJssAO1n+8/q/JvbuxRSeL84hxmyn/ZAhDTB3L1Ix+RgAG5pgihnZQT6Ev OjN9042Ls+FbJGPmJKvR9+u4U91K35rEGQP3jaUP9JCvfuX40fcpYYCw4gBasbCCuEIJ k8b2tYWkIqQLTj4wx3TnzjuJfyTreBor9FPWJiRvA5nCykPoJ/Hr4ihKLkC5ZW+RCNXR /iptCrro6N3Bz8B6jD85aQKaLrS2mLk6zhLeXwJkDVlo8vGOxlKk0x7ovqgHtN74rjrc 0KeQ== X-Gm-Message-State: APzg51CnZyTWYkRS3Au9IFk/c/2kWpqB29IZVWaAM3AivfIvu16niuHd ZV+ugwO+8Ns1CZz3TZr/Cv21xw== X-Google-Smtp-Source: ANB0VdYkwPhSzdiZcF3NawZ/nZhJDnPNfmHeaa2Z36lULhaQfL/zFwIa7wf5TLl0TNvm2XzYmUndbg== X-Received: by 2002:a17:902:b7c5:: with SMTP id v5-v6mr32498180plz.49.1537323562272; Tue, 18 Sep 2018 19:19:22 -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 e26-v6sm24230287pfi.70.2018.09.18.19.19.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 18 Sep 2018 19:19:18 -0700 (PDT) From: Kees Cook To: Herbert Xu Subject: [PATCH crypto-next 22/23] crypto: picoxcell - Remove VLA usage of skcipher Date: Tue, 18 Sep 2018 19:10:59 -0700 Message-Id: <20180919021100.3380-23-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180919021100.3380-1-keescook@chromium.org> References: <20180919021100.3380-1-keescook@chromium.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180918_191935_199730_F18925BC X-CRM114-Status: GOOD ( 16.30 ) 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: Kees Cook , Eric Biggers , Ard Biesheuvel , Linux Kernel Mailing List , linux-crypto , Jamie Iles , linux-arm-kernel@lists.infradead.org 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 replaces struct crypto_skcipher and SKCIPHER_REQUEST_ON_STACK() usage with struct crypto_sync_skcipher and SYNC_SKCIPHER_REQUEST_ON_STACK(), which uses a fixed stack size. [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Cc: Jamie Iles Cc: linux-arm-kernel@lists.infradead.org Signed-off-by: Kees Cook --- drivers/crypto/picoxcell_crypto.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/drivers/crypto/picoxcell_crypto.c b/drivers/crypto/picoxcell_crypto.c index 321d5e2ac833..a28f1d18fe01 100644 --- a/drivers/crypto/picoxcell_crypto.c +++ b/drivers/crypto/picoxcell_crypto.c @@ -171,7 +171,7 @@ struct spacc_ablk_ctx { * The fallback cipher. If the operation can't be done in hardware, * fallback to a software version. */ - struct crypto_skcipher *sw_cipher; + struct crypto_sync_skcipher *sw_cipher; }; /* AEAD cipher context. */ @@ -799,17 +799,17 @@ static int spacc_aes_setkey(struct crypto_ablkcipher *cipher, const u8 *key, * Set the fallback transform to use the same request flags as * the hardware transform. */ - crypto_skcipher_clear_flags(ctx->sw_cipher, + crypto_sync_skcipher_clear_flags(ctx->sw_cipher, CRYPTO_TFM_REQ_MASK); - crypto_skcipher_set_flags(ctx->sw_cipher, + crypto_sync_skcipher_set_flags(ctx->sw_cipher, cipher->base.crt_flags & CRYPTO_TFM_REQ_MASK); - err = crypto_skcipher_setkey(ctx->sw_cipher, key, len); + err = crypto_sync_skcipher_setkey(ctx->sw_cipher, key, len); tfm->crt_flags &= ~CRYPTO_TFM_RES_MASK; tfm->crt_flags |= - crypto_skcipher_get_flags(ctx->sw_cipher) & + crypto_sync_skcipher_get_flags(ctx->sw_cipher) & CRYPTO_TFM_RES_MASK; if (err) @@ -914,7 +914,7 @@ static int spacc_ablk_do_fallback(struct ablkcipher_request *req, struct crypto_tfm *old_tfm = crypto_ablkcipher_tfm(crypto_ablkcipher_reqtfm(req)); struct spacc_ablk_ctx *ctx = crypto_tfm_ctx(old_tfm); - SKCIPHER_REQUEST_ON_STACK(subreq, ctx->sw_cipher); + SYNC_SKCIPHER_REQUEST_ON_STACK(subreq, ctx->sw_cipher); int err; /* @@ -922,7 +922,7 @@ static int spacc_ablk_do_fallback(struct ablkcipher_request *req, * the ciphering has completed, put the old transform back into the * request. */ - skcipher_request_set_tfm(subreq, ctx->sw_cipher); + skcipher_request_set_sync_tfm(subreq, ctx->sw_cipher); skcipher_request_set_callback(subreq, req->base.flags, NULL, NULL); skcipher_request_set_crypt(subreq, req->src, req->dst, req->nbytes, req->info); @@ -1020,9 +1020,8 @@ static int spacc_ablk_cra_init(struct crypto_tfm *tfm) ctx->generic.flags = spacc_alg->type; ctx->generic.engine = engine; if (alg->cra_flags & CRYPTO_ALG_NEED_FALLBACK) { - ctx->sw_cipher = crypto_alloc_skcipher( - alg->cra_name, 0, CRYPTO_ALG_ASYNC | - CRYPTO_ALG_NEED_FALLBACK); + ctx->sw_cipher = crypto_alloc_sync_skcipher( + alg->cra_name, 0, CRYPTO_ALG_NEED_FALLBACK); if (IS_ERR(ctx->sw_cipher)) { dev_warn(engine->dev, "failed to allocate fallback for %s\n", alg->cra_name); @@ -1041,7 +1040,7 @@ static void spacc_ablk_cra_exit(struct crypto_tfm *tfm) { struct spacc_ablk_ctx *ctx = crypto_tfm_ctx(tfm); - crypto_free_skcipher(ctx->sw_cipher); + crypto_free_sync_skcipher(ctx->sw_cipher); } static int spacc_ablk_encrypt(struct ablkcipher_request *req)