Received: by 10.213.65.68 with SMTP id h4csp2120218imn; Sun, 8 Apr 2018 20:12:13 -0700 (PDT) X-Google-Smtp-Source: AIpwx48EDJd+xU0VBGMWVtCZp7cAvwP9/oX89f0MoT2S93+MN4ZwvluqlxUyZw/vstb+2FJtiPxE X-Received: by 2002:a17:902:a501:: with SMTP id s1-v6mr37100493plq.201.1523243533235; Sun, 08 Apr 2018 20:12:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243533; cv=none; d=google.com; s=arc-20160816; b=Nlqu89AX267t4HINUAusKID7ikC4/PvvNmzxeSHWyavMC0nslDa5/kmpDXkvAVT4ma NPAMQCvnxwxKFn8xsik5tpgtOMIc9Wv+dnE6npav8OmSx2hgRcNiPc+ooJH5kC7hosBA qVuo1/CzzBjWOt5eKyoakfstyD2xMufVj3XIsnj9Z57uiAFmw2SCBtx/Y/4eg8wrFUAc 4iRXm7oZsfYesIVJiw7th20dBThKyoXipMld9Qpmi5OsIVRRbQeb7TTv5+iPKiVBioDQ JAMDKfzuDBFdL04HZfu+JV4FoPCCRdz4OOLVUoDD5+ggSkxgTOoAlhp+lBIBnn3l0e/H gJTw== 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 o1-v6si13433106pld.130.2018.04.08.20.11.36; Sun, 08 Apr 2018 20:12:13 -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 S1757732AbeDICnj (ORCPT + 99 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 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: 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(-) 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_req= uest *req, bool update) } =20 if (hash_later) { - if (req->nbytes) { - scatterwalk_map_and_copy(rctx->buffer, req->src, - req->nbytes - hash_later, - hash_later, 0); - } else { + int offset =3D 0; + + if (hash_later > req->nbytes) { memcpy(rctx->buffer, rctx->buffer + xmit_len, - hash_later); + hash_later - req->nbytes); + offset =3D 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 =3D hash_later; } else { rctx->bufcnt =3D 0; @@ -1189,11 +1196,10 @@ static int omap_sham_update(struct ahash_request *r= eq) if (!req->nbytes) return 0; =20 - if (ctx->total + req->nbytes < ctx->buflen) { + if (ctx->bufcnt + req->nbytes <=3D ctx->buflen) { scatterwalk_map_and_copy(ctx->buffer + ctx->bufcnt, req->src, 0, req->nbytes, 0); ctx->bufcnt +=3D req->nbytes; - ctx->total +=3D req->nbytes; return 0; } =20 --=20 2.15.1