From patchwork Mon Mar 19 16:02:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 132047 Delivered-To: patch@linaro.org Received: by 10.80.152.129 with SMTP id j1csp2985491edb; Mon, 19 Mar 2018 09:05:22 -0700 (PDT) X-Google-Smtp-Source: AG47ELuaCQSYT7PJWFv8L9d3q3GFSaErUOlwLIdmQsSMCpfQRlcTp0j4uslmlrl/vohzydasWfuR X-Received: by 2002:a17:902:209:: with SMTP id 9-v6mr12796034plc.403.1521475522209; Mon, 19 Mar 2018 09:05:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521475522; cv=none; d=google.com; s=arc-20160816; b=0jpgtgRomIx/sbx50sNKzVSslkOkhZNB77keLbCBrAEFpFBr6RoVeR4cj9yaxV9PwS b0QN4+uDn0XX24knJ8aUuAsjpIAltnFvxoRzBQDc5yMMf6JApvXR2st5mOHZ8JO2bdr/ 1aak+33zBAR7SgTFPkcCv+lLSo0ZPY4oNtRLGZfg7/e7XpEVHh/BWSh4hX9gUKqP9zv4 6zXdMZIQGrfqrtaP20+vlaaD13xg6qXPtfC06O4xPjFZ61qwUCr0Z5++tnag9EryRZOu 5aYUUXTt5UH1+HTSdVhSkZpQIedqO4/AewPOgLRp9nryNSgnr8KWya0vuaAQFDg0pxWr uFKg== 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=nUA0lifGzUQktYCG+6wH53n43q2Sfi88StTyB1PX0hs=; b=DG7hHvVDe4McoXJ5iJCiyGmOmdbcuSF9SxHnq3iA9IzM1Xpk0ltvDrZbSUriO4eGHh 6sXIm/sq382bkAKqx/zCvFsB8i2LU72mBYQiyPswr4xZbb+4pyPbVoIdKvvymsygkk3Q cCyKG6wqInocgy8n1WgmzMKXPevN1auPcmQ3EneJDu2RHLliuUusKy4wY20BHu2tB7X/ hfa6P32JAQANlJnM8Sfv/3QyzFfpWO1gKCU0RfPj341aBObImrSmIIjaOGCMJB6iDa3n O8+4BAMHQKeCZ5Vs6kwo0FLlEZhh6x2R5eYLFyE6Nsr46ZETH63d+XjZMYdf6lg0buou LOFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=WWAlvu2F; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 a11si162186pgt.752.2018.03.19.09.05.21; Mon, 19 Mar 2018 09:05:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=WWAlvu2F; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 S965787AbeCSQFS (ORCPT + 10 others); Mon, 19 Mar 2018 12:05:18 -0400 Received: from mail-co1nam03on0134.outbound.protection.outlook.com ([104.47.40.134]:7948 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965782AbeCSQFN (ORCPT ); Mon, 19 Mar 2018 12:05:13 -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=nUA0lifGzUQktYCG+6wH53n43q2Sfi88StTyB1PX0hs=; b=WWAlvu2FW6H6k0hp4F69XN8P7vvfKfkVyXLG2J2tJlt2dGg0WupUOAR69JVinDGkxJ7FDljCc3XJNx+5wtc7JNsrAKeJ+mR4NN/OhYrwKCEH/C1E5Mvru3cV/0CN40NGEElAgeuTIvN9j/UAbtYwMzDy2QaZAP2DPk0GV+sPUqM= 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.631.0; Mon, 19 Mar 2018 16:04:56 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62%5]) with mapi id 15.20.0631.004; Mon, 19 Mar 2018 16:04:56 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Tero Kristo , Herbert Xu , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 240/281] crypto: omap-sham - fix closing of hash with separate finalize call Thread-Topic: [PATCH AUTOSEL for 4.9 240/281] crypto: omap-sham - fix closing of hash with separate finalize call Thread-Index: AQHTv5uzd2Bm/0Bp6UKw6ndd0mAlvQ== Date: Mon, 19 Mar 2018 16:02:38 +0000 Message-ID: <20180319155742.13731-240-alexander.levin@microsoft.com> References: <20180319155742.13731-1-alexander.levin@microsoft.com> In-Reply-To: <20180319155742.13731-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:dhlO8/xIXC8oxlkc6LbCFiDDx1CgywoqAgImJpYp1m2lilRWN5x0PhwTxPj7oAmGBfhJBMzOcTfm87xX7HYr8znjWU7JCfiFO81VP1VhmzYCTDQKH7haGBUfnGL7NDT2So+wo95DmYwYUokN/3PHNaBw7aekAKuxbI36Qmk/cO8zSaKbdGMegynTgOnkrDmUbC+dFf3wfnjEkkamPJBqZI7naDWAN98fPduBR64uPGOx2wiaeTOgxOmZcX8Q16fA; 20:1oArdA190Brs9eftpFnMqJE2H9Og33VPEdixqz1m8U2mt3u4gqYCxNr1fASiwoBn8m/CA3itCHk518tt8IYot1AaqLBgLwpFuk/EPtvrhnhFwgQqnVGfLOCOfjdQzTknL/xks9xQCNR/5rcKGDh6mz08EVBrZDN0QP8Ie1syF9s= x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 27d08a85-12aa-42fa-3479-08d58db3288f 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)(5005006)(8121501046)(3231221)(944501300)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011); SRVR:DM5PR2101MB0885; BCL:0; PCL:0; RULEID:; SRVR:DM5PR2101MB0885; x-forefront-prvs: 06167FAD59 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(366004)(346002)(376002)(39380400002)(39860400002)(396003)(199004)(189003)(6666003)(8936002)(99286004)(3846002)(107886003)(2900100001)(68736007)(14454004)(6512007)(72206003)(81156014)(81166006)(105586002)(4326008)(25786009)(1076002)(22452003)(575784001)(86362001)(110136005)(10090500001)(54906003)(53936002)(316002)(66066001)(6486002)(106356001)(6116002)(6436002)(2950100002)(3660700001)(8676002)(36756003)(97736004)(102836004)(2906002)(305945005)(5250100002)(478600001)(6506007)(59450400001)(7736002)(3280700002)(5660300001)(26005)(86612001)(10290500003)(76176011)(2501003)(186003)(22906009)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:DM5PR2101MB0885; H:DM5PR2101MB1032.namprd21.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: xq/BE76fQFWcpY4NqQnPzMo2GyeRnW6W6N0IV4Fq4Fm1RvRmcTUHsliWDEy8Et210s8z3I3wvUv5LlyOsrHUoqJg5ZjwcMa8vPHteHt8wuMHPPaX69oIDNZ/1TlUigRYQzif3UUaBrL5X18Xbz/36UxNENgK0R/UMC5BU2u0cb/LsganoNj1FcIA+ZX7bdK5PDEdTQ5W/B9qJlyxamrnE+q+vXUW3+tAPzsTk9H4rhx5gsumpLGBQT8s0tXp6miKTGWH5FiHCytccnRfRs5R7Vcp69GnEuZ4ymdjQLi5mjYnVMuMtDxfYCaRZ/xPrvfTSzMkZxQ4h14oES9GOg8I0A== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 27d08a85-12aa-42fa-3479-08d58db3288f X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Mar 2018 16:02:38.3713 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0885 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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(-) -- 2.14.1 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 = DIV_ROUND_UP(new_len, bs) * bs; else - new_len = new_len / bs * bs; + new_len = (new_len - 1) / bs * bs; + + if (nbytes != new_len) + list_ok = false; while (nbytes > 0 && sg_tmp) { n++; @@ -846,6 +849,8 @@ static int omap_sham_prepare_request(struct ahash_request *req, bool update) xmit_len = DIV_ROUND_UP(xmit_len, bs) * bs; else xmit_len = xmit_len / bs * bs; + } else if (!final) { + xmit_len -= bs; } hash_later = rctx->total - xmit_len; @@ -1137,7 +1142,7 @@ static int omap_sham_handle_queue(struct omap_sham_dev *dd, ctx = ahash_request_ctx(req); err = omap_sham_prepare_request(req, ctx->op == OP_UPDATE); - if (err) + if (err || !ctx->total) goto err1; dev_dbg(dd->dev, "handling new req, op: %lu, nbytes: %d\n",