stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* FAILED: patch "[PATCH] crypto: acomp - Fix CFI failure due to type punning" failed to apply to 6.16-stable tree
@ 2025-08-21 12:54 gregkh
  2025-08-21 19:21 ` [PATCH 6.16.y 1/2] crypto: zstd - convert to acomp Sasha Levin
  0 siblings, 1 reply; 7+ messages in thread
From: gregkh @ 2025-08-21 12:54 UTC (permalink / raw)
  To: ebiggers, giovanni.cabiddu, herbert; +Cc: stable


The patch below does not apply to the 6.16-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.16.y
git checkout FETCH_HEAD
git cherry-pick -x 962ddc5a7a4b04c007bba0f3e7298cda13c62efd
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2025082113-buddhism-try-6476@gregkh' --subject-prefix 'PATCH 6.16.y' HEAD^..

Possible dependencies:



thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 962ddc5a7a4b04c007bba0f3e7298cda13c62efd Mon Sep 17 00:00:00 2001
From: Eric Biggers <ebiggers@kernel.org>
Date: Tue, 8 Jul 2025 17:59:54 -0700
Subject: [PATCH] crypto: acomp - Fix CFI failure due to type punning

To avoid a crash when control flow integrity is enabled, make the
workspace ("stream") free function use a consistent type, and call it
through a function pointer that has that same type.

Fixes: 42d9f6c77479 ("crypto: acomp - Move scomp stream allocation code into acomp")
Cc: stable@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/crypto/deflate.c b/crypto/deflate.c
index fe8e4ad0fee1..21404515dc77 100644
--- a/crypto/deflate.c
+++ b/crypto/deflate.c
@@ -48,9 +48,14 @@ static void *deflate_alloc_stream(void)
 	return ctx;
 }
 
+static void deflate_free_stream(void *ctx)
+{
+	kvfree(ctx);
+}
+
 static struct crypto_acomp_streams deflate_streams = {
 	.alloc_ctx = deflate_alloc_stream,
-	.cfree_ctx = kvfree,
+	.free_ctx = deflate_free_stream,
 };
 
 static int deflate_compress_one(struct acomp_req *req,
diff --git a/crypto/zstd.c b/crypto/zstd.c
index ebeadc1f3b5f..c2a19cb0879d 100644
--- a/crypto/zstd.c
+++ b/crypto/zstd.c
@@ -54,9 +54,14 @@ static void *zstd_alloc_stream(void)
 	return ctx;
 }
 
+static void zstd_free_stream(void *ctx)
+{
+	kvfree(ctx);
+}
+
 static struct crypto_acomp_streams zstd_streams = {
 	.alloc_ctx = zstd_alloc_stream,
-	.cfree_ctx = kvfree,
+	.free_ctx = zstd_free_stream,
 };
 
 static int zstd_init(struct crypto_acomp *acomp_tfm)
diff --git a/include/crypto/internal/acompress.h b/include/crypto/internal/acompress.h
index ffffd88bbbad..2d97440028ff 100644
--- a/include/crypto/internal/acompress.h
+++ b/include/crypto/internal/acompress.h
@@ -63,10 +63,7 @@ struct crypto_acomp_stream {
 struct crypto_acomp_streams {
 	/* These must come first because of struct scomp_alg. */
 	void *(*alloc_ctx)(void);
-	union {
-		void (*free_ctx)(void *);
-		void (*cfree_ctx)(const void *);
-	};
+	void (*free_ctx)(void *);
 
 	struct crypto_acomp_stream __percpu *streams;
 	struct work_struct stream_work;


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 6.16.y 1/2] crypto: zstd - convert to acomp
  2025-08-21 12:54 FAILED: patch "[PATCH] crypto: acomp - Fix CFI failure due to type punning" failed to apply to 6.16-stable tree gregkh
@ 2025-08-21 19:21 ` Sasha Levin
  2025-08-21 19:21   ` [PATCH 6.16.y 2/2] crypto: acomp - Fix CFI failure due to type punning Sasha Levin
  0 siblings, 1 reply; 7+ messages in thread
From: Sasha Levin @ 2025-08-21 19:21 UTC (permalink / raw)
  To: stable; +Cc: Suman Kumar Chakraborty, Giovanni Cabiddu, Herbert Xu,
	Sasha Levin

From: Suman Kumar Chakraborty <suman.kumar.chakraborty@intel.com>

[ Upstream commit f5ad93ffb54119a8dc5e18f070624d4ead586969 ]

Convert the implementation to a native acomp interface using zstd
streaming APIs, eliminating the need for buffer linearization.

This includes:
   - Removal of the scomp interface in favor of acomp
   - Refactoring of stream allocation, initialization, and handling for
     both compression and decompression using Zstandard streaming APIs
   - Replacement of crypto_register_scomp() with crypto_register_acomp()
     for module registration

Signed-off-by: Suman Kumar Chakraborty <suman.kumar.chakraborty@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Stable-dep-of: 962ddc5a7a4b ("crypto: acomp - Fix CFI failure due to type punning")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 crypto/zstd.c | 352 +++++++++++++++++++++++++++++++++-----------------
 1 file changed, 232 insertions(+), 120 deletions(-)

diff --git a/crypto/zstd.c b/crypto/zstd.c
index 7570e11b4ee6..657e0cf7b952 100644
--- a/crypto/zstd.c
+++ b/crypto/zstd.c
@@ -12,188 +12,300 @@
 #include <linux/net.h>
 #include <linux/vmalloc.h>
 #include <linux/zstd.h>
-#include <crypto/internal/scompress.h>
+#include <crypto/internal/acompress.h>
+#include <crypto/scatterwalk.h>
 
 
-#define ZSTD_DEF_LEVEL	3
+#define ZSTD_DEF_LEVEL		3
+#define ZSTD_MAX_WINDOWLOG	18
+#define ZSTD_MAX_SIZE		BIT(ZSTD_MAX_WINDOWLOG)
 
 struct zstd_ctx {
 	zstd_cctx *cctx;
 	zstd_dctx *dctx;
-	void *cwksp;
-	void *dwksp;
+	size_t wksp_size;
+	zstd_parameters params;
+	u8 wksp[0] __aligned(8);
 };
 
-static zstd_parameters zstd_params(void)
-{
-	return zstd_get_params(ZSTD_DEF_LEVEL, 0);
-}
+static DEFINE_MUTEX(zstd_stream_lock);
 
-static int zstd_comp_init(struct zstd_ctx *ctx)
+static void *zstd_alloc_stream(void)
 {
-	int ret = 0;
-	const zstd_parameters params = zstd_params();
-	const size_t wksp_size = zstd_cctx_workspace_bound(&params.cParams);
+	zstd_parameters params;
+	struct zstd_ctx *ctx;
+	size_t wksp_size;
 
-	ctx->cwksp = vzalloc(wksp_size);
-	if (!ctx->cwksp) {
-		ret = -ENOMEM;
-		goto out;
-	}
+	params = zstd_get_params(ZSTD_DEF_LEVEL, ZSTD_MAX_SIZE);
 
-	ctx->cctx = zstd_init_cctx(ctx->cwksp, wksp_size);
-	if (!ctx->cctx) {
-		ret = -EINVAL;
-		goto out_free;
-	}
-out:
-	return ret;
-out_free:
-	vfree(ctx->cwksp);
-	goto out;
+	wksp_size = max_t(size_t,
+			  zstd_cstream_workspace_bound(&params.cParams),
+			  zstd_dstream_workspace_bound(ZSTD_MAX_SIZE));
+	if (!wksp_size)
+		return ERR_PTR(-EINVAL);
+
+	ctx = kvmalloc(sizeof(*ctx) + wksp_size, GFP_KERNEL);
+	if (!ctx)
+		return ERR_PTR(-ENOMEM);
+
+	ctx->params = params;
+	ctx->wksp_size = wksp_size;
+
+	return ctx;
 }
 
-static int zstd_decomp_init(struct zstd_ctx *ctx)
+static struct crypto_acomp_streams zstd_streams = {
+	.alloc_ctx = zstd_alloc_stream,
+	.cfree_ctx = kvfree,
+};
+
+static int zstd_init(struct crypto_acomp *acomp_tfm)
 {
 	int ret = 0;
-	const size_t wksp_size = zstd_dctx_workspace_bound();
 
-	ctx->dwksp = vzalloc(wksp_size);
-	if (!ctx->dwksp) {
-		ret = -ENOMEM;
-		goto out;
-	}
+	mutex_lock(&zstd_stream_lock);
+	ret = crypto_acomp_alloc_streams(&zstd_streams);
+	mutex_unlock(&zstd_stream_lock);
 
-	ctx->dctx = zstd_init_dctx(ctx->dwksp, wksp_size);
-	if (!ctx->dctx) {
-		ret = -EINVAL;
-		goto out_free;
-	}
-out:
 	return ret;
-out_free:
-	vfree(ctx->dwksp);
-	goto out;
 }
 
-static void zstd_comp_exit(struct zstd_ctx *ctx)
+static void zstd_exit(struct crypto_acomp *acomp_tfm)
 {
-	vfree(ctx->cwksp);
-	ctx->cwksp = NULL;
-	ctx->cctx = NULL;
+	crypto_acomp_free_streams(&zstd_streams);
 }
 
-static void zstd_decomp_exit(struct zstd_ctx *ctx)
+static int zstd_compress_one(struct acomp_req *req, struct zstd_ctx *ctx,
+			     const void *src, void *dst, unsigned int *dlen)
 {
-	vfree(ctx->dwksp);
-	ctx->dwksp = NULL;
-	ctx->dctx = NULL;
-}
+	unsigned int out_len;
 
-static int __zstd_init(void *ctx)
-{
-	int ret;
+	ctx->cctx = zstd_init_cctx(ctx->wksp, ctx->wksp_size);
+	if (!ctx->cctx)
+		return -EINVAL;
 
-	ret = zstd_comp_init(ctx);
-	if (ret)
-		return ret;
-	ret = zstd_decomp_init(ctx);
-	if (ret)
-		zstd_comp_exit(ctx);
-	return ret;
+	out_len = zstd_compress_cctx(ctx->cctx, dst, req->dlen, src, req->slen,
+				     &ctx->params);
+	if (zstd_is_error(out_len))
+		return -EINVAL;
+
+	*dlen = out_len;
+
+	return 0;
 }
 
-static void *zstd_alloc_ctx(void)
+static int zstd_compress(struct acomp_req *req)
 {
-	int ret;
+	struct crypto_acomp_stream *s;
+	unsigned int pos, scur, dcur;
+	unsigned int total_out = 0;
+	bool data_available = true;
+	zstd_out_buffer outbuf;
+	struct acomp_walk walk;
+	zstd_in_buffer inbuf;
 	struct zstd_ctx *ctx;
+	size_t pending_bytes;
+	size_t num_bytes;
+	int ret;
 
-	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
-	if (!ctx)
-		return ERR_PTR(-ENOMEM);
+	s = crypto_acomp_lock_stream_bh(&zstd_streams);
+	ctx = s->ctx;
+
+	ret = acomp_walk_virt(&walk, req, true);
+	if (ret)
+		goto out;
 
-	ret = __zstd_init(ctx);
-	if (ret) {
-		kfree(ctx);
-		return ERR_PTR(ret);
+	ctx->cctx = zstd_init_cstream(&ctx->params, 0, ctx->wksp, ctx->wksp_size);
+	if (!ctx->cctx) {
+		ret = -EINVAL;
+		goto out;
 	}
 
-	return ctx;
-}
+	do {
+		dcur = acomp_walk_next_dst(&walk);
+		if (!dcur) {
+			ret = -ENOSPC;
+			goto out;
+		}
 
-static void __zstd_exit(void *ctx)
-{
-	zstd_comp_exit(ctx);
-	zstd_decomp_exit(ctx);
-}
+		outbuf.pos = 0;
+		outbuf.dst = (u8 *)walk.dst.virt.addr;
+		outbuf.size = dcur;
 
-static void zstd_free_ctx(void *ctx)
-{
-	__zstd_exit(ctx);
-	kfree_sensitive(ctx);
-}
+		do {
+			scur = acomp_walk_next_src(&walk);
+			if (dcur == req->dlen && scur == req->slen) {
+				ret = zstd_compress_one(req, ctx, walk.src.virt.addr,
+							walk.dst.virt.addr, &total_out);
+				acomp_walk_done_src(&walk, scur);
+				acomp_walk_done_dst(&walk, dcur);
+				goto out;
+			}
 
-static int __zstd_compress(const u8 *src, unsigned int slen,
-			   u8 *dst, unsigned int *dlen, void *ctx)
-{
-	size_t out_len;
-	struct zstd_ctx *zctx = ctx;
-	const zstd_parameters params = zstd_params();
+			if (scur) {
+				inbuf.pos = 0;
+				inbuf.src = walk.src.virt.addr;
+				inbuf.size = scur;
+			} else {
+				data_available = false;
+				break;
+			}
 
-	out_len = zstd_compress_cctx(zctx->cctx, dst, *dlen, src, slen, &params);
-	if (zstd_is_error(out_len))
-		return -EINVAL;
-	*dlen = out_len;
-	return 0;
-}
+			num_bytes = zstd_compress_stream(ctx->cctx, &outbuf, &inbuf);
+			if (ZSTD_isError(num_bytes)) {
+				ret = -EIO;
+				goto out;
+			}
 
-static int zstd_scompress(struct crypto_scomp *tfm, const u8 *src,
-			  unsigned int slen, u8 *dst, unsigned int *dlen,
-			  void *ctx)
-{
-	return __zstd_compress(src, slen, dst, dlen, ctx);
+			pending_bytes = zstd_flush_stream(ctx->cctx, &outbuf);
+			if (ZSTD_isError(pending_bytes)) {
+				ret = -EIO;
+				goto out;
+			}
+			acomp_walk_done_src(&walk, inbuf.pos);
+		} while (dcur != outbuf.pos);
+
+		total_out += outbuf.pos;
+		acomp_walk_done_dst(&walk, dcur);
+	} while (data_available);
+
+	pos = outbuf.pos;
+	num_bytes = zstd_end_stream(ctx->cctx, &outbuf);
+	if (ZSTD_isError(num_bytes))
+		ret = -EIO;
+	else
+		total_out += (outbuf.pos - pos);
+
+out:
+	if (ret)
+		req->dlen = 0;
+	else
+		req->dlen = total_out;
+
+	crypto_acomp_unlock_stream_bh(s);
+
+	return ret;
 }
 
-static int __zstd_decompress(const u8 *src, unsigned int slen,
-			     u8 *dst, unsigned int *dlen, void *ctx)
+static int zstd_decompress_one(struct acomp_req *req, struct zstd_ctx *ctx,
+			       const void *src, void *dst, unsigned int *dlen)
 {
 	size_t out_len;
-	struct zstd_ctx *zctx = ctx;
 
-	out_len = zstd_decompress_dctx(zctx->dctx, dst, *dlen, src, slen);
+	ctx->dctx = zstd_init_dctx(ctx->wksp, ctx->wksp_size);
+	if (!ctx->dctx)
+		return -EINVAL;
+
+	out_len = zstd_decompress_dctx(ctx->dctx, dst, req->dlen, src, req->slen);
 	if (zstd_is_error(out_len))
 		return -EINVAL;
+
 	*dlen = out_len;
+
 	return 0;
 }
 
-static int zstd_sdecompress(struct crypto_scomp *tfm, const u8 *src,
-			    unsigned int slen, u8 *dst, unsigned int *dlen,
-			    void *ctx)
+static int zstd_decompress(struct acomp_req *req)
 {
-	return __zstd_decompress(src, slen, dst, dlen, ctx);
-}
+	struct crypto_acomp_stream *s;
+	unsigned int total_out = 0;
+	unsigned int scur, dcur;
+	zstd_out_buffer outbuf;
+	struct acomp_walk walk;
+	zstd_in_buffer inbuf;
+	struct zstd_ctx *ctx;
+	size_t pending_bytes;
+	int ret;
 
-static struct scomp_alg scomp = {
-	.alloc_ctx		= zstd_alloc_ctx,
-	.free_ctx		= zstd_free_ctx,
-	.compress		= zstd_scompress,
-	.decompress		= zstd_sdecompress,
-	.base			= {
-		.cra_name	= "zstd",
-		.cra_driver_name = "zstd-scomp",
-		.cra_module	 = THIS_MODULE,
+	s = crypto_acomp_lock_stream_bh(&zstd_streams);
+	ctx = s->ctx;
+
+	ret = acomp_walk_virt(&walk, req, true);
+	if (ret)
+		goto out;
+
+	ctx->dctx = zstd_init_dstream(ZSTD_MAX_SIZE, ctx->wksp, ctx->wksp_size);
+	if (!ctx->dctx) {
+		ret = -EINVAL;
+		goto out;
 	}
+
+	do {
+		scur = acomp_walk_next_src(&walk);
+		if (scur) {
+			inbuf.pos = 0;
+			inbuf.size = scur;
+			inbuf.src = walk.src.virt.addr;
+		} else {
+			break;
+		}
+
+		do {
+			dcur = acomp_walk_next_dst(&walk);
+			if (dcur == req->dlen && scur == req->slen) {
+				ret = zstd_decompress_one(req, ctx, walk.src.virt.addr,
+							  walk.dst.virt.addr, &total_out);
+				acomp_walk_done_dst(&walk, dcur);
+				acomp_walk_done_src(&walk, scur);
+				goto out;
+			}
+
+			if (!dcur) {
+				ret = -ENOSPC;
+				goto out;
+			}
+
+			outbuf.pos = 0;
+			outbuf.dst = (u8 *)walk.dst.virt.addr;
+			outbuf.size = dcur;
+
+			pending_bytes = zstd_decompress_stream(ctx->dctx, &outbuf, &inbuf);
+			if (ZSTD_isError(pending_bytes)) {
+				ret = -EIO;
+				goto out;
+			}
+
+			total_out += outbuf.pos;
+
+			acomp_walk_done_dst(&walk, outbuf.pos);
+		} while (scur != inbuf.pos);
+
+		if (scur)
+			acomp_walk_done_src(&walk, scur);
+	} while (ret == 0);
+
+out:
+	if (ret)
+		req->dlen = 0;
+	else
+		req->dlen = total_out;
+
+	crypto_acomp_unlock_stream_bh(s);
+
+	return ret;
+}
+
+static struct acomp_alg zstd_acomp = {
+	.base = {
+		.cra_name = "zstd",
+		.cra_driver_name = "zstd-generic",
+		.cra_flags = CRYPTO_ALG_REQ_VIRT,
+		.cra_module = THIS_MODULE,
+	},
+	.init = zstd_init,
+	.exit = zstd_exit,
+	.compress = zstd_compress,
+	.decompress = zstd_decompress,
 };
 
 static int __init zstd_mod_init(void)
 {
-	return crypto_register_scomp(&scomp);
+	return crypto_register_acomp(&zstd_acomp);
 }
 
 static void __exit zstd_mod_fini(void)
 {
-	crypto_unregister_scomp(&scomp);
+	crypto_unregister_acomp(&zstd_acomp);
 }
 
 module_init(zstd_mod_init);
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 6.16.y 2/2] crypto: acomp - Fix CFI failure due to type punning
  2025-08-21 19:21 ` [PATCH 6.16.y 1/2] crypto: zstd - convert to acomp Sasha Levin
