From patchwork Mon Mar 19 16:02:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 132065 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp3003363ljb; Mon, 19 Mar 2018 10:47:55 -0700 (PDT) X-Google-Smtp-Source: AG47ELuQYDad1874Me7P+oVh16IWsJ5XLnehPtQBH8g+lWrNy//0oDVqEOEijpO9+vHZqf3gRfHl X-Received: by 10.98.30.66 with SMTP id e63mr10929563pfe.67.1521481675273; Mon, 19 Mar 2018 10:47:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521481675; cv=none; d=google.com; s=arc-20160816; b=VNUWsWPvBxMeSQLnroRoxT/W7g2De92pDdZmVWXYDae5QFImnu+Ph2eb2HBVwwZRBN 3JzrPy72n4u0A/hl+cv8fiw29OMjlHn9Ljmso6A7Q46F3TDlihOLtT+g4ETPpkH4hr/Y f0gL2XsPdj0CYX5z2pEJC4Dlq1eHl8TGy5WRuqLGSrhbeC3aMGbpi2gE1UIZkYlwBgA4 9XOA4iI36DbrlaEFVLVaR0x4AZhjKoyuF+SCkSC4FbNBIIrT6cJ+sYBsZpPQpbqu8L53 N1ZwzEHCbVAJ+uwPNBEZLatM5PRtYB+fZjneuO15tYGTPVhkP3APSYHJIlrruJsu2d7d EwuA== 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=Z+2GT6WaB9Yj4POnOfARkKGX00C/MqydS7IRW2QPR7w=; b=S31yWQ0+y/wtL9xE9AADrIN0LYbQsU18xLAaGg3MNAQLD3YvVw3tzxmQ/+gT/jFECp H4n0rWwBfUADSEzbwuVMEWQXYPV/J2i7WWMnQc2Ust+JPj3SfSrI2B2FHD0XBcktKTkc Jqkv/FsscqG4N/xe50Vw1c+x7dh8WuYQ4A2fUatno65FjvHc8bHyMFKiQBp+DxvfJEVt brWq2Aa786jAcaiI2Rrm5prIXttU/EhL9PRO1VMVaKLpsqBnoW3+AOPhaEzCE4U5JCNH MS4gPTllof3zus34P5JlvwnqUNYc/4QN0LyG2q070Dn4VWkfngNP+Yj6O8GN59UUxzjO nhjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=ls2ld01Y; 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 u12-v6si352776plm.481.2018.03.19.10.47.55; Mon, 19 Mar 2018 10:47:55 -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=ls2ld01Y; 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 S965817AbeCSRrx (ORCPT + 10 others); Mon, 19 Mar 2018 13:47:53 -0400 Received: from mail-co1nam03on0101.outbound.protection.outlook.com ([104.47.40.101]:45241 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965768AbeCSQFK (ORCPT ); Mon, 19 Mar 2018 12:05:10 -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=Z+2GT6WaB9Yj4POnOfARkKGX00C/MqydS7IRW2QPR7w=; b=ls2ld01YGWMXJjGDqJCapCEc7RFzZrMvSl/dwEd8iaEr4tYl3W9KGrlABeWBu6RkPmCzZME7yVcZmqg7NUBffoXLbxGThGJctnCwkTHJuNl8svTUVIH+HDgru5B5m1mxf/g1kKyTzdWI+wE3Z5TJRE+uJxHn6ctiRUuPXv6s1D4= 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:55 +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:55 +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 239/281] crypto: omap-sham - buffer handling fixes for hashing later Thread-Topic: [PATCH AUTOSEL for 4.9 239/281] crypto: omap-sham - buffer handling fixes for hashing later Thread-Index: AQHTv5uz5Gz/MZzJkUqCXrLsexWXDQ== Date: Mon, 19 Mar 2018 16:02:37 +0000 Message-ID: <20180319155742.13731-239-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:x3mj9eLmWHygruWQycxQIU13FDgI3bNjrAARePaPCt1om2NbJivngs299DwEw1WrTLVDoZm5bA3Tw1jEUv8TvMl1NXwjGrKMQvtmuEGhYi2BtDtLlhLdAOfUblm/i20y/87EWCevwYs/393RNDfIxIimQHI303M0yj5MYFgCtbw9HD+CVeB89MhLpNGpiMXAo4dEpFtFrIXnqru1K/gQuRpxAbkucvMclJz1EfCQeJJLaYczY8TFI7dD541vOdQV; 20:n+3mzT1PkUva8HClG5U5bVq7WtXaR2f9uI8JWaMFGwwPgW9LAZ5HMZgSUFjVdcwsexKnTZwz9Bjv/eQLfKeMK3cQQwtU5thbBZ5Wlbt8etLe5oFZ0hIbv6AoC+IZU9rUxwasfEuw7pNOhma998K1/Ps86CUmMvpgZ9n1axcwlnQ= x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 82bfe8c5-b08f-4f5a-c5d8-08d58db32843 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: SQdXqmPKFmqLsBfv74nQSXn5UdQgudcey8PbfmzkNVaJ9EKXE1w6aScxBlQrCVk4KUtk9J0qg6Dz2NExHo9Ek6X3PzKttpvcNwF2g7CzlzKY58exu5mXecS5ysVLQpnFkDtdbr6MAhQMLAnMs4e3Yr3f02ypkcv3IgpfQdCCPOexd3HdhIwd0jbaPJq0+p5tN8VoDC1rrDEuBPXaaM5E+9Rh7FWNgx7hvGyF8tFwK9ZbtbwLVl7mbX5c1XvCAR3TazUwfqeV/l8EHZQBF4Hv2WmwWBPTwl07jyrsrHpsd5vriC0iriYfAv+7BdnRNTUjadMPFStRsUzlo16NAzxLjA== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 82bfe8c5-b08f-4f5a-c5d8-08d58db32843 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Mar 2018 16:02:37.2515 (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 5d78d57ede8f9e7f656c610ed25be7be337e0529 ] Currently, the hash later code only handles the cases when we have either new data coming in with the request or old data in the buffer, but not the combination when we have both. Fix this by changing the ordering of the code a bit and handling both cases properly simultaneously if needed. Also, fix an issue with omap_sham_update that surfaces with this fix, so that the code checks the bufcnt instead of total data amount against buffer length to avoid any buffer overflows. Signed-off-by: Tero Kristo Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- drivers/crypto/omap-sham.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) -- 2.14.1 diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c index d0b16e5e4ee5..c65b49baf0c7 100644 --- a/drivers/crypto/omap-sham.c +++ b/drivers/crypto/omap-sham.c @@ -873,14 +873,21 @@ static int omap_sham_prepare_request(struct ahash_request *req, bool update) } if (hash_later) { - if (req->nbytes) { - scatterwalk_map_and_copy(rctx->buffer, req->src, - req->nbytes - hash_later, - hash_later, 0); - } else { + int offset = 0; + + if (hash_later > req->nbytes) { memcpy(rctx->buffer, rctx->buffer + xmit_len, - hash_later); + hash_later - req->nbytes); + offset = hash_later - req->nbytes; } + + if (req->nbytes) { + scatterwalk_map_and_copy(rctx->buffer + offset, + req->src, + offset + req->nbytes - + hash_later, hash_later, 0); + } + rctx->bufcnt = hash_later; } else { rctx->bufcnt = 0; @@ -1189,11 +1196,10 @@ static int omap_sham_update(struct ahash_request *req) if (!req->nbytes) return 0; - if (ctx->total + req->nbytes < ctx->buflen) { + if (ctx->bufcnt + req->nbytes <= ctx->buflen) { scatterwalk_map_and_copy(ctx->buffer + ctx->bufcnt, req->src, 0, req->nbytes, 0); ctx->bufcnt += req->nbytes; - ctx->total += req->nbytes; return 0; }