FAILED: patch "[PATCH] crypto: nx - fix bounce buffer leaks in" failed to apply to 6.6-stable tree
Subsystems (4)
[email protected]
maintainerThe patch below does not apply to the 6.6-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 <[email protected]>.
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.6.y
git checkout FETCH_HEAD
git cherry-pick -x adb3faf2db1a66d0f015b44ac909a32dfc7f2f9c
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026050440-dude-evade-6747@gregkh' --subject-prefix 'PATCH 6.6.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From adb3faf2db1a66d0f015b44ac909a32dfc7f2f9c Mon Sep 17 00:00:00 2001
From: Thorsten Blum <[email protected]>
Date: Wed, 11 Mar 2026 16:56:47 +0100
Subject: [PATCH] crypto: nx - fix bounce buffer leaks in
nx842_crypto_{alloc,free}_ctx
The bounce buffers are allocated with __get_free_pages() using BOUNCE_BUFFER_ORDER (order 2 = 4 pages), but both the allocation error path and nx842_crypto_free_ctx() release the buffers with free_page(). Use free_pages() with the matching order instead.
drivers/crypto/nx/nx-842.c +4 -4
@@ -116,8 +116,8 @@ void *nx842_crypto_alloc_ctx(struct nx842_driver *driver) ctx->dbounce = (u8 *)__get_free_pages (GFP_KERNEL ,BOUNCE_BUFFER_ORDER );if (!ctx->wmem || !ctx->sbounce || !ctx->dbounce) {kfree (ctx->wmem); -free_page ((unsigned long )ctx->sbounce); -free_page ((unsigned long )ctx->dbounce); +free_pages ((unsigned long )ctx->sbounce,BOUNCE_BUFFER_ORDER ); +free_pages ((unsigned long )ctx->dbounce,BOUNCE_BUFFER_ORDER );kfree (ctx);return ERR_PTR (-ENOMEM ); }
@@ -131,8 +131,8 @@ void nx842_crypto_free_ctx(void *p)struct nx842_crypto_ctx *ctx = p;kfree (ctx->wmem); -free_page ((unsigned long )ctx->sbounce); -free_page ((unsigned long )ctx->dbounce); +free_pages ((unsigned long )ctx->sbounce,BOUNCE_BUFFER_ORDER ); +free_pages ((unsigned long )ctx->dbounce,BOUNCE_BUFFER_ORDER ); }EXPORT_SYMBOL_GPL (nx842_crypto_free_ctx);
Sasha Levin
maintainerPATCH 1/3 crypto: nx - Avoid -Wflex-array-member-not-at-end warning
From: "Gustavo A. R. Silva" <[email protected]>
[ Upstream commit 1e6b251ce1759392666856908113dd5d7cea044d ]
-Wflex-array-member-not-at-end is coming in GCC-14, and we are getting ready to enable it globally. So, we are deprecating flexible-array members in the middle of another structure.
There is currently an object (header) in struct nx842_crypto_ctx that contains a flexible structure (struct nx842_crypto_header):
struct nx842_crypto_ctx {
...
struct nx842_crypto_header header;
struct nx842_crypto_header_group group[NX842_CRYPTO_GROUP_MAX];
...
};So, in order to avoid ending up with a flexible-array member in the middle of another struct, we use the struct_group_tagged() helper to separate the flexible array from the rest of the members in the flexible structure:
struct nx842_crypto_header {
struct_group_tagged(nx842_crypto_header_hdr, hdr,
... the rest of the members
);
struct nx842_crypto_header_group group[];
} __packed;With the change described above, we can now declare an object of the type of the tagged struct, without embedding the flexible array in the middle of another struct:
struct nx842_crypto_ctx {
...
struct nx842_crypto_header_hdr header;
struct nx842_crypto_header_group group[NX842_CRYPTO_GROUP_MAX];
... } __packed;
We also use container_of() whenever we need to retrieve a pointer to the flexible structure, through which we can access the flexible array if needed.
So, with these changes, fix the following warning:
In file included from drivers/crypto/nx/nx-842.c:55:drivers/crypto/nx/nx-842.h:174:36: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
174 | struct nx842_crypto_header header;
| ^~~~~~
Stable-dep-of: adb3faf2db1a ("crypto: nx - fix bounce buffer leaks in nx842_crypto_{alloc,free}_ctx")
--- drivers/crypto/nx/nx-842.c | 6 ++++-- drivers/crypto/nx/nx-842.h | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-)
drivers/crypto/nx/nx-842.c +4 -2
@@ -251,7 +251,9 @@ int nx842_crypto_compress(struct crypto_tfm *tfm, u8 *dst, unsigned int *dlen) { struct nx842_crypto_ctx *ctx = crypto_tfm_ctx(tfm); -struct nx842_crypto_header *hdr = &ctx->header; +struct nx842_crypto_header *hdr = +container_of (&ctx->header, + struct nx842_crypto_header, hdr);struct nx842_crypto_param p;struct nx842_constraints c = *ctx->driver->constraints;unsigned int groups, hdrsize, h;
@@ -490,7 +492,7 @@ int nx842_crypto_decompress(struct crypto_tfm *tfm, }memcpy (&ctx->header, src, hdr_len); - hdr = &ctx->header; + hdr = container_of(&ctx->header, struct nx842_crypto_header, hdr);for (n =0 ; n < hdr->groups; n++) {/* ignore applies to last group */
drivers/crypto/nx/nx-842.h +6 -4
@@ -157,9 +157,11 @@ struct nx842_crypto_header_group { } __packed;struct nx842_crypto_header { -__be16 magic;/* NX842_CRYPTO_MAGIC */ -__be16 ignore;/* decompressed end bytes to ignore */ -u8 groups;/* total groups in this header */ + struct_group_tagged(nx842_crypto_header_hdr, hdr, + __be16 magic; /* NX842_CRYPTO_MAGIC */ +__be16 ignore;/* decompressed end bytes to ignore */ +u8 groups;/* total groups in this header */ + );struct nx842_crypto_header_group group[]; } __packed;
@@ -171,7 +173,7 @@ struct nx842_crypto_ctx {u8 *wmem;u8 *sbounce, *dbounce; -struct nx842_crypto_header header; +struct nx842_crypto_header_hdr header;struct nx842_crypto_header_group group[NX842_CRYPTO_GROUP_MAX ];struct nx842_driver *driver;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/3 crypto: nx - Migrate to scomp API
From: Ard Biesheuvel <[email protected]>
[ Upstream commit 980b5705f4e73f567e405cd18337cc32fd51cf79 ]
The only remaining user of 842 compression has been migrated to the acomp compression API, and so the NX hardware driver has to follow suit, given that no users of the obsolete 'comp' API remain, and it is going to be removed.
So migrate the NX driver code to scomp. These will be wrapped and exposed as acomp implementation via the crypto subsystem's acomp-to-scomp adaptation layer.
Stable-dep-of: adb3faf2db1a ("crypto: nx - fix bounce buffer leaks in nx842_crypto_{alloc,free}_ctx")
--- drivers/crypto/nx/nx-842.c | 33 +++++++++++++++------------ drivers/crypto/nx/nx-842.h | 15 ++++++------ drivers/crypto/nx/nx-common-powernv.c | 31 ++++++++++++------------- drivers/crypto/nx/nx-common-pseries.c | 33 +++++++++++++-------------- 4 files changed, 58 insertions(+), 54 deletions(-)
drivers/crypto/nx/nx-842.c +19 -14
@@ -101,9 +101,13 @@ static int update_param(struct nx842_crypto_param *p,return 0 ; } -int nx842_crypto_init (struct crypto_tfm *tfm,struct nx842_driver *driver) +void *nx842_crypto_alloc_ctx (struct nx842_driver *driver) { -struct nx842_crypto_ctx *ctx =crypto_tfm_ctx (tfm); +struct nx842_crypto_ctx *ctx; + + ctx =kzalloc (sizeof (*ctx),GFP_KERNEL ); +if (!ctx) +return ERR_PTR (-ENOMEM );spin_lock_init (&ctx->lock); ctx->driver = driver;
@@ -114,22 +118,23 @@ int nx842_crypto_init(struct crypto_tfm *tfm, struct nx842_driver *driver)kfree (ctx->wmem);free_page ((unsigned long )ctx->sbounce);free_page ((unsigned long )ctx->dbounce); -return -ENOMEM ; +kfree (ctx); +return ERR_PTR (-ENOMEM ); } -return 0 ; +return ctx; } -EXPORT_SYMBOL_GPL (nx842_crypto_init); +EXPORT_SYMBOL_GPL (nx842_crypto_alloc_ctx); -void nx842_crypto_exit (struct crypto_tfm *tfm) +void nx842_crypto_free_ctx (void *p) { -struct nx842_crypto_ctx *ctx =crypto_tfm_ctx (tfm); +struct nx842_crypto_ctx *ctx = p;kfree (ctx->wmem);free_page ((unsigned long )ctx->sbounce);free_page ((unsigned long )ctx->dbounce); } -EXPORT_SYMBOL_GPL (nx842_crypto_exit); +EXPORT_SYMBOL_GPL (nx842_crypto_free_ctx);static void check_constraints (struct nx842_constraints *c) {
@@ -246,11 +251,11 @@ static int compress(struct nx842_crypto_ctx *ctx,return update_param (p, slen, dskip + dlen); } -int nx842_crypto_compress (struct crypto_tfm *tfm, +int nx842_crypto_compress (struct crypto_scomp *tfm,const u8 *src,unsigned int slen, -u8 *dst,unsigned int *dlen) +u8 *dst,unsigned int *dlen,void *pctx) { -struct nx842_crypto_ctx *ctx =crypto_tfm_ctx (tfm); +struct nx842_crypto_ctx *ctx = pctx;struct nx842_crypto_header *hdr =container_of (&ctx->header, struct nx842_crypto_header, hdr);
@@ -431,11 +436,11 @@ static int decompress(struct nx842_crypto_ctx *ctx,return update_param (p, slen + padding, dlen); } -int nx842_crypto_decompress (struct crypto_tfm *tfm, +int nx842_crypto_decompress (struct crypto_scomp *tfm,const u8 *src,unsigned int slen, -u8 *dst,unsigned int *dlen) +u8 *dst,unsigned int *dlen,void *pctx) { -struct nx842_crypto_ctx *ctx =crypto_tfm_ctx (tfm); +struct nx842_crypto_ctx *ctx = pctx;struct nx842_crypto_header *hdr;struct nx842_crypto_param p;struct nx842_constraints c = *ctx->driver->constraints;
drivers/crypto/nx/nx-842.h +8 -7
@@ -3,7 +3,6 @@#ifndef __NX_842_H__#define __NX_842_H__ -#include <crypto/algapi.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/module.h>
@@ -101,6 +100,8 @@#define LEN_ON_SIZE (pa, size) ((size) - ((pa) & ((size) - 1)))#define LEN_ON_PAGE (pa) LEN_ON_SIZE(pa, PAGE_SIZE) +struct crypto_scomp ; +static inline unsigned long nx842_get_pa (void *addr) {if (!is_vmalloc_addr (addr))
@@ -179,13 +180,13 @@ struct nx842_crypto_ctx { struct nx842_driver *driver; }; -int nx842_crypto_init (struct crypto_tfm *tfm,struct nx842_driver *driver); -void nx842_crypto_exit (struct crypto_tfm *tfm); -int nx842_crypto_compress (struct crypto_tfm *tfm, +void *nx842_crypto_alloc_ctx (struct nx842_driver *driver); +void nx842_crypto_free_ctx (void *ctx); +int nx842_crypto_compress (struct crypto_scomp *tfm,const u8 *src,unsigned int slen, -u8 *dst,unsigned int *dlen); -int nx842_crypto_decompress (struct crypto_tfm *tfm, +u8 *dst,unsigned int *dlen,void *ctx); +int nx842_crypto_decompress (struct crypto_scomp *tfm,const u8 *src,unsigned int slen, -u8 *dst,unsigned int *dlen); +u8 *dst,unsigned int *dlen,void *ctx);#endif /* __NX_842_H__ */
drivers/crypto/nx/nx-common-powernv.c +15 -16
@@ -9,6 +9,7 @@#include "nx-842.h" +#include <crypto/internal/scompress.h> #include <linux/timer.h> #include <asm/prom.h>
@@ -1031,23 +1032,21 @@ static struct nx842_driver nx842_powernv_driver = { .decompress = nx842_powernv_decompress, }; -static int nx842_powernv_crypto_init (struct crypto_tfm *tfm) +static void *nx842_powernv_crypto_alloc_ctx (void ) { -return nx842_crypto_init (tfm, &nx842_powernv_driver); +return nx842_crypto_alloc_ctx (&nx842_powernv_driver); } -static struct crypto_alg nx842_powernv_alg = { - .cra_name ="842" , - .cra_driver_name ="842-nx" , - .cra_priority =300 , - .cra_flags =CRYPTO_ALG_TYPE_COMPRESS , - .cra_ctxsize =sizeof (struct nx842_crypto_ctx ), - .cra_module =THIS_MODULE , - .cra_init = nx842_powernv_crypto_init, - .cra_exit = nx842_crypto_exit, - .cra_u = { .compress = { - .coa_compress = nx842_crypto_compress, - .coa_decompress = nx842_crypto_decompress } } +static struct scomp_alg nx842_powernv_alg = { + .base.cra_name ="842" , + .base.cra_driver_name ="842-nx" , + .base.cra_priority =300 , + .base.cra_module =THIS_MODULE , + + .alloc_ctx = nx842_powernv_crypto_alloc_ctx, + .free_ctx = nx842_crypto_free_ctx, + .compress = nx842_crypto_compress, + .decompress = nx842_crypto_decompress, };static __init int nx_compress_powernv_init (void )
@@ -1107,7 +1106,7 @@ static __init int nx_compress_powernv_init(void) nx842_powernv_exec = nx842_exec_vas; } - ret =crypto_register_alg (&nx842_powernv_alg); + ret =crypto_register_scomp (&nx842_powernv_alg);if (ret) {nx_delete_coprocs ();return ret;
@@ -1128,7 +1127,7 @@ static void __exit nx_compress_powernv_exit(void)if (!nx842_ct)vas_unregister_api_powernv (); -crypto_unregister_alg (&nx842_powernv_alg); +crypto_unregister_scomp (&nx842_powernv_alg);nx_delete_coprocs (); }
drivers/crypto/nx/nx-common-pseries.c +16 -17
@@ -11,6 +11,7 @@#include <asm/vio.h> #include <asm/hvcall.h> #include <asm/vas.h> +#include <crypto/internal/scompress.h> #include "nx-842.h" #include "nx_csbcpb.h" /* struct nx_csbcpb */
@@ -1008,23 +1009,21 @@ static struct nx842_driver nx842_pseries_driver = { .decompress = nx842_pseries_decompress, }; -static int nx842_pseries_crypto_init (struct crypto_tfm *tfm) +static void *nx842_pseries_crypto_alloc_ctx (void ) { -return nx842_crypto_init (tfm, &nx842_pseries_driver); +return nx842_crypto_alloc_ctx (&nx842_pseries_driver); } -static struct crypto_alg nx842_pseries_alg = { - .cra_name ="842" , - .cra_driver_name ="842-nx" , - .cra_priority =300 , - .cra_flags =CRYPTO_ALG_TYPE_COMPRESS , - .cra_ctxsize =sizeof (struct nx842_crypto_ctx ), - .cra_module =THIS_MODULE , - .cra_init = nx842_pseries_crypto_init, - .cra_exit = nx842_crypto_exit, - .cra_u = { .compress = { - .coa_compress = nx842_crypto_compress, - .coa_decompress = nx842_crypto_decompress } } +static struct scomp_alg nx842_pseries_alg = { + .base.cra_name ="842" , + .base.cra_driver_name ="842-nx" , + .base.cra_priority =300 , + .base.cra_module =THIS_MODULE , + + .alloc_ctx = nx842_pseries_crypto_alloc_ctx, + .free_ctx = nx842_crypto_free_ctx, + .compress = nx842_crypto_compress, + .decompress = nx842_crypto_decompress, }; static int nx842_probe(struct vio_dev *viodev,
@@ -1072,7 +1071,7 @@ static int nx842_probe(struct vio_dev *viodev,if (ret) goto error; - ret =crypto_register_alg (&nx842_pseries_alg); + ret =crypto_register_scomp (&nx842_pseries_alg);if (ret) {dev_err (&viodev->dev,"could not register comp alg: %d\n" , ret); goto error;
@@ -1120,7 +1119,7 @@ static void nx842_remove(struct vio_dev *viodev)if (caps_feat)sysfs_remove_group (&viodev->dev.kobj, &nxcop_caps_attr_group); -crypto_unregister_alg (&nx842_pseries_alg); +crypto_unregister_scomp (&nx842_pseries_alg);spin_lock_irqsave (&devdata_mutex, flags); old_devdata = rcu_dereference_check(devdata,
@@ -1252,7 +1251,7 @@ static void __exit nx842_pseries_exit(void)vas_unregister_api_pseries (); -crypto_unregister_alg (&nx842_pseries_alg); +crypto_unregister_scomp (&nx842_pseries_alg);spin_lock_irqsave (&devdata_mutex, flags); old_devdata = rcu_dereference_check(devdata,
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/3 crypto: nx - fix bounce buffer leaks in nx842_crypto_{alloc,free}_ctx
In reply to Sasha LevinFrom: Thorsten Blum <[email protected]>
[ Upstream commit adb3faf2db1a66d0f015b44ac909a32dfc7f2f9c ]
The bounce buffers are allocated with __get_free_pages() using BOUNCE_BUFFER_ORDER (order 2 = 4 pages), but both the allocation error path and nx842_crypto_free_ctx() release the buffers with free_page(). Use free_pages() with the matching order instead.
--- drivers/crypto/nx/nx-842.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/crypto/nx/nx-842.c +4 -4
@@ -116,8 +116,8 @@ void *nx842_crypto_alloc_ctx(struct nx842_driver *driver) ctx->dbounce = (u8 *)__get_free_pages (GFP_KERNEL ,BOUNCE_BUFFER_ORDER );if (!ctx->wmem || !ctx->sbounce || !ctx->dbounce) {kfree (ctx->wmem); -free_page ((unsigned long )ctx->sbounce); -free_page ((unsigned long )ctx->dbounce); +free_pages ((unsigned long )ctx->sbounce,BOUNCE_BUFFER_ORDER ); +free_pages ((unsigned long )ctx->dbounce,BOUNCE_BUFFER_ORDER );kfree (ctx);return ERR_PTR (-ENOMEM ); }
@@ -131,8 +131,8 @@ void nx842_crypto_free_ctx(void *p)struct nx842_crypto_ctx *ctx = p;kfree (ctx->wmem); -free_page ((unsigned long )ctx->sbounce); -free_page ((unsigned long )ctx->dbounce); +free_pages ((unsigned long )ctx->sbounce,BOUNCE_BUFFER_ORDER ); +free_pages ((unsigned long )ctx->dbounce,BOUNCE_BUFFER_ORDER ); }EXPORT_SYMBOL_GPL (nx842_crypto_free_ctx);
Signature · 1 line
2.53.0