@ 2025-08-21 19:21   ` Sasha Levin
  2025-08-22  7:16     ` Giovanni Cabiddu
  0 siblings, 1 reply; 7+ messages in thread
From: Sasha Levin @ 2025-08-21 19:21 UTC (permalink / raw)
  To: stable; +Cc: Eric Biggers, Giovanni Cabiddu, Herbert Xu, Sasha Levin

From: Eric Biggers <ebiggers@kernel.org>

[ Upstream commit 962ddc5a7a4b04c007bba0f3e7298cda13c62efd ]

To avoid a crash when control flow integrity is enabled, make the
workspace ("stream") free function use a consistent type, and call it
through a function pointer that has that same type.

Fixes: 42d9f6c77479 ("crypto: acomp - Move scomp stream allocation code into acomp")
Cc: stable@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 crypto/deflate.c                    | 7 ++++++-
 crypto/zstd.c                       | 7 ++++++-
 include/crypto/internal/acompress.h | 5 +----
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/crypto/deflate.c b/crypto/deflate.c
index fe8e4ad0fee1..21404515dc77 100644
--- a/crypto/deflate.c
+++ b/crypto/deflate.c
@@ -48,9 +48,14 @@ static void *deflate_alloc_stream(void)
 	return ctx;
 }
 
+static void deflate_free_stream(void *ctx)
+{
+	kvfree(ctx);
+}
+
 static struct crypto_acomp_streams deflate_streams = {
 	.alloc_ctx = deflate_alloc_stream,
-	.cfree_ctx = kvfree,
+	.free_ctx = deflate_free_stream,
 };
 
 static int deflate_compress_one(struct acomp_req *req,
diff --git a/crypto/zstd.c b/crypto/zstd.c
index 657e0cf7b952..ff5f596a4ea7 100644
--- a/crypto/zstd.c
+++ b/crypto/zstd.c
@@ -54,9 +54,14 @@ static void *zstd_alloc_stream(void)
 	return ctx;
 }
 
