Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp412578pxb; Wed, 3 Mar 2021 06:30:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJw/yAjcwyJn9pj3BulpezmFG0mCvSNhqwVykEV7GilLXQIzzNQjQBhnsx1uj3Fd41zKcefE X-Received: by 2002:a17:906:3883:: with SMTP id q3mr25501092ejd.160.1614781855565; Wed, 03 Mar 2021 06:30:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614781855; cv=none; d=google.com; s=arc-20160816; b=PWFGjl8onQNvPdwxoXz4G7BE5EDWRWqgX1wbS4IjACMF6R1GEy/pVepDJ2TKLZsq6s Q2PWN/pNKHLqrmwudX9wE2Ky8muv3PQMYuUBjd+7fqNFdOEAVUzDnvlzGrd0rVdKHB8r /cPtHIs6+FrCWIJSwilwpqdDDsHsbd+WVvl3oikdzwJ3dYPQdWtMTNKhjuxOAJ6XMey7 Yhtl1yG8Y9yxm+TGfRwI4QyB7C0fw6MGNHp9QSpHpP2mh9HW6d5ZtMByuAtnq2jqqpoy gWTQKpuYTK0LIt4dPmfldPZ2QiWQ1VEQ3qDxrBxgRwb1rhJotoi/slpKRSqINAmDnqIQ eqcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=04S8ubD0Mrt+UA46nb6hSFIkpVKBdIDTiMZ80lPwCIk=; b=LEGKdHUNuRxn8z1ldk94RUTKEDEUsm9xuFvO6o5pMP5DZIpjldjoj6GjHdNCaGs/kf +MGTSYcnmJsXjbu6ZiG2uQUXH3u3ZGEwTcxYRa+z9qoWMSJr2Uj6uzU5VeryR8mcU0GV 2cnPYpu5YdXDxIP8sK9t+J8IjDDPTQl7sai1y08GXGij3qfUMfDyNCr0LEAoeeNCyC33 mJmCf0FMUskaiYz2FPQo7/+VRfy/jjSO6a8+7NPxDwZ0DVW8MCyv2f3sCvY8NGtbcS2g 1pW6SM6tJkz4KIez1G0HpKPi9ydv1RkGKUjhVtlpGv+2q/GWox5l9rw46ylR0bepdgvN 2n3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LZa+QYpA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e5si8882638edy.342.2021.03.03.06.30.24; Wed, 03 Mar 2021 06:30:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LZa+QYpA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243513AbhCAVOx (ORCPT + 99 others); Mon, 1 Mar 2021 16:14:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:48318 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237972AbhCARNx (ORCPT ); Mon, 1 Mar 2021 12:13:53 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 61E2B65031; Mon, 1 Mar 2021 16:44:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614617097; bh=gc9ncjPHJsdcGRuKmWxQxwuCfGUSBofBeY/kfl3dsZc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LZa+QYpAs1lObQwaLW1kxiZx0rxqzGYHW6WT/JMq3BaOUhmmZqmUaGora4afmR+xI gnWvH+KNb4l/OeG5m3oQNikfBybP4NctgOvKWDB3OfEz1wko5v1i7hQ2GsZsAmDnxm rqKzugE2scX8hh5mNmxCb8WmDR4a+mphVFW5x3E4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Corentin Labbe , Herbert Xu Subject: [PATCH 4.19 202/247] crypto: sun4i-ss - IV register does not work on A10 and A13 Date: Mon, 1 Mar 2021 17:13:42 +0100 Message-Id: <20210301161041.551649206@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161031.684018251@linuxfoundation.org> References: <20210301161031.684018251@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Corentin Labbe commit b756f1c8fc9d84e3f546d7ffe056c5352f4aab05 upstream. Allwinner A10 and A13 SoC have a version of the SS which produce invalid IV in IVx register. Instead of adding a variant for those, let's convert SS to produce IV directly from data. Fixes: 6298e948215f2 ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator") Cc: Signed-off-by: Corentin Labbe Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/sunxi-ss/sun4i-ss-cipher.c | 34 ++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) --- a/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c +++ b/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c @@ -24,6 +24,7 @@ static int sun4i_ss_opti_poll(struct skc unsigned int ivsize = crypto_skcipher_ivsize(tfm); struct sun4i_cipher_req_ctx *ctx = skcipher_request_ctx(areq); u32 mode = ctx->mode; + void *backup_iv = NULL; /* when activating SS, the default FIFO space is SS_RX_DEFAULT(32) */ u32 rx_cnt = SS_RX_DEFAULT; u32 tx_cnt = 0; @@ -53,6 +54,13 @@ static int sun4i_ss_opti_poll(struct skc return -EINVAL; } + if (areq->iv && ivsize > 0 && mode & SS_DECRYPTION) { + backup_iv = kzalloc(ivsize, GFP_KERNEL); + if (!backup_iv) + return -ENOMEM; + scatterwalk_map_and_copy(backup_iv, areq->src, areq->cryptlen - ivsize, ivsize, 0); + } + spin_lock_irqsave(&ss->slock, flags); for (i = 0; i < op->keylen; i += 4) @@ -126,9 +134,12 @@ static int sun4i_ss_opti_poll(struct skc } while (oleft); if (areq->iv) { - for (i = 0; i < 4 && i < ivsize / 4; i++) { - v = readl(ss->base + SS_IV0 + i * 4); - *(u32 *)(areq->iv + i * 4) = v; + if (mode & SS_DECRYPTION) { + memcpy(areq->iv, backup_iv, ivsize); + kfree_sensitive(backup_iv); + } else { + scatterwalk_map_and_copy(areq->iv, areq->dst, areq->cryptlen - ivsize, + ivsize, 0); } } @@ -160,6 +171,7 @@ static int sun4i_ss_cipher_poll(struct s unsigned int ileft = areq->cryptlen; unsigned int oleft = areq->cryptlen; unsigned int todo; + void *backup_iv = NULL; struct sg_mapping_iter mi, mo; unsigned long pi = 0, po = 0; /* progress for in and out */ bool miter_err; @@ -202,6 +214,13 @@ static int sun4i_ss_cipher_poll(struct s if (no_chunk == 1) return sun4i_ss_opti_poll(areq); + if (areq->iv && ivsize > 0 && mode & SS_DECRYPTION) { + backup_iv = kzalloc(ivsize, GFP_KERNEL); + if (!backup_iv) + return -ENOMEM; + scatterwalk_map_and_copy(backup_iv, areq->src, areq->cryptlen - ivsize, ivsize, 0); + } + spin_lock_irqsave(&ss->slock, flags); for (i = 0; i < op->keylen; i += 4) @@ -330,9 +349,12 @@ static int sun4i_ss_cipher_poll(struct s sg_miter_stop(&mo); } if (areq->iv) { - for (i = 0; i < 4 && i < ivsize / 4; i++) { - v = readl(ss->base + SS_IV0 + i * 4); - *(u32 *)(areq->iv + i * 4) = v; + if (mode & SS_DECRYPTION) { + memcpy(areq->iv, backup_iv, ivsize); + kfree_sensitive(backup_iv); + } else { + scatterwalk_map_and_copy(areq->iv, areq->dst, areq->cryptlen - ivsize, + ivsize, 0); } }