From patchwork Mon Dec 14 20:02:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 11972885 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=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,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 9D56EC2BB48 for ; Mon, 14 Dec 2020 20:04:30 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3BF6C2076B for ; Mon, 14 Dec 2020 20:04:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3BF6C2076B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=oEiZf9xOx5H6ZmwdIbnoRnOHJ7nSRMsw72adLFHpN0Y=; b=TJl0DX5mtsOIuw18682CnR+5Ub 8mQuztLJY/9d5CA86gc2YJ+K4o+WdIuw9hXPCOpB/iXCQJfF2C70gDcWqvWvh2ew9WqlzLJEVuth1 K9GIDaq+jFOGl0jKuNLAiugCOcPKQp/lqZr2ill0wVk+JNoVBKSWOikMxxfIP1G4ZkyUN8b04NNyV dzw0UMmBsiLSpID9FhGXhZBUrN+XioE3hL4FrWtXdHQOXU2bxSqJZnqh+k/apmrUyyf8Efzv8vwdq jrfK29rOFArIYv7f19gXgLhkaD/0fKEZC3QPYeK43XVxnBEDZ/gGtHp5z9mssuG10GdUMAPPgBhV4 GavUPzgA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kou3g-0007NY-VQ; Mon, 14 Dec 2020 20:03:01 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kou3e-0007Mp-En for linux-arm-kernel@lists.infradead.org; Mon, 14 Dec 2020 20:02:59 +0000 Received: by mail-pg1-x544.google.com with SMTP id v29so13348341pgk.12 for ; Mon, 14 Dec 2020 12:02:58 -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=IcIRwkZ8OZdNHBj5vIxvJw4vzDArIn2JvgviRxGrME0=; b=BxgQm4GOTVDXkX8er1nP7MnoFp1SSFm0fOFDppClgd5e+RfY2YSQO8U4xhDsZydL5y droFoRW+xtGGZFSuvMCLYmX8CUXDRlCQqvnTjQbUliug0cF4rTfHEYnIPQze9c0U0qus tklfphhmK4d0q+PrZmu183Z4Fg+pOj7XuHPJP9HynYRtzL8CLCXyGG5yB9T/OGtTLPjO sIcpoFFAeTtn1pdBu8NOzVT45MXxKguubd/z2WpkQIKwpJYS5stNxIAdadtDCvgD06/Y J/BAt2YVUv31WZakw51Gk24D5Yerypg62C2s3vKJH49JjF97nmlzCyoI28ezisy34xBN EGrQ== 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=IcIRwkZ8OZdNHBj5vIxvJw4vzDArIn2JvgviRxGrME0=; b=kP6tzpC4C/ajUX1iDnvkvgVjs/flkwonmYRzyzU0TmFCvIgOsdZN/4o7w7O8z6aKsQ IhjoObRnhuOQH7adqcZTW8VGP0uROtg0mDIIWkjItByszOBsw3yTbz5fqvt6O6ZWvneM s97UqZAZoAMhryb63nwVI/3i9+MAcOAxdydK22mSH4DYMT0/sEp0toMQeTEth6z1RPn9 Hgl01uygwMD1UD6R39UMiFiCrRxemkZYUV+Z5UZo83V5yV5WnA68nvq5IXIFi9x8bVtN CKSiVHWpEddTeY0b0dUzjjxUd8dRc3D/p2SnsIpzUHi4mGSrpthpehkiRZLoT4ma0gS2 X8RA== X-Gm-Message-State: AOAM5308MeplAKmpvLq7o3zztdyy4q/QNNSMsaMR7RrkyywUsc5qsj0y PGToUMZIDNzK8QLg7h4H0yrQ7A== X-Google-Smtp-Source: ABdhPJwO/V/z0sxQfPRx31wpvQ3CP7pHObiVAuAdG03+4tQ8oJkJX2O9uVVXDk6uzKgWyKip5r4pFQ== X-Received: by 2002:a63:5849:: with SMTP id i9mr25981184pgm.271.1607976176314; Mon, 14 Dec 2020 12:02:56 -0800 (PST) Received: from localhost.localdomain ([163.172.76.58]) by smtp.googlemail.com with ESMTPSA id js9sm22434109pjb.2.2020.12.14.12.02.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Dec 2020 12:02:55 -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 Subject: [PATCH v4 1/8] crypto: sun4i-ss: linearize buffers content must be kept Date: Mon, 14 Dec 2020 20:02:25 +0000 Message-Id: <20201214200232.17357-2-clabbe@baylibre.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201214200232.17357-1-clabbe@baylibre.com> References: <20201214200232.17357-1-clabbe@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201214_150258_609760_D520AE8F X-CRM114-Status: GOOD ( 16.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Corentin Labbe , linux-sunxi@googlegroups.com, linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When running the non-optimized cipher function, SS produce partial random output. This is due to linearize buffers being reseted after each loop. For preserving stack, instead of moving them back to start of function, I move them in sun4i_ss_ctx. Fixes: 8d3bcb9900ca ("crypto: sun4i-ss - reduce stack usage") Signed-off-by: Corentin Labbe --- drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c | 12 ++++-------- drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h | 2 ++ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c index b72de8939497..19f1aa577ed4 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c @@ -233,8 +233,6 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) while (oleft) { if (ileft) { - char buf[4 * SS_RX_MAX];/* buffer for linearize SG src */ - /* * todo is the number of consecutive 4byte word that we * can read from current SG @@ -256,12 +254,12 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) */ todo = min(rx_cnt * 4 - ob, ileft); todo = min_t(size_t, todo, mi.length - oi); - memcpy(buf + ob, mi.addr + oi, todo); + memcpy(ss->buf + ob, mi.addr + oi, todo); ileft -= todo; oi += todo; ob += todo; if (!(ob % 4)) { - writesl(ss->base + SS_RXFIFO, buf, + writesl(ss->base + SS_RXFIFO, ss->buf, ob / 4); ob = 0; } @@ -295,13 +293,11 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) oo = 0; } } else { - char bufo[4 * SS_TX_MAX]; /* buffer for linearize SG dst */ - /* * read obl bytes in bufo, we read at maximum for * emptying the device */ - readsl(ss->base + SS_TXFIFO, bufo, tx_cnt); + readsl(ss->base + SS_TXFIFO, ss->bufo, tx_cnt); obl = tx_cnt * 4; obo = 0; do { @@ -313,7 +309,7 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) */ todo = min_t(size_t, mo.length - oo, obl - obo); - memcpy(mo.addr + oo, bufo + obo, todo); + memcpy(mo.addr + oo, ss->bufo + obo, todo); oleft -= todo; obo += todo; oo += todo; diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h index 5c291e4a6857..c242fccb2ab6 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h @@ -148,6 +148,8 @@ struct sun4i_ss_ctx { struct reset_control *reset; struct device *dev; struct resource *res; + char buf[4 * SS_RX_MAX];/* buffer for linearize SG src */ + char bufo[4 * SS_TX_MAX]; /* buffer for linearize SG dst */ spinlock_t slock; /* control the use of the device */ #ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_PRNG u32 seed[SS_SEED_LEN / BITS_PER_LONG];