+static void zstd_free_stream(void *ctx)
+{
+	kvfree(ctx);
+}
+
 static struct crypto_acomp_streams zstd_streams = {
 	.alloc_ctx = zstd_alloc_stream,
-	.cfree_ctx = kvfree,
+	.free_ctx = zstd_free_stream,
 };
 
 static int zstd_init(struct crypto_acomp *acomp_tfm)
diff --git a/include/crypto/internal/acompress.h b/include/crypto/internal/acompress.h
index ffffd88bbbad..2d97440028ff 100644
--- a/include/crypto/internal/acompress.h
+++ b/include/crypto/internal/acompress.h
@@ -63,10 +63,7 @@ struct crypto_acomp_stream {
 struct crypto_acomp_streams {
 	/* These must come first because of struct scomp_alg. */
 	void *(*alloc_ctx)(void);
-	union {
-		void (*free_ctx)(void *);
-		void (*cfree_ctx)(const void *);
-	};
+	void (*free_ctx)(void *);
 
 	struct crypto_acomp_stream __percpu *streams;
 	struct work_struct stream_work;
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 6.16.y 2/2] crypto: acomp - Fix CFI failure due to type punning
  2025-08-21 19:21   ` [PATCH 6.16.y 2/2] crypto: acomp - Fix CFI failure due to type punning Sasha Levin
@ 2025-08-22  7:16     ` Giovanni Cabiddu
  2025-08-22  7:48       ` Herbert Xu
  0 siblings, 1 reply; 7+ messages in thread
From: Giovanni Cabiddu @ 2025-08-22  7:16 UTC (permalink / raw)
  To: Sasha Levin, stable, Eric Biggers, Herbert Xu

Hi Sasha,

On Thu, Aug 21, 2025 at 03:21:31PM -0400, Sasha Levin wrote:
> From: Eric Biggers <ebiggers@kernel.org>
> 
> [ Upstream commit 962ddc5a7a4b04c007bba0f3e7298cda13c62efd ]
> 
> To avoid a crash when control flow integrity is enabled, make the
> workspace ("stream") free function use a consistent type, and call it
> through a function pointer that has that same type.
> 
> Fixes: 42d9f6c77479 ("crypto: acomp - Move scomp stream allocation code into acomp")
> Cc: stable@vger.kernel.org
> Signed-off-by: Eric Biggers <ebiggers@kernel.org>
> Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
>  crypto/deflate.c                    | 7 ++++++-
>  crypto/zstd.c                       | 7 ++++++-
>  include/crypto/internal/acompress.h | 5 +----
>  3 files changed, 13 insertions(+), 6 deletions(-)
> 
> diff --git a/crypto/deflate.c b/crypto/deflate.c
> index fe8e4ad0fee1..21404515dc77 100644
> --- a/crypto/deflate.c
> +++ b/crypto/deflate.c
> @@ -48,9 +48,14 @@ static void *deflate_alloc_stream(void)
>  	return ctx;
>  }
>  
> +static void deflate_free_stream(void *ctx)
> +{
> +	kvfree(ctx);
> +}
> +
>  static struct crypto_acomp_streams deflate_streams = {
>  	.alloc_ctx = deflate_alloc_stream,
> -	.cfree_ctx = kvfree,
> +	.free_ctx = deflate_free_stream,
>  };
>  
>  static int deflate_compress_one(struct acomp_req *req,

Wouldn't it be simpler to drop the below changes to crypto/zstd.c in
this patch and avoid backporting commit f5ad93ffb541 ("crypto: zstd -
convert to acomp") to stable?

f5ad93ffb541 appears to be more of a feature than a fix, and there are
related follow-up changes that aren't marked with a Fixes tag:

  03ba056e63d3 ("crypto: zstd - fix duplicate check warning")
  25f4e1d7193d ("crypto: zstd - replace zero-length array with flexible array member")

Eric, Herbert, what's your take?

> diff --git a/crypto/zstd.c b/crypto/zstd.c
> index 657e0cf7b952..ff5f596a4ea7 100644
> --- a/crypto/zstd.c
> +++ b/crypto/zstd.c
> @@ -54,9 +54,14 @@ static void *zstd_alloc_stream(void)
>  	return ctx;
>  }
>  
> +static void zstd_free_stream(void *ctx)
> +{
> +	kvfree(ctx);
> +}
> +
>  static struct crypto_acomp_streams zstd_streams = {
>  	.alloc_ctx = zstd_alloc_stream,
> -	.cfree_ctx = kvfree,
> +	.free_ctx = zstd_free_stream,
>  };
>  
>  static int zstd_init(struct crypto_acomp *acomp_tfm)
> diff --git a/include/crypto/internal/acompress.h b/include/crypto/internal/acompress.h
> index ffffd88bbbad..2d97440028ff 100644
> --- a/include/crypto/internal/acompress.h
> +++ b/include/crypto/internal/acompress.h
> @@ -63,10 +63,7 @@ struct crypto_acomp_stream {
>  struct crypto_acomp_streams {
>  	/* These must come first because of struct scomp_alg. */
>  	void *(*alloc_ctx)(void);
> -	union {
> -		void (*free_ctx)(void *);
> -		void (*cfree_ctx)(const void *);
> -	};
> +	void (*free_ctx)(void *);
>  
>  	struct crypto_acomp_stream __percpu *streams;
>  	struct work_struct stream_work;

Regards,

-- 
Giovanni

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 6.16.y 2/2] crypto: acomp - Fix CFI failure due to type punning
  2025-08-22  7:16     ` Giovanni Cabiddu
@ 2025-08-22  7:48       ` Herbert Xu
  2025-08-22  7:54         ` Greg KH
  0 siblings, 1 reply; 7+ messages in thread
From: Herbert Xu @ 2025-08-22  7:48 UTC (permalink / raw)
  To: Giovanni Cabiddu; +Cc: Sasha Levin, stable, Eric Biggers

On Fri, Aug 22, 2025 at 08:16:36AM +0100, Giovanni Cabiddu wrote:
>
> Wouldn't it be simpler to drop the below changes to crypto/zstd.c in
> this patch and avoid backporting commit f5ad93ffb541 ("crypto: zstd -
> convert to acomp") to stable?
> 
> f5ad93ffb541 appears to be more of a feature than a fix, and there are
> related follow-up changes that aren't marked with a Fixes tag:
> 
>   03ba056e63d3 ("crypto: zstd - fix duplicate check warning")
>   25f4e1d7193d ("crypto: zstd - replace zero-length array with flexible array member")
> 
> Eric, Herbert, what's your take?

Yes there is no reason to backport that patch at all.

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 6.16.y 2/2] crypto: acomp - Fix CFI failure due to type punning
  2025-08-22  7:48       ` Herbert Xu
@ 2025-08-22  7:54         ` Greg KH
  2025-08-22 10:49           ` Giovanni Cabiddu
  0 siblings, 1 reply; 7+ messages in thread
From: Greg KH @ 2025-08-22  7:54 UTC (permalink / raw)
  To: Herbert Xu; +Cc: Giovanni Cabiddu, Sasha Levin, stable, Eric Biggers

On Fri, Aug 22, 2025 at 03:48:46PM +0800, Herbert Xu wrote:
> On Fri, Aug 22, 2025 at 08:16:36AM +0100, Giovanni Cabiddu wrote:
> >
> > Wouldn't it be simpler to drop the below changes to crypto/zstd.c in
> > this patch and avoid backporting commit f5ad93ffb541 ("crypto: zstd -
> > convert to acomp") to stable?
> > 
> > f5ad93ffb541 appears to be more of a feature than a fix, and there are
> > related follow-up changes that aren't marked with a Fixes tag:
> > 
> >   03ba056e63d3 ("crypto: zstd - fix duplicate check warning")
> >   25f4e1d7193d ("crypto: zstd - replace zero-length array with flexible array member")
> > 
> > Eric, Herbert, what's your take?
> 
> Yes there is no reason to backport that patch at all.

Both now dropped, thanks.

greg k-h

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 6.16.y 2/2] crypto: acomp - Fix CFI failure due to type punning
  2025-08-22  7:54         ` Greg KH
@ 2025-08-22 10:49           ` Giovanni Cabiddu
  0 siblings, 0 replies; 7+ messages in thread
From: Giovanni Cabiddu @ 2025-08-22 10:49 UTC (permalink / raw)
  To: Greg KH; +Cc: Herbert Xu, Sasha Levin, stable, Eric Biggers

On Fri, Aug 22, 2025 at 09:54:46AM +0200, Greg KH wrote:
> On Fri, Aug 22, 2025 at 03:48:46PM +0800, Herbert Xu wrote:
> > On Fri, Aug 22, 2025 at 08:16:36AM +0100, Giovanni Cabiddu wrote:
> > >
> > > Wouldn't it be simpler to drop the below changes to crypto/zstd.c in
> > > this patch and avoid backporting commit f5ad93ffb541 ("crypto: zstd -
> > > convert to acomp") to stable?
> > > 
> > > f5ad93ffb541 appears to be more of a feature than a fix, and there are
> > > related follow-up changes that aren't marked with a Fixes tag:
> > > 
> > >   03ba056e63d3 ("crypto: zstd - fix duplicate check warning")
> > >   25f4e1d7193d ("crypto: zstd - replace zero-length array with flexible array member")
> > > 
> > > Eric, Herbert, what's your take?
> > 
> > Yes there is no reason to backport that patch at all.
> 
> Both now dropped, thanks.

Thanks Greg.

I'm going to send a backport for the second patch, 962ddc5a7a4b
("crypto: acomp - Fix CFI failure due to type punning"), which includes
only the required logic for deflate.

Regards,

-- 
Giovanni

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-08-22 10:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-21 12:54 FAILED: patch "[PATCH] crypto: acomp - Fix CFI failure due to type punning" failed to apply to 6.16-stable tree gregkh
2025-08-21 19:21 ` [PATCH 6.16.y 1/2] crypto: zstd - convert to acomp Sasha Levin
2025-08-21 19:21   ` [PATCH 6.16.y 2/2] crypto: acomp - Fix CFI failure due to type punning Sasha Levin
2025-08-22  7:16     ` Giovanni Cabiddu
2025-08-22  7:48       ` Herbert Xu
2025-08-22  7:54         ` Greg KH
2025-08-22 10:49           ` Giovanni Cabiddu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).