From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 288ECEB64DA for ; Wed, 19 Jul 2023 08:30:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=14+3+Lumfl9xTQRcR+lDukSdE6dmCTpSp9tK1KMyL2g=; b=mfuAEztb0zX/Jl nmkvJaQZgEPR/x8yKeOn0d7/E+5FiaLtHZUsPqPusLX1ESuObu+2eX32CvlT959xO94ro0I4iHLht MZFh8rs7wv1CBe1vyNw96lSOimg4J/g+HfPTq0CYq4ALrHTXaXUV4IhBpGgK1IwUH9LCxl9fQkIHw 3qi1YrJKVwO/HEU7CtOG0TxmDmCE5QRaDqG0ktUIUGPNX6HAlI1QgTfAkqa7fjS2ArvHJSWwvIV3U 0ECJqHFS0YABQ7lhhaQ+0cFcryiTvDFeopA+58p+CAmlwHb9TxH3TKOXOUW+p3Yj6hl1tRALWq8ci X5sXibJq95OEY+GscAKQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qM2ZM-006MP4-39; Wed, 19 Jul 2023 08:30:01 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qM2ZL-006MOT-2r for linux-mtd@bombadil.infradead.org; Wed, 19 Jul 2023 08:30:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=Xx+B+/JS5iJKrFtMpTmi7o2r1Iae5mMIlVpmo5oMOLE=; b=rJLEcCeNAvUsqaELpDI3HfgX0R 9kP+nYxIuPKtiZrCsmTmxUoGQa0c6A14rzEWFro8aa8fJFgnD5LikFRANGnl9hPbf+UWS7zowhaIg ziKY6wFeOfMXodbnkX5Jmz3MRmsAcQp0KObfrT2QMXMmPsFaweLzxTFei5N9gpLSMr4fmDZAqLfMv 6I2BIaw6gKaKT1c6LsWwlPVXKFk9QaDvHwSlVz3/5ciVYOhSfgBSa854vHu6TSDCcGEZ1ELRP0kXS EUUZ9T3vzIDm4eiMLj8AB0X94c52waqsM46uyppzDpxHrWUuux5398EaCMP5dR7iDWiZfWFsPCBkm 8uXOZy2w==; Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLkJN-00BYNi-0P for linux-mtd@lists.infradead.org; Tue, 18 Jul 2023 13:00:21 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9281461524; Tue, 18 Jul 2023 12:59:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9BC7FC433A9; Tue, 18 Jul 2023 12:59:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689685182; bh=WHwz9/IerLZuAMcdxeFxF/xnqkGa8Udt+0cnPybEFbA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XVg1yBawcsOWEcOzZms+CEOR9fHPLE7HVa0+cg/25hWlk3oZGj4hCF9Y5VExy5iZ8 bAV3urUBiTlj231pQbsb8hWkRUHFZMnxwyoVx4IkyvMwwl455KuDE7mhvQ8cC+cjxV 771+ImPUjmwoPJg1jv2AKFNBoPwts+Qam+NJH+0QfHPezWDSB0lM2k4hCWHPhfJXSN PUhBB2ppv3XF1L18IqbGeQqG3medjJxSo6D837YoLznf0mjS2FeozbcJKbUBz0sm23 MGM0LAwfArD9hnsadorqPiFYlUK3skwIMvl8aeYTD/y7t67X33AQ1uTRETr+dseedO lvqIV6V5a7nwQ== From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: Ard Biesheuvel , Herbert Xu , Eric Biggers , Kees Cook , Haren Myneni , Nick Terrell , Minchan Kim , Sergey Senozhatsky , Jens Axboe , Giovanni Cabiddu , Richard Weinberger , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Steffen Klassert , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, qat-linux@intel.com, linuxppc-dev@lists.ozlabs.org, linux-mtd@lists.infradead.org, netdev@vger.kernel.org Subject: [RFC PATCH 03/21] crypto: acompress - Drop destination scatterlist allocation feature Date: Tue, 18 Jul 2023 14:58:29 +0200 Message-Id: <20230718125847.3869700-4-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230718125847.3869700-1-ardb@kernel.org> References: <20230718125847.3869700-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=6259; i=ardb@kernel.org; h=from:subject; bh=WHwz9/IerLZuAMcdxeFxF/xnqkGa8Udt+0cnPybEFbA=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIWVbT4GvRLH/LEkjV81tn2oObnkfxfv3ra95U7VM4jzxV 9sMlr7vKGVhEONgkBVTZBGY/ffdztMTpWqdZ8nCzGFlAhnCwMUpABNxOcnI0JNvE8/+bpmSW14M y44lsq9WHbTVEA5NsljuK5jAfTnOlJFh657yZdMNtxc8ClR4vf+ZnOr6jWGmb+QOJvypXbOvUWE VFwA= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230718_140019_863558_807BB6A3 X-CRM114-Status: GOOD ( 19.72 ) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-mtd" Errors-To: linux-mtd-bounces+linux-mtd=archiver.kernel.org@lists.infradead.org The acomp crypto code will allocate a destination scatterlist and its backing pages on the fly if no destination is passed. This feature is not used, and given that the caller should own this memory, it is far better if the caller allocates it. This is especially true for decompression, where the output size is essentially unbounded, and so the caller already needs to provide the size for this feature to work reliably. Signed-off-by: Ard Biesheuvel --- crypto/acompress.c | 6 ---- crypto/scompress.c | 14 +--------- crypto/testmgr.c | 29 -------------------- include/crypto/acompress.h | 16 ++--------- 4 files changed, 4 insertions(+), 61 deletions(-) diff --git a/crypto/acompress.c b/crypto/acompress.c index 1c682810a484dcdf..431876b0ee2096fd 100644 --- a/crypto/acompress.c +++ b/crypto/acompress.c @@ -71,7 +71,6 @@ static int crypto_acomp_init_tfm(struct crypto_tfm *tfm) acomp->compress = alg->compress; acomp->decompress = alg->decompress; - acomp->dst_free = alg->dst_free; acomp->reqsize = alg->reqsize; if (alg->exit) @@ -173,11 +172,6 @@ void acomp_request_free(struct acomp_req *req) if (tfm->__crt_alg->cra_type != &crypto_acomp_type) crypto_acomp_scomp_free_ctx(req); - if (req->flags & CRYPTO_ACOMP_ALLOC_OUTPUT) { - acomp->dst_free(req->dst); - req->dst = NULL; - } - __acomp_request_free(req); } EXPORT_SYMBOL_GPL(acomp_request_free); diff --git a/crypto/scompress.c b/crypto/scompress.c index 442a82c9de7def1f..3155cdce9116e092 100644 --- a/crypto/scompress.c +++ b/crypto/scompress.c @@ -122,12 +122,9 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir) if (!req->src || !req->slen || req->slen > SCOMP_SCRATCH_SIZE) return -EINVAL; - if (req->dst && !req->dlen) + if (!req->dst || !req->dlen || req->dlen > SCOMP_SCRATCH_SIZE) return -EINVAL; - if (!req->dlen || req->dlen > SCOMP_SCRATCH_SIZE) - req->dlen = SCOMP_SCRATCH_SIZE; - scratch = raw_cpu_ptr(&scomp_scratch); spin_lock(&scratch->lock); @@ -139,17 +136,9 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir) ret = crypto_scomp_decompress(scomp, scratch->src, req->slen, scratch->dst, &req->dlen, *ctx); if (!ret) { - if (!req->dst) { - req->dst = sgl_alloc(req->dlen, GFP_ATOMIC, NULL); - if (!req->dst) { - ret = -ENOMEM; - goto out; - } - } scatterwalk_map_and_copy(scratch->dst, req->dst, 0, req->dlen, 1); } -out: spin_unlock(&scratch->lock); return ret; } @@ -197,7 +186,6 @@ int crypto_init_scomp_ops_async(struct crypto_tfm *tfm) crt->compress = scomp_acomp_compress; crt->decompress = scomp_acomp_decompress; - crt->dst_free = sgl_free; crt->reqsize = sizeof(void *); return 0; diff --git a/crypto/testmgr.c b/crypto/testmgr.c index b41a8e8c1d1a1987..4971351f55dbabb9 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -3497,21 +3497,6 @@ static int test_acomp(struct crypto_acomp *tfm, goto out; } -#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS - crypto_init_wait(&wait); - sg_init_one(&src, input_vec, ilen); - acomp_request_set_params(req, &src, NULL, ilen, 0); - - ret = crypto_wait_req(crypto_acomp_compress(req), &wait); - if (ret) { - pr_err("alg: acomp: compression failed on NULL dst buffer test %d for %s: ret=%d\n", - i + 1, algo, -ret); - kfree(input_vec); - acomp_request_free(req); - goto out; - } -#endif - kfree(input_vec); acomp_request_free(req); } @@ -3573,20 +3558,6 @@ static int test_acomp(struct crypto_acomp *tfm, goto out; } -#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS - crypto_init_wait(&wait); - acomp_request_set_params(req, &src, NULL, ilen, 0); - - ret = crypto_wait_req(crypto_acomp_decompress(req), &wait); - if (ret) { - pr_err("alg: acomp: decompression failed on NULL dst buffer test %d for %s: ret=%d\n", - i + 1, algo, -ret); - kfree(input_vec); - acomp_request_free(req); - goto out; - } -#endif - kfree(input_vec); acomp_request_free(req); } diff --git a/include/crypto/acompress.h b/include/crypto/acompress.h index 574cffc90730f5f3..ccb6f3279bc8b32e 100644 --- a/include/crypto/acompress.h +++ b/include/crypto/acompress.h @@ -43,15 +43,12 @@ struct acomp_req { * * @compress: Function performs a compress operation * @decompress: Function performs a de-compress operation - * @dst_free: Frees destination buffer if allocated inside the - * algorithm * @reqsize: Context size for (de)compression requests * @base: Common crypto API algorithm data structure */ struct crypto_acomp { int (*compress)(struct acomp_req *req); int (*decompress)(struct acomp_req *req); - void (*dst_free)(struct scatterlist *dst); unsigned int reqsize; struct crypto_tfm base; }; @@ -222,8 +219,7 @@ static inline void acomp_request_set_callback(struct acomp_req *req, { req->base.complete = cmpl; req->base.data = data; - req->base.flags &= CRYPTO_ACOMP_ALLOC_OUTPUT; - req->base.flags |= flgs & ~CRYPTO_ACOMP_ALLOC_OUTPUT; + req->base.flags = flgs; } /** @@ -233,11 +229,9 @@ static inline void acomp_request_set_callback(struct acomp_req *req, * * @req: asynchronous compress request * @src: pointer to input buffer scatterlist - * @dst: pointer to output buffer scatterlist. If this is NULL, the - * acomp layer will allocate the output memory + * @dst: pointer to output buffer scatterlist * @slen: size of the input buffer - * @dlen: size of the output buffer. If dst is NULL, this can be used by - * the user to specify the maximum amount of memory to allocate + * @dlen: size of the output buffer */ static inline void acomp_request_set_params(struct acomp_req *req, struct scatterlist *src, @@ -249,10 +243,6 @@ static inline void acomp_request_set_params(struct acomp_req *req, req->dst = dst; req->slen = slen; req->dlen = dlen; - - req->flags &= ~CRYPTO_ACOMP_ALLOC_OUTPUT; - if (!req->dst) - req->flags |= CRYPTO_ACOMP_ALLOC_OUTPUT; } static inline struct crypto_istat_compress *comp_get_stat( -- 2.39.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/