Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1292842ybi; Fri, 2 Aug 2019 12:48:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqw8hbcR6l+vrvzfLBqGcSRTulWw4Ovg2tGtOHX0BZ3VcYiskmC+QI/W9nX/wKtDkHv23RMU X-Received: by 2002:aa7:9531:: with SMTP id c17mr63557771pfp.130.1564775297259; Fri, 02 Aug 2019 12:48:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564775297; cv=none; d=google.com; s=arc-20160816; b=QJq6lflQb5HIS2HCXyhk/CYxRTB1aVYdk81uOEgTIzwFzSAR69o7WPTqci15gfeASl 8Co0rShNpeCK/0eYAzFSpojgC7qFBM+VOd7RKGEIzrU75U9214oymqEf88Jx4U5BeQTR KX0Igt495pulh2fvqAl1HhV+i8gmd1qX2tM3is7ErcVCom6COeYOpBVUmL9fW+fFpfmh Z58MPo4EAgZOfbecigtiMu90YWBRm6uzIZijfG5ayN4MBEZAMmbTtHTOMJNLzUhoSFzS J6HrUu9GUWY5Y+e0EYfTzmz1jEb/ZOXcTzYDiOTsu9Wh+XjCrx2NUpAJCYFk4uOd1dQj H+Mw== 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=OOR+IWv5fDD9p+/kCN/IELDexHZmjE+ZvnYi+6CtqeY=; b=dK1mQxU3yUvnGMOQwqhwxPh2aGE4KXut5EAPjUu76+87rlvIv3mFSfLQymFgzDCx4J e9hC/onOg86FmNtSiinuHKb7gN3opUpWL14RtTCdjWMnosVIfVQsT+NB7oyCp6Wg+eTM A21sI+K2Q5WIzT+3692bKbn54dg2ArPCGWn30p2GYraAAUtTUbrbO1Ii3CaIkiPVFqok BAC/dXSJZUqAIqKYpeiyHQuI/l8aX5odt4zp8VOzH1LqkJ0YocVKJbfUBwdMiKPW2vy4 TDuUpMeKqGJU17C9aHi9PHtzJAIQKjUIae7/YdpsXtRt8Vl5djiRlugq+iXYG3w+4nbR CFVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=T4McB9JZ; 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 h7si41733827pgc.130.2019.08.02.12.48.01; Fri, 02 Aug 2019 12:48:17 -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=T4McB9JZ; 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 S2406543AbfHBKDz (ORCPT + 99 others); Fri, 2 Aug 2019 06:03:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:42262 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391757AbfHBJk7 (ORCPT ); Fri, 2 Aug 2019 05:40:59 -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 5EF492086A; Fri, 2 Aug 2019 09:40:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564738858; bh=Zmwopr/24pAQwUduIhpFzQx5huUTsu1JiX7uxykUQaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T4McB9JZlanVYA6Z3uHY6cU49GlmLFu4+dgF+3KVuj6Rvi6TEOfwstwkz7q7Lw/Wp 7NlxR4HxrClv+f5iR5JQlxcdrG7Tff0Q/Tf1trU1+w/U7M7wP/x0dO+wNtkGmxAk3m Y69Hd0CDwgY7gZtkCJn569YdKllsmkcgNC9h+8UE= 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.9 023/223] crypto: talitos - properly handle split ICV. Date: Fri, 2 Aug 2019 11:34:08 +0200 Message-Id: <20190802092240.536064002@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802092238.692035242@linuxfoundation.org> References: <20190802092238.692035242@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 0b12772c7919..e7864aa494a1 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