Received: by 10.213.65.68 with SMTP id h4csp2118427imn; Sun, 8 Apr 2018 20:09:45 -0700 (PDT) X-Google-Smtp-Source: AIpwx48eJv5wSY5+Q6CrwlFJGGt/sCI+El81V5mXUl0zAyRAe3YV5wlC1KhAL5zVpl6kC1UzjCZe X-Received: by 10.99.109.75 with SMTP id i72mr23754514pgc.403.1523243385565; Sun, 08 Apr 2018 20:09:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243385; cv=none; d=google.com; s=arc-20160816; b=fvMn6JrLEffAUiptY1kUsktuIXSzbFTYBEQ0KyfE5AWOjoNUXto1aK0ldFusNLHXv3 ymFvVxPrsnLYKEFHYE2QhsVwMfif//eXbNiPGHM1E+BIz3yv5R7peFp9ByLCSqWdIFlX jgGjfM+pzoK2zSfkyQe3Jqa/t6Ii0W2sE/kzpzeUnSrvKhb+525UVQ0ZHXHWbsVgcdEB Fi4MFpWDzS7zsaduUIaw9ICDZGPevpqRQ3TbJTmJyKL+06xw62MbPMlX3jlanB+jTP6P Bb8UoUc/0syqUMG4sE8ppnAHD715BKPoebocFOFlEREe5WoELz48jHjXYrPjw907AZRy AMbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=NKfE98pSi4i0FPkiupnz+FO7OVsNfZ+j5BtzUUH+bmQ=; b=SD3ZbZgvKrqBN8bngJu/GAyb+W08L74sAASSFdwLcl0PuGywqJBfjIjV4t2EqLOpIX uQ2Yg70wOyqaxE99dswelgbaxgTkBo0W35VsZOyz/8hWF1IPsuRCJE2rJ+nXeLbGHMrK 5Pp2a5akUWH1iuemeCcJDgOH5HlFYFr/mB8IAqEADel1iYHWWslMK0dUwC5xbg/42VnG sIIYi6sm8SFdOFPrYkAJA9zdPnlc/s9u9NKXxE74ncevHxKwglTV1yAnQAYjlvtBRSt9 IMLGpk6FMcOTaEyEFNpOuETsSLrhfxX6bYwhDzwGZFM5vbpBoVYvuOZR4WQxvtO1jMer Bd6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=lQnGldLM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p2si11637483pff.253.2018.04.08.20.09.08; Sun, 08 Apr 2018 20:09:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=lQnGldLM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756538AbeDICnh (ORCPT + 99 others); Sun, 8 Apr 2018 22:43:37 -0400 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=NKfE98pSi4i0FPkiupnz+FO7OVsNfZ+j5BtzUUH+bmQ=; b=lQnGldLMlzrtsRiuSCa+DU1yfwhcSy5Gx6B69GJKwtv3vaLu957M6T2gDf5FHDKcgTnpcKB76I/Z+UegapF2NiQIUBu1eB8gZkZb2hqdHQy+zpvUMBrDBjqqnBcN4ixv3f4I6EREdubNWifWiY0BO2VN3VSfW2NBvE8fKB3yuD0= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0885.namprd21.prod.outlook.com (52.132.132.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:26:45 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:26:45 +0000 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 Thread-Topic: [PATCH AUTOSEL for 4.9 026/293] crypto: omap-sham - fix closing of hash with separate finalize call Thread-Index: AQHTz5jwHNF0TLyyJ0qIfAUx/Jy8QA== 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> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0885;7:x3wgahrVB0ra+VQqysCGY+CmMEb95m0ld6ptfWJAUwoNKysz76gQxSzEuKu5/xcuQcdD+NRWvY6Y7xXsgpwM2z2K29OU/Dsd40+668TVZsPwdBJJPbopFSSNgJSDMupeBRLzpX86B3CxW3YsRVDwvdLHHkYgKeMf6SOZqtKT6FtaLLn0d4Bx8bZFWlJKJXlVDTZoRAmAqLpRI5PjQAQsZWoDpmrJiah1pkFeD0RO4vwJQ2NIAMOunXJiq16SFSU1;20:zuhg0716TuurbUrypm+ojo/7PY+gHVBSb1aDS/T9kMJ179nOB5HRVflx6yUUiCSqpUHq3Nhq6/cJsnfScHda6FaGbb2NinhaoHu3zq3Pu7GF1TP8RnqOD+RQckRAMmZr34UxiJetkwIGCD6fcxhTOY3fSEqY9Bu9P39PM8pDCHA= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 274f06d6-1d4d-44a0-3128-08d59db09312 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0885; x-ms-traffictypediagnostic: DM5PR2101MB0885: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(31051911155226)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB0885;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0885; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39860400002)(366004)(346002)(376002)(396003)(39380400002)(189003)(199004)(2906002)(68736007)(22452003)(316002)(6512007)(5660300001)(6666003)(54906003)(110136005)(486006)(6486002)(102836004)(36756003)(14454004)(99286004)(86612001)(105586002)(72206003)(106356001)(2900100001)(1076002)(97736004)(10090500001)(3280700002)(5250100002)(6436002)(3660700001)(6116002)(575784001)(3846002)(305945005)(86362001)(59450400001)(66066001)(10290500003)(186003)(81166006)(8936002)(478600001)(476003)(25786009)(81156014)(8676002)(4326008)(7736002)(2501003)(107886003)(6506007)(2616005)(26005)(76176011)(446003)(53936002)(11346002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0885;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: w3GfjUUBnG07u5cqjbakcJMeWYmmtlISYnu8Sur0DAHPted7tNpHZ/0A+rC3KJ3zbgLqps/C+SQghdyGKIPtQz4hcZFIakwk9biZJNARzhmJG7mVj/yGd3lsnmvtozXX6H3AQS4TwHPxl6GawVfFkcunGVG0q5+gFoN9jftU3erDMKDOCpAPhAeaTv9PfOn0Ud+DBohMfVdw12IrOjiAdsFW8nrSlHNCfWkS2lCINOqmom5vsnVXLYl2onD+J3DatRRoF/wQqVque/YvxwWlY6cPnFQv4AyGZE5hcEpIMlyI8rq0Bht84YY+ss/OAj+hCcCQKJ309UunLR8j7xKXIsZni0ujDQF/j4ht3EREkfW3oNoBCHm7+1kFgD4vrIRAMenhhLHFMzsP6oJObrb+kIviNXqELSiIGM48U2XSeAE= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 274f06d6-1d4d-44a0-3128-08d59db09312 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:23:10.4248 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0885 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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