Skip to contentSkip to conversation

crypto: scomp - Fix memory leak on module unload

PATCH New Herbert Xu 1 participant 3 messages Mar 16, 2025 Crypto API

lore
Share & tools
lore

Herbert Xu

author maintainer
#0 lore raw

cover crypto: scomp - Fix memory leak on module unload

This mini series fixes the leaking of stream memory when an scomp algorith module is unloaded.

Herbert Xu (2):
crypto: scompress - Fix incorrect stream freeing
crypto: api - Call crypto_alg_put in crypto_unregister_alg

 crypto/algapi.c    | 3 +--
 crypto/scompress.c | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)
Signature · 1 line
2.39.5
author maintainer
#1 lore raw

PATCH 1/2 crypto: scompress - Fix incorrect stream freeing

Fix stream freeing crash by passing the correct pointer.

Fixes 3d72ad46a23a ("crypto: acomp - Move stream management into scomp layer")
---
 crypto/scompress.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/scompress.c +1 -1
index 57bb7353d767..d4be977b9729 100644
@@ -117,7 +117,7 @@ static void scomp_free_streams(struct scomp_alg *alg)
 		if (!ps->ctx)
 			break;
 
-		alg->free_ctx(ps);
+		alg->free_ctx(ps->ctx);
 	}
 
 	free_percpu(stream);
Signature · 1 line
2.39.5
author maintainer
#2 lore raw

PATCH 2/2 crypto: api - Call crypto_alg_put in crypto_unregister_alg

In reply to Herbert Xu

Instead of calling cra_destroy by hand, call it through crypto_alg_put so that the correct unwinding functions are called through crypto_destroy_alg.

Fixes 3d6979bf3bd5 ("crypto: api - Add cra_type->destroy hook")
---
 crypto/algapi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
crypto/algapi.c +1 -2
index e7a9a2ada2cf..ea9ed9580aa8 100644
@@ -464,8 +464,7 @@ void crypto_unregister_alg(struct crypto_alg *alg)
 	if (WARN_ON(refcount_read(&alg->cra_refcnt) != 1))
 		return;
 
-	if (alg->cra_destroy)
-		alg->cra_destroy(alg);
+	crypto_alg_put(alg);
 
 	crypto_remove_final(&list);
 }
Signature · 1 line
2.39.5