Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3782709ybi; Mon, 29 Jul 2019 12:31:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqxnJV44hNllKEq6eH1VCxIJoeonpgDZduw9Ps1lyt0FA2pxTo5+0wrUWt7U5mucnzZVfcu5 X-Received: by 2002:a17:90a:25c8:: with SMTP id k66mr114097881pje.129.1564428719149; Mon, 29 Jul 2019 12:31:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564428719; cv=none; d=google.com; s=arc-20160816; b=r6KdorkHiZ/HKRLxYY0gM+gEtwzh3KR1rEo1j3DwLR7oAcEb3iaqjURDbpnfHcz1Vp +HjzdHLq+LdusztVWMa6VHGt01pezZE0xwEu8MDG0Xh5NtYhg8Zr1nkwcgS+XQ2t0r8j vHLoU2Qs24AeKTLAAHFKunNHE3xqyUGI2SqBs1DQIw08vJI0lvO9fdgGq25U/8cdEamN mwzsEf6j2lvdQ3SnjhkffXLWhaQ9bsvgp+CbkdEx6+j7KIjL86RXYLday/muW1Kn5qmU Q73B7+/aDJ5qbbhVg/BQxFpN1gCdtBFnmqHGeI/3BW8JivC22tHyACro2E9Q980aH63Z LuBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gT1gs5Nej0ag8zZjwTHVyKx+0l68j53ECi5YPS7aNDk=; b=qLW0jVBzCCUegAnPDDVkjINkuF5NsTATmrf3Riexcd45GDVvieikz8ZQqaye7hvRK+ GA4I4e4Dr5OhLEJzUlkjPVx00xeEMgTK9+nuFmpHldOPDEM5U5bMPyMEcr2COWGsE4S0 SogRHjT4hpEvcWGAHn7kfD586b1OgNrzgvBQVJIhuu3RAv7vDCqJ28gRcHLjirszFcQ5 +GbxTJT+CAJaQzDwkvDWVqf2gI6TCT/55rLeQpjksWh+prB1owk64ofritDZJ1hDFk29 LF4BBYqRNDcspboBomZviIpjM8mCjOyTfc4+0Qk6kdHJF3iN6YfSlNzpgV3dAcXMw/9K ji3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XzmeCWlh; 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 c1si26197980pgw.444.2019.07.29.12.31.44; Mon, 29 Jul 2019 12:31:59 -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=@kernel.org header.s=default header.b=XzmeCWlh; 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 S2388153AbfG2TYu (ORCPT + 99 others); Mon, 29 Jul 2019 15:24:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:37016 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388022AbfG2TYq (ORCPT ); Mon, 29 Jul 2019 15:24:46 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id ADEE221773; Mon, 29 Jul 2019 19:24:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564428285; bh=DoTqwVFTyAxASKtJGnOTzi4ztiwCJuSpxgeUHydExzc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XzmeCWlhAANeS96C9fjhdWZkfafTMsMoOgzGfoYpi2NPhUIN06Zwe7RktI+7VEpFu FFOeqirAV6QMnEFOp/GLW8a8SjIvl2F0SikiqQkWgAUQ+15P+wQuOcyJDwafZXG/aO u7iULbJK/wWcbIiLGxf5QXsIL72Vnig3vjEWbyTU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christophe Leroy , Herbert Xu , Sasha Levin Subject: [PATCH 4.14 028/293] crypto: talitos - properly handle split ICV. Date: Mon, 29 Jul 2019 21:18:39 +0200 Message-Id: <20190729190823.840328555@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190820.321094988@linuxfoundation.org> References: <20190729190820.321094988@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit eae55a586c3c8b50982bad3c3426e9c9dd7a0075 ] The driver assumes that the ICV is as a single piece in the last element of the scatterlist. This assumption is wrong. This patch ensures that the ICV is properly handled regardless of the scatterlist layout. Fixes: 9c4a79653b35 ("crypto: talitos - Freescale integrated security engine (SEC) driver") Signed-off-by: Christophe Leroy Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- drivers/crypto/talitos.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index 8707607039d3..62dca638105d 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c @@ -984,7 +984,6 @@ static void ipsec_esp_encrypt_done(struct device *dev, struct crypto_aead *authenc = crypto_aead_reqtfm(areq); unsigned int authsize = crypto_aead_authsize(authenc); struct talitos_edesc *edesc; - struct scatterlist *sg; void *icvdata; edesc = container_of(desc, struct talitos_edesc, desc); @@ -998,9 +997,8 @@ static void ipsec_esp_encrypt_done(struct device *dev, else icvdata = &edesc->link_tbl[edesc->src_nents + edesc->dst_nents + 2]; - sg = sg_last(areq->dst, edesc->dst_nents); - memcpy((char *)sg_virt(sg) + sg->length - authsize, - icvdata, authsize); + sg_pcopy_from_buffer(areq->dst, edesc->dst_nents ? : 1, icvdata, + authsize, areq->assoclen + areq->cryptlen); } kfree(edesc); @@ -1016,7 +1014,6 @@ static void ipsec_esp_decrypt_swauth_done(struct device *dev, struct crypto_aead *authenc = crypto_aead_reqtfm(req); unsigned int authsize = crypto_aead_authsize(authenc); struct talitos_edesc *edesc; - struct scatterlist *sg; char *oicv, *icv; struct talitos_private *priv = dev_get_drvdata(dev); bool is_sec1 = has_ftr_sec1(priv); @@ -1026,9 +1023,18 @@ static void ipsec_esp_decrypt_swauth_done(struct device *dev, ipsec_esp_unmap(dev, edesc, req); if (!err) { + char icvdata[SHA512_DIGEST_SIZE]; + int nents = edesc->dst_nents ? : 1; + unsigned int len = req->assoclen + req->cryptlen; + /* auth check */ - sg = sg_last(req->dst, edesc->dst_nents ? : 1); - icv = (char *)sg_virt(sg) + sg->length - authsize; + if (nents > 1) { + sg_pcopy_to_buffer(req->dst, nents, icvdata, authsize, + len - authsize); + icv = icvdata; + } else { + icv = (char *)sg_virt(req->dst) + len - authsize; + } if (edesc->dma_len) { if (is_sec1) @@ -1458,7 +1464,6 @@ static int aead_decrypt(struct aead_request *req) struct talitos_ctx *ctx = crypto_aead_ctx(authenc); struct talitos_private *priv = dev_get_drvdata(ctx->dev); struct talitos_edesc *edesc; - struct scatterlist *sg; void *icvdata; req->cryptlen -= authsize; @@ -1493,9 +1498,8 @@ static int aead_decrypt(struct aead_request *req) else icvdata = &edesc->link_tbl[0]; - sg = sg_last(req->src, edesc->src_nents ? : 1); - - memcpy(icvdata, (char *)sg_virt(sg) + sg->length - authsize, authsize); + sg_pcopy_to_buffer(req->src, edesc->src_nents ? : 1, icvdata, authsize, + req->assoclen + req->cryptlen - authsize); return ipsec_esp(edesc, req, ipsec_esp_decrypt_swauth_done); } -- 2.20.1