Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9964680ybi; Wed, 24 Jul 2019 13:10:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqw7UQ9bnBV3BscD4jyo6IogdMo08GwSZ00F/V7MUGLSHpx36dzz51+VbX3MyF9UoeNoYkww X-Received: by 2002:a62:5c3:: with SMTP id 186mr13011823pff.144.1563999007349; Wed, 24 Jul 2019 13:10:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563999007; cv=none; d=google.com; s=arc-20160816; b=VTzV41yaPFuUT5M0pmIkJq1cu14cLz179RlNyS9NTOl7NflFBzQLjtz5ZGpwJmYutL S4p7A+e1LvkXRHao1A4ArcWqG3wZAPctsLKoALH5cANBSl3Jk3WUiEJ1aNfAikCXs65w +2grFmZK1P8n24R/ozAXO+BMVi++LgvBQvDbjUsMJCDQ3nNmLIlafgNSv9LPV56/jl1k 3F0enItlNLXa8Bna8kXDWFRCMkWfv3m1JCOXNg5dI6QuEPzhUmYlcrFf6Xssu1R7PA1b YNBaYH7CCf4p4bbnIzHJgIX1ovma/wg92kSchp+VjcSgupOwD0NJ3ujUpW0DYfYbPKER Ll3A== 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=wrrCV036zeVcl9V6KwYb/LxENFEKlK2fJZW/xOrdxwM=; b=07wR6YNWj82bf9cnGnYFTKJR09VONJKGRUHtnycfsIQu4b/VSN4KUy/1r/kGSgbjBe /AU6SCJxUfX81V11Frwr1QhhKi8sHBh9YcdJUL43ICqJ05+EC2XKMRUAYJloHQmnmAZ9 edlDRuvRcw63+7e2SkWhch9yG6Q/wuEXLSnIB3kyV4IMavlmdfrwCCGmlQt3Kn8YGDDv t9cPeA1Tq6j8gxGm2wzUDcKU5zWB+HCDyYHB7QLdtp0/ZiffitQRisyFx7z1IfLXT4pA KtiSNI/R9kWGSMj/9DGMXrr9oqi8uEyDbkly2XI9mJ08077lVokrvsPopP0kviDM1OLb qZtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="c5vM/IgG"; 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 b5si3992869pgc.396.2019.07.24.13.09.53; Wed, 24 Jul 2019 13:10:07 -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="c5vM/IgG"; 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 S2405569AbfGXUCq (ORCPT + 99 others); Wed, 24 Jul 2019 16:02:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:52678 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405556AbfGXUCm (ORCPT ); Wed, 24 Jul 2019 16:02:42 -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 5921120665; Wed, 24 Jul 2019 20:02:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563998561; bh=PVC0wf0JlH0t0MfT4sWdR8zu+au9l5HG6PIaSqV0i/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c5vM/IgGUldGyFHB1KbWctg9+5WvVH00pLoA3us+CGgJDoBqxjP4pPEmyN14YB2EH hdqhBFc5s99VPmR2ObZQ7ds7VUpq+pJDmYyDedIVaEo9F3R8JKxk8+f6nJxDl/9YCM pPM4RRPtgpF3VPZ3/qlXD57Yphp1B1SSFxmvFEpc= 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.19 035/271] crypto: talitos - properly handle split ICV. Date: Wed, 24 Jul 2019 21:18:24 +0200 Message-Id: <20190724191658.202538101@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191655.268628197@linuxfoundation.org> References: <20190724191655.268628197@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 d46f58c13433..254f711f1934 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c @@ -1001,7 +1001,6 @@ static void ipsec_esp_encrypt_done(struct device *dev, unsigned int authsize = crypto_aead_authsize(authenc); unsigned int ivsize = crypto_aead_ivsize(authenc); struct talitos_edesc *edesc; - struct scatterlist *sg; void *icvdata; edesc = container_of(desc, struct talitos_edesc, desc); @@ -1015,9 +1014,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); } dma_unmap_single(dev, edesc->iv_dma, ivsize, DMA_TO_DEVICE); @@ -1035,7 +1033,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); @@ -1045,9 +1042,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) @@ -1463,7 +1469,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; @@ -1497,9 +1502,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