From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-by2nam03on0126.outbound.protection.outlook.com ([104.47.42.126]:2432 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755456AbeDIA0w (ORCPT ); Sun, 8 Apr 2018 20:26:52 -0400 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Tero Kristo , Herbert Xu , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 026/293] crypto: omap-sham - fix closing of hash with separate finalize call Date: Mon, 9 Apr 2018 00:23:10 +0000 Message-ID: <20180409002239.163177-26-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Tero Kristo [ Upstream commit 898d86a565925f09de3d0b30cf3b47ec2e409680 ] Currently there is an interesting corner case failure with omap-sham driver, if the finalize call is done separately with no data, but all previous data has already been processed. In this case, it is not possible to close the hash with the hardware without providing any data, so we get incorrect results. Fix this by adjusting the size of data sent to the hardware crypto engine in case the non-final data size falls on the block size boundary, by reducing the amount of data sent by one full block. This makes it sure that we always have some data available for the finalize call and we can close the hash properly. Signed-off-by: Tero Kristo Reported-by: Aparna Balasubramanian Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- drivers/crypto/omap-sham.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c index c65b49baf0c7..d8305ddf87d0 100644 --- a/drivers/crypto/omap-sham.c +++ b/drivers/crypto/omap-sham.c @@ -750,7 +750,10 @@ static int omap_sham_align_sgs(struct scatterlist *sg, if (final) new_len =3D DIV_ROUND_UP(new_len, bs) * bs; else - new_len =3D new_len / bs * bs; + new_len =3D (new_len - 1) / bs * bs; + + if (nbytes !=3D new_len) + list_ok =3D false; =20 while (nbytes > 0 && sg_tmp) { n++; @@ -846,6 +849,8 @@ static int omap_sham_prepare_request(struct ahash_reque= st *req, bool update) xmit_len =3D DIV_ROUND_UP(xmit_len, bs) * bs; else xmit_len =3D xmit_len / bs * bs; + } else if (!final) { + xmit_len -=3D bs; } =20 hash_later =3D rctx->total - xmit_len; @@ -1137,7 +1142,7 @@ retry: ctx =3D ahash_request_ctx(req); =20 err =3D omap_sham_prepare_request(req, ctx->op =3D=3D OP_UPDATE); - if (err) + if (err || !ctx->total) goto err1; =20 dev_dbg(dd->dev, "handling new req, op: %lu, nbytes: %d\n", --=20 2.15.1