The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] lkdtm/core: fix resource leaks on module init error path
@ 2026-07-01 15:14 Jiangshan Yi
  2026-08-05  1:57 ` kernel test robot
  2026-08-05  7:11 ` kernel test robot
  0 siblings, 2 replies; 4+ messages in thread
From: Jiangshan Yi @ 2026-07-01 15:14 UTC (permalink / raw)
  To: kees, arnd, gregkh; +Cc: linux-kernel, 13667453960, Jiangshan Yi

When lkdtm_register_cpoint() fails during lkdtm_module_init(), the code
jumps to out_err:, which only calls debugfs_remove_recursive() and
returns the error code. Since module_init() returned an error, the
kernel does not load the module and never invokes module_exit(), so
lkdtm_module_exit() is not called.

As a result, everything allocated earlier in the init path is leaked:

  - the lkdtm_kernel_info string allocated by kasprintf(),
  - the four kmem_caches created by lkdtm_usercopy_init() and
    lkdtm_heap_init().

The corresponding cleanup — lkdtm_heap_exit(), lkdtm_usercopy_exit()
and kfree(lkdtm_kernel_info) — lives only in lkdtm_module_exit() and
is therefore never executed on this failure path.

Free these resources on the error path before returning, mirroring the
cleanup done in lkdtm_module_exit().

Signed-off-by: Jiangshan Yi <yijiangshan@kylinos.cn>
---
 drivers/misc/lkdtm/core.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/misc/lkdtm/core.c b/drivers/misc/lkdtm/core.c
index ededa32d6744..d741c6051408 100644
--- a/drivers/misc/lkdtm/core.c
+++ b/drivers/misc/lkdtm/core.c
@@ -468,6 +468,9 @@ static int __init lkdtm_module_init(void)
 
 out_err:
 	debugfs_remove_recursive(lkdtm_debugfs_root);
+	lkdtm_heap_exit();
+	lkdtm_usercopy_exit();
+	kfree(lkdtm_kernel_info);
 	return ret;
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-08-05  7:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-01 15:14 [PATCH] lkdtm/core: fix resource leaks on module init error path Jiangshan Yi
2026-08-05  1:57 ` kernel test robot
2026-08-05  2:27   ` Jiangshan Yi
2026-08-05  7:11 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox