Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5619617pxb; Wed, 26 Jan 2022 16:43:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJw2AchpZPiU62e+as14FTvfiUnY3NAFUpfXj1lKCCb5OHSgiaKpVp6lYySqCUHNkrK7R4ek X-Received: by 2002:a17:90a:e7c8:: with SMTP id kb8mr1559175pjb.228.1643244184576; Wed, 26 Jan 2022 16:43:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643244184; cv=none; d=google.com; s=arc-20160816; b=bqRKSITYEuHNTMAkVq7KeiXfvJudCty3voyDcVwpOciq3T9+VivCm204fiBrwe4EhQ Q4xzEKtytpWMVdo4u6gySTzkn3ANCmyiOhE+FRjW+jSruXeI9m+cCWCocn2uhbgBkvJ/ hdtmtLoFI2KOeT3rEdbziDheJs7ZgDSBjyPUlL0u3Z8orsvMvRqmfU/S3Ofj1NZpbAC/ M+jomFpMMeT/Fq3VPmjer0K28qx+VhVCOmsOWbYFtCkGAieKDLROyhec1R0e//DfiQ5r CmBdxNY16qkSZBpAkdThrpH9cfAnK/6cEPtseJwneMgZHmV5Qn1mNhf9xlr9+GTqjknQ spKQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uQfQxPxFJ18OHZiKr+H6x2uvjjAUEJks7M+mZV0XyDU=; b=Dvow8DFg3D1feW7cFNqejjVHJXwNm0zmDsREZP9V+3HOKs3UmyPzCZoPFigXn2+IgY Tl/3vAf2MlqJx/NpkV9+J95HxnGmN1GCTxFcAOoSCooqghDhdsV4LPX6bAR8eVxAAy/F pXv918925HwCqFE3Ms0ECUUDOIrvcO0V62zQ67Nhwg0cmC0Ks60LaV6PVEPzR3gHAoXB ZUikq/QgMlS3InisBFEAMva6X9PpJSHqmjlnr1MTTVHE7KhSy6Ej9mCy9YgdYfESxOP7 gnn1Xzec69RmISGR6nOyUFWZsNdeZip9Pqt3Z/6zipU7hplAFrXMIVy9crXg9iKbNMZL g7pQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=gI5EvP3V; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q16si847105pgk.830.2022.01.26.16.42.47; Wed, 26 Jan 2022 16:43:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-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=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=gI5EvP3V; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231757AbiAZVE5 (ORCPT + 99 others); Wed, 26 Jan 2022 16:04:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231690AbiAZVEx (ORCPT ); Wed, 26 Jan 2022 16:04:53 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7B74C06161C for ; Wed, 26 Jan 2022 13:04:52 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id f202-20020a1c1fd3000000b0034dd403f4fbso628131wmf.1 for ; Wed, 26 Jan 2022 13:04:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uQfQxPxFJ18OHZiKr+H6x2uvjjAUEJks7M+mZV0XyDU=; b=gI5EvP3Vb93EkxWs5/NGdIKIUHXcZ9cD9PdxdQ7AihS1mp1WTtquESrkQ6JOACLki7 b2yp7STxQIt6XVZNAdkqGfgp+Lz/deN30PAjSTkDJl/MSHZLDhnBwPHPjpDB+t1qbsoN /3T5mHPFZmgSIkaDztl2MQfQto871u3/wf28GDMSsqYwmBdYWkQPqzZxA1n7iDQ6BJ2R RAe4PUYx4cn45hZeDcg6MRkKdyCcefKnagdZiyC32zANamTA1ve0rX2BC5g3wBrhqozr aW1epb7TiZPn/6GRVlyA6plsOHzrsfw5rr57aGhyuJWIHNE5hamLD6o5boZpoLi9gxN2 zMNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uQfQxPxFJ18OHZiKr+H6x2uvjjAUEJks7M+mZV0XyDU=; b=itTjbbhfsJHM89R0slqwUnJXwjQW7A6a0o3+2ezYGAjrRDxMl8Io3oiMfy9hb6bAil Wkp3sv9KjcPy4bAvEL4qn0aLi0GT0MxYx6KhSSbGUjA95M/kzOTmxNBXcJJGgUdRooLZ FUhuWgEwXM0+WYRyfyhCM+AVi7qLeM3JGmIs6iV1a+ZJ7KQzOtXG2onJ6KGochYc/reo NyX2F5XPAzU5SVISVBRfMBw3WSymvk3MrPnYGZjf3d0KP4uYHdfyhb0r7Fv80vxeEjaS ixxgyEIeuEEQ1SI8v+Voci8LMjdvFiHmp4hgSYsJuwcPNHPXS1F/3b2l3IhYR+kkFPHG uHWw== X-Gm-Message-State: AOAM532Nw2n6jXwHHOgNlwXxPgtPSQAUSdieQmx8V9DR47+wa/KJrFh9 4+fRLpP68j9ftkSJQ+bFv3IE0g== X-Received: by 2002:a05:600c:1c16:: with SMTP id j22mr480719wms.60.1643231091453; Wed, 26 Jan 2022 13:04:51 -0800 (PST) Received: from localhost.localdomain (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.googlemail.com with ESMTPSA id j19sm4948611wmq.17.2022.01.26.13.04.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 13:04:50 -0800 (PST) From: Corentin Labbe To: davem@davemloft.net, herbert@gondor.apana.org.au, jernej.skrabec@gmail.com, 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@lists.linux.dev, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH 2/8] crypto: sun4i-ss: do not allocate backup IV on requests Date: Wed, 26 Jan 2022 21:04:35 +0000 Message-Id: <20220126210441.3661782-3-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220126210441.3661782-1-clabbe@baylibre.com> References: <20220126210441.3661782-1-clabbe@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Instead of allocate memory on each requests, it is easier to pre-allocate buffer for backup IV. This made error path easier. Signed-off-by: Corentin Labbe --- .../allwinner/sun4i-ss/sun4i-ss-cipher.c | 22 +++++++------------ drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h | 1 + 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c index 8dc2a475c601..a8c784acce13 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c @@ -20,7 +20,6 @@ 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; @@ -47,10 +46,8 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct skcipher_request *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); + scatterwalk_map_and_copy(ctx->backup_iv, areq->src, + areq->cryptlen - ivsize, ivsize, 0); } if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG)) { @@ -133,8 +130,8 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct skcipher_request *areq) if (areq->iv) { if (mode & SS_DECRYPTION) { - memcpy(areq->iv, backup_iv, ivsize); - kfree_sensitive(backup_iv); + memcpy(areq->iv, ctx->backup_iv, ivsize); + memzero_explicit(ctx->backup_iv, ivsize); } else { scatterwalk_map_and_copy(areq->iv, areq->dst, areq->cryptlen - ivsize, ivsize, 0); @@ -198,7 +195,6 @@ 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 long pi = 0, po = 0; /* progress for in and out */ bool miter_err; @@ -242,10 +238,8 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) 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); + scatterwalk_map_and_copy(ctx->backup_iv, areq->src, + areq->cryptlen - ivsize, ivsize, 0); } if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG)) { @@ -382,8 +376,8 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) } if (areq->iv) { if (mode & SS_DECRYPTION) { - memcpy(areq->iv, backup_iv, ivsize); - kfree_sensitive(backup_iv); + memcpy(areq->iv, ctx->backup_iv, ivsize); + memzero_explicit(ctx->backup_iv, ivsize); } else { scatterwalk_map_and_copy(areq->iv, areq->dst, areq->cryptlen - ivsize, ivsize, 0); diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h index 0fee6f4e2d90..ba59c7a48825 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h @@ -183,6 +183,7 @@ struct sun4i_tfm_ctx { struct sun4i_cipher_req_ctx { u32 mode; + u8 backup_iv[AES_BLOCK_SIZE]; struct skcipher_request fallback_req; // keep at the end }; -- 2.34.1