Message ID | 20221226024335.767587-1-denis.semakin@huawei.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [RFC,v2] ima: fix possible memory leak in cache allocating for namespace | expand |
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@huawei.com> > Signed-off-by: Ilya Hanov <ilya.hanov@huawei-partners.com> > --- > 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
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)