[v1,2/2] integrity: Add the release() hook to the integrity LSM module

Message ID 20230310231107.10954-2-mirsad.todorovac@alu.unizg.hr
State New
Headers
Series [v1,1/2] LSM: add a release() hook for the clean exit cleanup of the LSM modules |

Commit Message

Mirsad Todorovac March 10, 2023, 11:11 p.m. UTC
  The kmem_cache_create() callback in the init() hook of the integrity LSM
module doesn't have a corresponding kmem_cache_destroy() function call.

The allocated cache is destroyed on kernel shutdown in an undefined manner.

This patch should define a proper destructor to deallocate resource in a
well-behaved, defined order.

Signed-off-by: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr>
Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Mimi Zohar <zohar@linux.ibm.com>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Thomas Weißschuh <linux@weissschuh.net>
Cc: Casey Schaufler <casey@schaufler-ca.com>
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Mickaël Salaün <mic@digikod.net>
Cc: Frederick Lawler <fred@cloudflare.com>

---
 security/integrity/iint.c | 7 +++++++
 1 file changed, 7 insertions(+)
  

Patch

diff --git a/security/integrity/iint.c b/security/integrity/iint.c
index 8638976f7990..3f69eb702b2e 100644
--- a/security/integrity/iint.c
+++ b/security/integrity/iint.c
@@ -179,9 +179,16 @@  static int __init integrity_iintcache_init(void)
 			      0, SLAB_PANIC, init_once);
 	return 0;
 }
+
+static int __exit integrity_iintcache_release(void)
+{
+	kmem_cache_destroy(iint_cache);
+}
+
 DEFINE_LSM(integrity) = {
 	.name = "integrity",
 	.init = integrity_iintcache_init,
+	.release = integrity_iintcache_release,
 };