From patchwork Mon Nov 16 13:53:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 325486 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 250A4C6369E for ; Mon, 16 Nov 2020 13:55:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E0FCA22280 for ; Mon, 16 Nov 2020 13:55:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="khITfdpV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729771AbgKPNye (ORCPT ); Mon, 16 Nov 2020 08:54:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729770AbgKPNyd (ORCPT ); Mon, 16 Nov 2020 08:54:33 -0500 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C21F3C0613D1 for ; Mon, 16 Nov 2020 05:54:32 -0800 (PST) Received: by mail-pl1-x642.google.com with SMTP id y22so8430444plr.6 for ; Mon, 16 Nov 2020 05:54:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mVzZeX/xHmC7db3jb+d+RTV9mPod+mGCeVwxUA/QzHc=; b=khITfdpV7TkpTI3z7ek6WPFVnE/hkdUS1kE3iVr+zubshbicRf3ouAsQNOcAGmsXFR aZVJP1dw8wraRpfHz05MmqGSK0WgIJnQ/oaLCI9/zHAHO+skG9QQFuDHQcTYmCCsiWRR bkM5pajDBxam1DhN9q6MaPj8L8mUPxWadt5A3M/xtnLXo0byO2upaIcjoTgK5oP60RKu mGR5ZB/HXca1A+3cbn6Y8chlsZtyNx8qgLI7hrBxZyDCg2SPFmDvzg0t537yHMT3EysE RgW3wgZtmZ/ApXOOXn1kTXICBOoL3JK+ZQEWnRgDvBiEh7K0AUAOWzLxD8qJPueWapu1 uj3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mVzZeX/xHmC7db3jb+d+RTV9mPod+mGCeVwxUA/QzHc=; b=s8s6KrNPP758ogdmIBZ96kpquFosD9HxyWkeSeIgjZ9qsT4df0aK5lFcLkDqNmVh6k IOW+DYRXMaskmHKHkbaQyWNVxhfpac//fappbPOWGUMFBmFSpnsAdm3O7w2f5aRoyXBA b4ic7gkPd5Y5i7+Etxdh7W4OxyHqBr+kz9MHz4BDB75bXpBpv/Yy0lCdbWU/CpzfW9ah SWl3YnxiyRNMyCsJ9o3jaVN5te9VpoplplhE4QjrPk9kF+KDOSrrzsETDXCFhfs3/Kpt Fbuo5VphaZz44SaMkTVU/hUorZlcWgFLbEsp5gGQcvU3SjQTArlzZh9YO/fd/h7kfsHa gkxw== X-Gm-Message-State: AOAM532Vd7wcsyvy3XgzIstgGHhE4FvoyjtsMYU7lg3Dwssd8YdAGo5J t+oEldqItWoYoypM9k8Ff4S4lA== X-Google-Smtp-Source: ABdhPJycsJpsHxxQgUQikdHZHQq+B46p3AfeivU5IrTPRF+X2sx8pQsUDBuZgBM8ImvHOT/pMe+oCA== X-Received: by 2002:a17:902:70cc:b029:d7:e8ad:26d4 with SMTP id l12-20020a17090270ccb02900d7e8ad26d4mr13298602plt.33.1605534872355; Mon, 16 Nov 2020 05:54:32 -0800 (PST) Received: from localhost.localdomain ([163.172.76.58]) by smtp.googlemail.com with ESMTPSA id u22sm15864031pgf.24.2020.11.16.05.54.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 05:54:31 -0800 (PST) From: Corentin Labbe To: arnd@arndb.de, davem@davemloft.net, herbert@gondor.apana.org.au, jernej.skrabec@siol.net, mripard@kernel.org, wens@csie.org Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Corentin Labbe , stable@vger.kernel.org Subject: [PATCH v3 3/7] crypto: sun4i-ss: IV register does not work on A10 and A13 Date: Mon, 16 Nov 2020 13:53:41 +0000 Message-Id: <20201116135345.11834-4-clabbe@baylibre.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201116135345.11834-1-clabbe@baylibre.com> References: <20201116135345.11834-1-clabbe@baylibre.com> Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 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 --- .../allwinner/sun4i-ss/sun4i-ss-cipher.c | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c index 4dd736ee5a4d..53478c3feca6 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c @@ -20,6 +20,7 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct skcipher_request *areq) 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; @@ -42,6 +43,13 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct skcipher_request *areq) 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) @@ -102,9 +110,12 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct skcipher_request *areq) } 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); } } @@ -161,6 +172,7 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) unsigned int ileft = areq->cryptlen; unsigned int oleft = areq->cryptlen; unsigned int todo; + void *backup_iv = NULL; struct sg_mapping_iter mi, mo; unsigned int oi, oo; /* offset for in and out */ unsigned int ob = 0; /* offset in buf */ @@ -202,6 +214,13 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) if (need_fallback) return sun4i_ss_cipher_poll_fallback(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) @@ -322,9 +341,12 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) } } 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); } } From patchwork Mon Nov 16 13:53:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 325485 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33DE1C64E7A for ; Mon, 16 Nov 2020 13:55:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 04B39222EC for ; Mon, 16 Nov 2020 13:55:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="iblwlVcd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729833AbgKPNys (ORCPT ); Mon, 16 Nov 2020 08:54:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729827AbgKPNys (ORCPT ); Mon, 16 Nov 2020 08:54:48 -0500 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2217C0613D2 for ; Mon, 16 Nov 2020 05:54:47 -0800 (PST) Received: by mail-pf1-x442.google.com with SMTP id c66so14206468pfa.4 for ; Mon, 16 Nov 2020 05:54:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LA6HiyjtrQWg93rXzUxCKFCbWr20SEsMu/GK7GDnTM4=; b=iblwlVcd2lUD/gwKL5jWgNtBU8xtXkfkke8Of+1dHqmGyy37nax0rkrq4lAXptvJVb AXqrTry0jNdofQ+ymr26F5xvtaGj2ALrfbMCnUWvEynp27GBSifY99vEi2dweI6enESU vy36OwiE+cI6m+WwQAamyl1AOUTuLz4liMHynQe16YSSqU+JdC4W2cKigHXBhsY+lJfD df9hu4J1U6K00TDaQluTa930RJUmRhNzpxugl2rmno4CG3ZBTDMbYQWTfAJdDl9Vm86E zQDaMD03Wj8qHlYlgW3jmyS7s2L/bHD9blRaKnd4GVwAh71hLJPRRdAdhXjqbvQRg633 0j2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LA6HiyjtrQWg93rXzUxCKFCbWr20SEsMu/GK7GDnTM4=; b=C0xE59d0DHDxWW/IPPSYVs0mMgb8E4rXbWpwW3JcRQph+1DGl2bXYEDbLg/bigAcAg f7X392WyAQ+LMcPRJqCxRcTFl1IXABsBof4INEWgwXk+a0ShSq8cEk0I1qOJUMVfPmHY gdfMhVBCLGVMgvQ4UKwzaZRx5bwmSjHYMT/pfHWFnr27oYsjo9px3My8R4zUGhpAmHxW 7BpAVE2S9iwpxblARIvjSdhEFEdRg+U31/YG5EyGAIQRl1c8sJT0GJg919VqeSlafA80 IhX6gSXT7BH4TPsytgOH55CDBeKmXrtvhlkWwU6GpKDJP6bOjQRHZko2FqlLHkIEAJKd aEeQ== X-Gm-Message-State: AOAM5307TG8NJrXFW5n7gsVf6nwpgVt4L73AYLLooTut8foZ59QAC/mD cw/cdLnJbhpuRVS7DUNyIiCfww== X-Google-Smtp-Source: ABdhPJxtV8S3t14TtRMP1LjRfXosxCQyIdl5lzyfHOzvv6zyR1P0pO6Y21nlXDj/H4LetTS7oza29Q== X-Received: by 2002:a17:90b:4c0b:: with SMTP id na11mr3329213pjb.0.1605534887618; Mon, 16 Nov 2020 05:54:47 -0800 (PST) Received: from localhost.localdomain ([163.172.76.58]) by smtp.googlemail.com with ESMTPSA id u22sm15864031pgf.24.2020.11.16.05.54.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 05:54:47 -0800 (PST) From: Corentin Labbe To: arnd@arndb.de, davem@davemloft.net, herbert@gondor.apana.org.au, jernej.skrabec@siol.net, mripard@kernel.org, wens@csie.org Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Corentin Labbe , stable@vger.kernel.org Subject: [PATCH v3 5/7] crypto: sun4i-ss: initialize need_fallback Date: Mon, 16 Nov 2020 13:53:43 +0000 Message-Id: <20201116135345.11834-6-clabbe@baylibre.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201116135345.11834-1-clabbe@baylibre.com> References: <20201116135345.11834-1-clabbe@baylibre.com> Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The need_fallback is never initialized and seem to be always true at runtime. So all hardware operations are always bypassed. Fixes: 0ae1f46c55f87 ("crypto: sun4i-ss - fallback when length is not multiple of blocksize") Cc: Signed-off-by: Corentin Labbe --- drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c index 8f4621826330..7f4c97cc9627 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c @@ -179,7 +179,7 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) unsigned int obo = 0; /* offset in bufo*/ unsigned int obl = 0; /* length of data in bufo */ unsigned long flags; - bool need_fallback; + bool need_fallback = false; if (!areq->cryptlen) return 0;