Received: by 10.192.165.156 with SMTP id m28csp1104657imm; Wed, 11 Apr 2018 12:30:10 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/ti89kMccSKAmfkz+P0Unat0Gr3lQOU+rev0JUp3bfa5vz1JHCv7RIrlai5xHVfuvXQy9R X-Received: by 2002:a17:902:5a5:: with SMTP id f34-v6mr6492351plf.288.1523475010304; Wed, 11 Apr 2018 12:30:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523475010; cv=none; d=google.com; s=arc-20160816; b=reRzqDg/KATNoSO1zmx7cS2WZzylGytr3SoAMmScyFvWcbJn2UFjfxrSEI1quDJSdk jNi3z4PQy2aqkdHAfXbcXvUvBIwipKs1kFjRkvFsmetAlumkamJ9F26QKBqcTbEGQiKm YGOulKwGXAlcdvo7z+YpZVH8Dz2KGhydlze7975JNSJOT7HE2BlnUJfa0euFWafHoOyJ l5aLJ+rxYAlQV7BFMKa1hI3kRn5WJIK7OGylezDnmjGLIoGTNGNA3RaBNTPPSNcTsbtK OQ84WWsPdL1QRUvDWCJSL9FPvk1HO8vc4E/Yc90Il0G5d23hW7gZXzRoRCfbXzswUbdy qWDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=0AT+CkXKRhwcZkz3GmxuUTAW/fkak4E9V/Ih65HhNAA=; b=rtuppT0dxsRfZ7ShiSn03rhfdI+kPXiqUsxco+Z/DfaZ98xftbFuD28MYuuIljm3mF YkteEug853Z5nZKEPiOgC1aBgttROZs20pNRtQqZCRgBsV+CSGm4dmW7/L/61nrFb/6H rN/lEVC6VaFmHhfoXhp2IydwdUgQmoH2YDkm350A+JPQIJY/FYVqnoGaVG6XlMSd5Fn/ xZZfSpx6HcP+GfLgZcLbCpWINwqm7Ao4yaATJ/TngiLGI0l9dqG1DIaSnmozsRDwOgfp Xmm3rhVvXCEd5Ibwec3U5ZQ+zTf5hoIiKkZYmlZhQr0xdg/yOi9MML+Nffb3eT8WNN7z VXLw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a33-v6si1637737plc.507.2018.04.11.12.29.33; Wed, 11 Apr 2018 12:30:10 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934654AbeDKTDX (ORCPT + 99 others); Wed, 11 Apr 2018 15:03:23 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:38918 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934625AbeDKTDV (ORCPT ); Wed, 11 Apr 2018 15:03:21 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 8CD9AE42; Wed, 11 Apr 2018 19:03:20 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tero Kristo , Herbert Xu , Sasha Levin Subject: [PATCH 4.9 234/310] crypto: omap-sham - buffer handling fixes for hashing later Date: Wed, 11 Apr 2018 20:36:13 +0200 Message-Id: <20180411183632.576679237@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183622.305902791@linuxfoundation.org> References: <20180411183622.305902791@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/omap-sham.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) --- a/drivers/crypto/omap-sham.c +++ b/drivers/crypto/omap-sham.c @@ -873,14 +873,21 @@ static int omap_sham_prepare_request(str } 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 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; }