From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DE630C38147 for ; Wed, 18 Jan 2023 14:55:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=lUtJY2IN53Vgq3TWpeG+Y3El9CoHL0AvH4W5dZ+tv7I=; b=KbmGOwctlezjex KIx8IGo7bVeINQQNzv/qNxEreaGsakxoL+q2HOq1ozsEg5LVWt//rUnPsKsw1cKVNMRCcqR3uX7p7 62PJVjNQoKA+KEmZMOG3MtSd4O/M1FSpWb/aPB04cz47/FiV18oZLgDtUE98cNhUZLf5D/TuT4TYc 8dx1DdwTPjv0GtJhjstRz1Xup1g+uzqnZdgRgbyDYO79DD9vzj5tRx5Orf3Xn18pLdGq2Xh3VqQHN tk11fjcJVMu6xYlzw7FMF+aAS+oGwuj4E3naC9aCZVprJdPk3CmonzhI1gtJyyb0mNhjrrW+wITrx yVQueZ7VVq06iR6vgYdA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pI9pV-001S9q-31; Wed, 18 Jan 2023 14:54:21 +0000 Received: from helcar.hmeau.com ([216.24.177.18] helo=formenos.hmeau.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pI9pR-001S7f-9N for linux-arm-kernel@lists.infradead.org; Wed, 18 Jan 2023 14:54:20 +0000 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 1pI9pD-001P0M-LV; Wed, 18 Jan 2023 22:54:04 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Wed, 18 Jan 2023 22:54:03 +0800 Date: Wed, 18 Jan 2023 22:54:03 +0800 From: Herbert Xu To: Tianjia Zhang Cc: "David S. Miller" , Catalin Marinas , Will Deacon , linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Ard Biesheuvel Subject: Re: [PATCH] crypto: arm64/sm4 - Fix possible crash in GCM cryption Message-ID: References: <20230118141928.48136-1-tianjia.zhang@linux.alibaba.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230118141928.48136-1-tianjia.zhang@linux.alibaba.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230118_065417_345622_246EB532 X-CRM114-Status: GOOD ( 18.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Jan 18, 2023 at 10:19:28PM +0800, Tianjia Zhang wrote: > When the cryption total length is zero, GCM cryption call > skcipher_walk_done() will cause an unexpected crash, so skip calling > this function to avoid possible crash when the GCM cryption length > is equal to zero. > > Fixes: ae1b83c7d572 ("crypto: arm64/sm4 - add CE implementation for GCM mode") > Signed-off-by: Tianjia Zhang > --- > arch/arm64/crypto/sm4-ce-gcm-glue.c | 12 +++++++----- > 1 file changed, 7 insertions(+), 5 deletions(-) > > diff --git a/arch/arm64/crypto/sm4-ce-gcm-glue.c b/arch/arm64/crypto/sm4-ce-gcm-glue.c > index c450a2025ca9..9b63bcf9aa85 100644 > --- a/arch/arm64/crypto/sm4-ce-gcm-glue.c > +++ b/arch/arm64/crypto/sm4-ce-gcm-glue.c > @@ -178,11 +178,13 @@ static int gcm_crypt(struct aead_request *req, struct skcipher_walk *walk, > > kernel_neon_end(); > > - err = skcipher_walk_done(walk, tail); > - if (err) > - return err; > - if (walk->nbytes) > - kernel_neon_begin(); > + if (walk->nbytes) { Please do if (!walk->nbytes) break; As an additional improvement, the tail calculation can be removed entirely because you already set the chunksize so the walker should only be feeding you multiples of chunksize except at the end. Cheers, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 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 04F37C32793 for ; Wed, 18 Jan 2023 14:58:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230435AbjARO6h (ORCPT ); Wed, 18 Jan 2023 09:58:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231290AbjARO56 (ORCPT ); Wed, 18 Jan 2023 09:57:58 -0500 Received: from formenos.hmeau.com (helcar.hmeau.com [216.24.177.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFB8310EF; Wed, 18 Jan 2023 06:54:18 -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 1pI9pD-001P0M-LV; Wed, 18 Jan 2023 22:54:04 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Wed, 18 Jan 2023 22:54:03 +0800 Date: Wed, 18 Jan 2023 22:54:03 +0800 From: Herbert Xu To: Tianjia Zhang Cc: "David S. Miller" , Catalin Marinas , Will Deacon , linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Ard Biesheuvel Subject: Re: [PATCH] crypto: arm64/sm4 - Fix possible crash in GCM cryption Message-ID: References: <20230118141928.48136-1-tianjia.zhang@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230118141928.48136-1-tianjia.zhang@linux.alibaba.com> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Wed, Jan 18, 2023 at 10:19:28PM +0800, Tianjia Zhang wrote: > When the cryption total length is zero, GCM cryption call > skcipher_walk_done() will cause an unexpected crash, so skip calling > this function to avoid possible crash when the GCM cryption length > is equal to zero. > > Fixes: ae1b83c7d572 ("crypto: arm64/sm4 - add CE implementation for GCM mode") > Signed-off-by: Tianjia Zhang > --- > arch/arm64/crypto/sm4-ce-gcm-glue.c | 12 +++++++----- > 1 file changed, 7 insertions(+), 5 deletions(-) > > diff --git a/arch/arm64/crypto/sm4-ce-gcm-glue.c b/arch/arm64/crypto/sm4-ce-gcm-glue.c > index c450a2025ca9..9b63bcf9aa85 100644 > --- a/arch/arm64/crypto/sm4-ce-gcm-glue.c > +++ b/arch/arm64/crypto/sm4-ce-gcm-glue.c > @@ -178,11 +178,13 @@ static int gcm_crypt(struct aead_request *req, struct skcipher_walk *walk, > > kernel_neon_end(); > > - err = skcipher_walk_done(walk, tail); > - if (err) > - return err; > - if (walk->nbytes) > - kernel_neon_begin(); > + if (walk->nbytes) { Please do if (!walk->nbytes) break; As an additional improvement, the tail calculation can be removed entirely because you already set the chunksize so the walker should only be feeding you multiples of chunksize except at the end. Cheers, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt