From nobody Tue Sep 9 21:32:29 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA6DCC74A44 for ; Sat, 11 Mar 2023 09:42:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230217AbjCKJmQ (ORCPT ); Sat, 11 Mar 2023 04:42:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230102AbjCKJmI (ORCPT ); Sat, 11 Mar 2023 04:42:08 -0500 Received: from 167-179-156-38.a7b39c.syd.nbn.aussiebb.net (167-179-156-38.a7b39c.syd.nbn.aussiebb.net [167.179.156.38]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A2031981; Sat, 11 Mar 2023 01:42:06 -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 1pavEB-002xbR-I9; Sat, 11 Mar 2023 17:09:24 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Sat, 11 Mar 2023 17:09:23 +0800 From: "Herbert Xu" Date: Sat, 11 Mar 2023 17:09:23 +0800 Subject: [v7 PATCH 7/8] crypto: stm32 - Fix empty message processing References: To: Linus Walleij , Lionel Debieve , Li kunyu , davem@davemloft.net, linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, mcoquelin.stm32@gmail.com Message-Id: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Change the emptymsg check in stm32_hash_copy_hash to rely on whether we have any existing hash state, rather than whether this particular update request is empty. =20 Also avoid computing the hash for empty messages as this could hang. Signed-off-by: Herbert Xu Reviewed-by: Linus Walleij Tested-by: Linus Walleij --- drivers/crypto/stm32/stm32-hash.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/drivers/crypto/stm32/stm32-hash.c b/drivers/crypto/stm32/stm32= -hash.c index 478822fc7a4e..f898ec62b459 100644 --- a/drivers/crypto/stm32/stm32-hash.c +++ b/drivers/crypto/stm32/stm32-hash.c @@ -95,6 +95,7 @@ #define HASH_FLAGS_SHA1 BIT(19) #define HASH_FLAGS_SHA224 BIT(20) #define HASH_FLAGS_SHA256 BIT(21) +#define HASH_FLAGS_EMPTY BIT(22) #define HASH_FLAGS_HMAC BIT(23) =20 #define HASH_OP_UPDATE 1 @@ -310,13 +311,6 @@ static void stm32_hash_write_ctrl(struct stm32_hash_de= v *hdev, int bufcnt) reg |=3D HASH_CR_LKEY; } =20 - /* - * On the Ux500 we need to set a special flag to indicate that - * the message is zero length. - */ - if (hdev->pdata->ux500 && bufcnt =3D=3D 0) - reg |=3D HASH_CR_UX500_EMPTYMSG; - if (!hdev->polled) stm32_hash_write(hdev, HASH_IMR, HASH_DCIE); =20 @@ -366,13 +360,23 @@ static void stm32_hash_append_sg(struct stm32_hash_re= quest_ctx *rctx) static int stm32_hash_xmit_cpu(struct stm32_hash_dev *hdev, const u8 *buf, size_t length, int final) { + struct stm32_hash_request_ctx *rctx =3D ahash_request_ctx(hdev->req); + struct stm32_hash_state *state =3D &rctx->state; unsigned int count, len32; const u32 *buffer =3D (const u32 *)buf; u32 reg; =20 - if (final) + if (final) { hdev->flags |=3D HASH_FLAGS_FINAL; =20 + /* Do not process empty messages if hw is buggy. */ + if (!(hdev->flags & HASH_FLAGS_INIT) && !length && + hdev->pdata->broken_emptymsg) { + state->flags |=3D HASH_FLAGS_EMPTY; + return 0; + } + } + len32 =3D DIV_ROUND_UP(length, sizeof(u32)); =20 dev_dbg(hdev->dev, "%s: length: %zd, final: %x len32 %i\n", @@ -827,7 +831,7 @@ static void stm32_hash_copy_hash(struct ahash_request *= req) __be32 *hash =3D (void *)rctx->digest; unsigned int i, hashsize; =20 - if (hdev->pdata->broken_emptymsg && !req->nbytes) + if (hdev->pdata->broken_emptymsg && (state->flags & HASH_FLAGS_EMPTY)) return stm32_hash_emptymsg_fallback(req); =20 switch (state->flags & HASH_FLAGS_ALGO_MASK) {