From patchwork Fri Nov 25 04:36:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 25813 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3765474wrr; Thu, 24 Nov 2022 20:40:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf5i1Cx6lHGvGr1RzgoNujLbVgPf25MI9Ful3Mpq+Izw0g3r218uQPb1hARcWDxT+Av6BuVU X-Received: by 2002:a17:906:4e89:b0:7ae:c1b2:d928 with SMTP id v9-20020a1709064e8900b007aec1b2d928mr14301784eju.296.1669351214477; Thu, 24 Nov 2022 20:40:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669351214; cv=none; d=google.com; s=arc-20160816; b=xK/ruoj1XbLTiEkypaP5A3litYDF5Xh4N2BzzLZR2+MLyO5hhsZWrKQfFS7fTMW0C0 APuCx+mgI3PfzhrN4g3VCfIKB1/+nlFY6msuLlZiz/u11KuSXVBbuvlwuLrvHffQijTZ cQ4mvS/xX/fh7dM5ADjLSx4Yp+KNhjI5uniN/+ldjLm49pWQ0+L2EhI0M5ovtnp6RmbL bgXCNilJ4SmPGQZszBMnwLYdEhLPqfQSiIUcMB5FGyP5CQwkQX+vMajIfPThUIfWIVC7 obf1854tSHl2rngt/UyqvrL/3kC+GL49Uy8ZgfFEAK1m34mra7eWjKsMlWHACgTsU0hw qpXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:to:references:subject:date:from; bh=gZ2UZQ9W6009jM9Lcs+xxcuxvQXoKK0/ZWSUVwxAvlc=; b=S77THnyxzd8/uffgaYALqYDj07Cm0h2YeUY5DnFumIl/MElBv3XXq0HGgrQWAJ9P0k zNki6oOi7/B+aIaiX1HcvWhmX9XvWkfMAzNDKAS2SFtRaFr4Cb9YYNs6Px94+r1CYRz5 zSQnTQZZw3w0rPyLB8+oz+I7qfoPON27LruhVTSqPywKIZmuBX/JMBkl7EQuQP7xBYTS LT6t8QJF1x2yRMvgm2JGVkVQJaFDSmjz04Yu9LQQVJIn5sh7U/MNaNgmLpDh5hul6kCe Pk7JM3qD6K1qpxFXK13wggTxKrsKewixPmOQ71Omq6kDpinPnfkLCwRFfdCxjxirM+Dy sRIA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id tz14-20020a170907c78e00b0078277d265bcsi1927825ejc.204.2022.11.24.20.39.50; Thu, 24 Nov 2022 20:40:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229555AbiKYEhJ (ORCPT + 99 others); Thu, 24 Nov 2022 23:37:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229652AbiKYEg5 (ORCPT ); Thu, 24 Nov 2022 23:36:57 -0500 Received: from formenos.hmeau.com (helcar.hmeau.com [216.24.177.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4ABA825C74; Thu, 24 Nov 2022 20:36:52 -0800 (PST) Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.94.2 #2 (Debian)) id 1oyQS7-000dkB-Ec; Fri, 25 Nov 2022 12:36:40 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Fri, 25 Nov 2022 12:36:39 +0800 From: "Herbert Xu" Date: Fri, 25 Nov 2022 12:36:39 +0800 Subject: [v2 PATCH 6/9] crypto: api - Increase MAX_ALGAPI_ALIGNMASK to 127 References: To: Ard Biesheuvel , Will Deacon , Marc Zyngier , Arnd Bergmann , Greg Kroah-Hartman , Andrew Morton , Linus Torvalds , Linux Memory Management List , Linux ARM , Linux Kernel Mailing List , "David S. Miller" , Linux Crypto Mailing List Message-Id: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750441618955243476?= X-GMAIL-MSGID: =?utf-8?q?1750441618955243476?= Previously we limited the maximum alignment mask to 63. This is mostly due to stack usage for shash. This patch introduces a separate limit for shash algorithms and increases the general limit to 127 which is the value that we need for DMA allocations on arm64. Signed-off-by: Herbert Xu --- crypto/shash.c | 9 +++++++-- include/crypto/algapi.h | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/crypto/shash.c b/crypto/shash.c index 4c88e63b3350..22c744389586 100644 --- a/crypto/shash.c +++ b/crypto/shash.c @@ -18,6 +18,8 @@ #include "internal.h" +#define MAX_SHASH_ALIGNMASK 63 + static const struct crypto_type crypto_shash_type; static int shash_no_setkey(struct crypto_shash *tfm, const u8 *key, @@ -100,7 +102,7 @@ static int shash_update_unaligned(struct shash_desc *desc, const u8 *data, * We cannot count on __aligned() working for large values: * https://patchwork.kernel.org/patch/9507697/ */ - u8 ubuf[MAX_ALGAPI_ALIGNMASK * 2]; + u8 ubuf[MAX_SHASH_ALIGNMASK * 2]; u8 *buf = PTR_ALIGN(&ubuf[0], alignmask + 1); int err; @@ -142,7 +144,7 @@ static int shash_final_unaligned(struct shash_desc *desc, u8 *out) * We cannot count on __aligned() working for large values: * https://patchwork.kernel.org/patch/9507697/ */ - u8 ubuf[MAX_ALGAPI_ALIGNMASK + HASH_MAX_DIGESTSIZE]; + u8 ubuf[MAX_SHASH_ALIGNMASK + HASH_MAX_DIGESTSIZE]; u8 *buf = PTR_ALIGN(&ubuf[0], alignmask + 1); int err; @@ -536,6 +538,9 @@ static int shash_prepare_alg(struct shash_alg *alg) alg->statesize > HASH_MAX_STATESIZE) return -EINVAL; + if (base->cra_alignmask > MAX_SHASH_ALIGNMASK) + return -EINVAL; + if ((alg->export && !alg->import) || (alg->import && !alg->export)) return -EINVAL; diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index 4c99eb66e654..8722fd67f40a 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h @@ -22,7 +22,7 @@ * algs and architectures. Ciphers have a lower maximum size. */ #define MAX_ALGAPI_BLOCKSIZE 160 -#define MAX_ALGAPI_ALIGNMASK 63 +#define MAX_ALGAPI_ALIGNMASK 127 #define MAX_CIPHER_BLOCKSIZE 16 #define MAX_CIPHER_ALIGNMASK 15