From patchwork Mon Apr 9 00:23:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 132982 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp729161ljb; Sun, 8 Apr 2018 19:44:16 -0700 (PDT) X-Google-Smtp-Source: AIpwx48weIsy+TTA5i36HYvVMCE1syk/8Qy0a+nfzeKvr1+Q9aZ8Y016/DuCmfqk7cQDI1hEtIRB X-Received: by 10.98.13.71 with SMTP id v68mr27758205pfi.69.1523241856342; Sun, 08 Apr 2018 19:44:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523241856; cv=none; d=google.com; s=arc-20160816; b=TvF3Cn182edqa+s5YpK9lD2sxbDBoyqBuQLipn1HblFoclbuj/7SXq+CIh/4TUz0Ob pobCYkRymy4VbRdmWS0cbZUTbJXiCnTe+ticEzi8ieUvvIBE/ex9gXaNRquGb6UYMP0i OVBvb1Nxt6aHOWH1ioJUYUx7HVp2jQ5GPEHymL9XYw+rZ+mbp/4ovYQWWBzxbl1H/RHT 7s3d2A4TROaX4TvjJFONg+i0frVgS3hsAD7RUliS91fgkpeyLdSOujWmofma/+ytYAXY PLhDyFs9+kdrap/lBv6sToHNP+nmpXp+CnnISBt1fi4VA2H0xk2knkl/yqPlhAXf8W5f Bz5g== 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=cm2VGSK59fqiO3rhd2hljPFgAG5FW2HpYoodtPO8Hy4=; b=UuEQNvpXQN2jnvBQL8VT5+zs+KtaSCdU8P/fB9ScVn8D+SdoMObXpohbvEYsVNr/Sn bTG0cSy0Mp9TY6zKkiJTRTN/kMkFe0p2KZ844QbhZovAHcImYBUqBjzp/qriw5fRvEp+ nitsT7/DrqYxNRy5B4itUYYV1K5QRF0tx0r6YB3IGwZ1IPvzRpAs+D2U/fmhRrVU7iK5 1tH+SfT6ESC5QL2DzF4/jhcgMNHjlpGX8apD94RvuQvq1MJ+YhU/OSWE/HgDvhF1R0Kl jWMRXf7uUEn3NWxR67Q+br+0t73IbXKJQ92Nfme5CTDDJlz+ZivqqQp4UqR9C70X9Sd0 9Fag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=JisF9y1J; 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 g11si8829862pgs.153.2018.04.08.19.44.16; Sun, 08 Apr 2018 19:44:16 -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=JisF9y1J; 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 S1757786AbeDICnj (ORCPT + 29 others); Sun, 8 Apr 2018 22:43:39 -0400 Received: from mail-by2nam03on0133.outbound.protection.outlook.com ([104.47.42.133]:46250 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755455AbeDIA0v (ORCPT ); Sun, 8 Apr 2018 20:26:51 -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=cm2VGSK59fqiO3rhd2hljPFgAG5FW2HpYoodtPO8Hy4=; b=JisF9y1JkpBGfEpaYn2Qu5i38qlFgrQDU38Ftz17fzlRN2NJO5Pncl450jhy9e/AdJzj1fwrlYz22YeXWKq+GLR/oTaJc8eYz+clSN6Ag8V7lPPPs8dqOauNdoJ++lG1eMVnPKVtKqK2wip2Pb1WO8PQ9dxK78gfvoR8y5ObHr8= 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:44 +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:44 +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 025/293] crypto: omap-sham - buffer handling fixes for hashing later Thread-Topic: [PATCH AUTOSEL for 4.9 025/293] crypto: omap-sham - buffer handling fixes for hashing later Thread-Index: AQHTz5jwgYyJwCMQlUKSWMAh6Nz8Fg== Date: Mon, 9 Apr 2018 00:23:09 +0000 Message-ID: <20180409002239.163177-25-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:PojUVnUikadcwilsq8Vxp249VKmnylLYqG3rDpBpYFLOMVWOQpF3s8cPEP9YQYCpLGcGJDzmUO0U7ObfHwco47sdtpeLBMwpdsZ5rzTlokD2FvxdRyzUfEikf8KElV/2jPMaxVAxAIzegtOLP3BR9gvM86xYnApDovjPAcqMt3P+DoG8gUOlKztiYPnfhUDk0jnag05TVFGzxEBpk0SlcWhsVhBT3M9nl7q4/R9dQ+M9v7faGF1kaJ21OHmsA/Gt; 20:i2gVkq6gVJm0DYopv9ANolAfMBbMm2q8afE8vIU+7XLpNaAWk9GviKcy9PUx7RPOdDBEIP8mPgUS/nA3Cl7JRgA2dOL7He8/sTtl0REH6NkYUP0W9rl6JDDx/zGH0BEwGp23e8m+3tvqc+MF7AcPQHSGbsWh0bO12arNCPZtOmg= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: f86eaa56-554e-45c0-4957-08d59db092a9 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: s2lkvUiFkV3kWDXp+cJ8pzCnuA1RAkoaE2OV6bfgGKxbG+xGBbOZnNBOOGN99c5aXHkAn+ou7xdplalGvvGhkBVKPG9uk2cH0v6nrtXWPPcdzP07Ium17PMH//2Fj13/Clh9LuXelgpGbPOcJhcBRJvu6TG4mUg+Lqiy1nMCqKBbF56ReBsvAN6/dvG0v7aDpcaXpnMsz8Xt6S/BR3kt79Kia1IX6C6RFNTg/HeHe5V1SFEOPTefHH615ZycRPMlwUGhNzh7+Wtwnasu0BwZxDsZ4FpHs6OzPsSz1vNyEAaG0jrvxRblP91KhJVWhYsQBf48Rk3yQYvK2EEpd5UpfvES5RUc8Zpd+DUvV9dmpD0YR8lrtDWwOfFRINO0QhSgaBGqaTQ0e3EqLbEh64x9HvfSUz4DKc9wVdY32LRDH7Q= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: f86eaa56-554e-45c0-4957-08d59db092a9 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:23:09.6123 (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 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.15.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; }