[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aX1tgpqjtIby9tav@gondor.apana.org.au>
Date: Sat, 31 Jan 2026 10:48:34 +0800
From: Herbert Xu <herbert@...dor.apana.org.au>
To: Ella Ma <alansnape3058@...il.com>
Cc: thomas.lendacky@....com, john.allen@....com, davem@...emloft.net,
arnd@...db.de, linux-crypto@...r.kernel.org,
linux-kernel@...r.kernel.org, julia.lawall@...ia.fr,
Markus.Elfring@....de, Tom Lendacky <thomas.lendacky@...il.com>
Subject: Re: [PATCH v2] crypto: ccp - Fix a crash due to incorrect cleanup
usage of kfree
On Fri, Jan 09, 2026 at 04:17:24PM +0100, Ella Ma wrote:
> Annotating a local pointer variable, which will be assigned with the
> kmalloc-family functions, with the `__cleanup(kfree)` attribute will
> make the address of the local variable, rather than the address returned
> by kmalloc, passed to kfree directly and lead to a crash due to invalid
> deallocation of stack address. According to other places in the repo,
> the correct usage should be `__free(kfree)`. The code coincidentally
> compiled because the parameter type `void *` of kfree is compatible with
> the desired type `struct { ... } **`.
>
> Fixes: a71475582ada ("crypto: ccp - reduce stack usage in ccp_run_aes_gcm_cmd")
> Signed-off-by: Ella Ma <alansnape3058@...il.com>
> Acked-by: Tom Lendacky <thomas.lendacky@...il.com>
> ---
>
> Changes in v2:
> - Update the subject prefix as suggested by Markus
>
>
> I don't have the machine to actually test the changed place. So I tried
> locally with a simple test module. The crash happens right when the
> module is being loaded.
>
> ```C
> #include <linux/init.h>
> #include <linux/module.h>
> MODULE_LICENSE("GPL");
> static int __init custom_init(void) {
> printk(KERN_INFO "Crash reproduce for drivers/crypto/ccp/ccp-ops.c");
> int *p __cleanup(kfree) = kzalloc(sizeof(int), GFP_KERNEL);
> *p = 42;
> return 0;
> }
> static void __exit custom_exit(void) {}
> module_init(custom_init);
> module_exit(custom_exit);
> ```
>
> BESIDES, scripts/checkpatch.pl reports a coding style issue originally
> existing in the code, `sizeof *wa`, I fixed this together in this patch.
>
> drivers/crypto/ccp/ccp-ops.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Patch applied. Thanks.
--
Email: Herbert Xu <herbert@...dor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Powered by blists - more mailing lists