Re: [RFC PATCH v2] ima: fix possible memory leak in cache allocating for namespace

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 12/25/22 21:43, Denis Semakin wrote:
There is a KMEM_CACHE(); macro which calls kmem_cache_create() function.
The default workflow is to call:
kmem_cache_create();
kmem_cache_alloc();
kmem_cache_free();
kmem_cache_destroy();

But here if register_blocking_lsm_notifier() return an error then
kmem_cache_destroy() will never calls which can lead a memory leak I suppose.

Signed-off-by: Denis Semakin <denis.semakin@xxxxxxxxxx>
Signed-off-by: Ilya Hanov <ilya.hanov@xxxxxxxxxxxxxxxxxxx>
---
  security/integrity/ima/ima_init_ima_ns.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/security/integrity/ima/ima_init_ima_ns.c b/security/integrity/ima/ima_init_ima_ns.c
index 1eaa6ceee2ee..5c850b740ae6 100644
--- a/security/integrity/ima/ima_init_ima_ns.c
+++ b/security/integrity/ima/ima_init_ima_ns.c
@@ -43,12 +43,16 @@ int ima_init_namespace(struct ima_namespace *ns)
  		ret = register_blocking_lsm_notifier
  						(&ns->ima_lsm_policy_notifier);
  		if (ret)
-			return ret;
+			goto destroy_cache;
  	}
set_bit(IMA_NS_ACTIVE, &ns->ima_ns_flags); return 0;
+
+destroy_cache:
+	kmem_cache_destroy(ns->ns_status_cache);
+	return ret;
  }
int __init ima_ns_init(void)

Since it doesn't make sense for me to carry a fix patch in this series I will merge this patch into the respective patch.

Thanks,
   Stefan



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux Kernel]     [Linux Kernel Hardening]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux