Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp266178yba; Mon, 20 May 2019 08:21:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqxoX97fWBPl3jW1+ohJ8+PcHUS0Zype/0BeQ6T5BZR627d5w/mqRC0YZSRuy4cBpzrb9mzP X-Received: by 2002:aa7:860a:: with SMTP id p10mr63691019pfn.214.1558365693183; Mon, 20 May 2019 08:21:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558365693; cv=none; d=google.com; s=arc-20160816; b=ETPJdg8rMAqzRDPrfB80fYbbqowBE1f+2tncvrgDpMMlJQPSZukgjk2hSHyr3VDiQE hM/YSjT6lYg1bi310Z8jSM1Y1tHBGUwwkFtRcMlG9ggP2ahW/xl7pwtBJ4c6tqlBkKN6 FoAxrjuznnWGjHunxvpwJvJZ1z2QuJ7mmNpCoVICuZb+c8wkTjsyksu34J+Gwb0FkhST 7lV9xv4xfaOmrUCyU8C1EKxIuDFfmfmtTXy3IzDh98tsG/ftKpDKfxT9gG0in8z7+pp7 ABDPE1FeOu9EqByHNsv+r9peD/j+PGVal5wm8XdT4c0W52lSfqCT5dzWGdgeXEgsgSdv olXg== 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=HFiOTadPqxz7CTrDXRcVqVi8RgVgp6287GZkQmc8CBo=; b=JYlnzT8TNslbKDSgtWB/1dyBa0vZ6ZraEb78m1/ss6cw8MMpe8LyY4Ws027j3Vk4xs IbUU0HNz/cwrPMNIgaszjAwVKr2kn2zJI3ut7h+0Uhn0QY8xRRmX2pati72skWZr/zmf sSqmIOUoLtvvvWsywD3fAnGMl+7LxabO9OmCRdyGsyGr3ex4RBtxdupGI8M+gEP9c3pP zyXRQHVxVgXq2aqhhpVK7cEuEFA0Sz5cNx2j4VJd8OY7KigpDpPJNcHhRwlRw+kXkOjG M+toNApQQ73D0BVCzP6pxyEuFC4w1b1aW2d+6Lg0JnRnnWumqPLY4KbExNR12korPmmL oAzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SauNnjPK; 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 1si16334229plp.131.2019.05.20.08.21.18; Mon, 20 May 2019 08:21:33 -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=SauNnjPK; 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 S2388295AbfETMWF (ORCPT + 99 others); Mon, 20 May 2019 08:22:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:35964 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388337AbfETMWC (ORCPT ); Mon, 20 May 2019 08:22:02 -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 4B436214DA; Mon, 20 May 2019 12:22:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558354921; bh=W6/X+FsS7lgY0ci9ipL3DN72hdu/rw1yHfoWA9Ns1Uk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SauNnjPK+ecHD/xXeECkjV8ViETQDdgpOWflvPX98Y9e0Sgor2Cvp6zjMW4AF0CEq +RcpBbVYN9y7NFMY+bdcPIvYbF8hjH/WfouWhSY3RUGIqzymjPaSWzQ1YVZYGGqO3H wrrX0EamnD63w4kyl/WCzwVLzacFJHOH9c8SrImc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Biggers , Zhang Zhijie , Herbert Xu Subject: [PATCH 4.19 029/105] crypto: rockchip - update IV buffer to contain the next IV Date: Mon, 20 May 2019 14:13:35 +0200 Message-Id: <20190520115249.055680286@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115247.060821231@linuxfoundation.org> References: <20190520115247.060821231@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 From: Zhang Zhijie commit f0cfd57b43fec65761ca61d3892b983a71515f23 upstream. The Kernel Crypto API request output the next IV data to IV buffer for CBC implementation. So the last block data of ciphertext should be copid into assigned IV buffer. Reported-by: Eric Biggers Fixes: 433cd2c617bf ("crypto: rockchip - add crypto driver for rk3288") Cc: # v4.5+ Signed-off-by: Zhang Zhijie Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c | 25 +++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) --- a/drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c +++ b/drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c @@ -250,9 +250,14 @@ static int rk_set_data_start(struct rk_c u8 *src_last_blk = page_address(sg_page(dev->sg_src)) + dev->sg_src->offset + dev->sg_src->length - ivsize; - /* store the iv that need to be updated in chain mode */ - if (ctx->mode & RK_CRYPTO_DEC) + /* Store the iv that need to be updated in chain mode. + * And update the IV buffer to contain the next IV for decryption mode. + */ + if (ctx->mode & RK_CRYPTO_DEC) { memcpy(ctx->iv, src_last_blk, ivsize); + sg_pcopy_to_buffer(dev->first, dev->src_nents, req->info, + ivsize, dev->total - ivsize); + } err = dev->load_data(dev, dev->sg_src, dev->sg_dst); if (!err) @@ -288,13 +293,19 @@ static void rk_iv_copyback(struct rk_cry struct ablkcipher_request *req = ablkcipher_request_cast(dev->async_req); struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req); + struct rk_cipher_ctx *ctx = crypto_ablkcipher_ctx(tfm); u32 ivsize = crypto_ablkcipher_ivsize(tfm); - if (ivsize == DES_BLOCK_SIZE) - memcpy_fromio(req->info, dev->reg + RK_CRYPTO_TDES_IV_0, - ivsize); - else if (ivsize == AES_BLOCK_SIZE) - memcpy_fromio(req->info, dev->reg + RK_CRYPTO_AES_IV_0, ivsize); + /* Update the IV buffer to contain the next IV for encryption mode. */ + if (!(ctx->mode & RK_CRYPTO_DEC)) { + if (dev->aligned) { + memcpy(req->info, sg_virt(dev->sg_dst) + + dev->sg_dst->length - ivsize, ivsize); + } else { + memcpy(req->info, dev->addr_vir + + dev->count - ivsize, ivsize); + } + } } static void rk_update_iv(struct rk_crypto_info *dev)