* [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* Re: [PATCH] lkdtm/core: fix resource leaks on module init error path
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
1 sibling, 1 reply; 4+ messages in thread
From: kernel test robot @ 2026-08-05 1:57 UTC (permalink / raw)
To: Jiangshan Yi, kees, arnd, gregkh
Cc: oe-kbuild-all, linux-kernel, 13667453960, Jiangshan Yi
Hi Jiangshan,
kernel test robot noticed the following build warnings:
[auto build test WARNING on char-misc/char-misc-testing]
[also build test WARNING on char-misc/char-misc-next char-misc/char-misc-linus soc/for-next linus/master v7.2-rc6 next-20260804]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Jiangshan-Yi/lkdtm-core-fix-resource-leaks-on-module-init-error-path/20260804-225548
base: char-misc/char-misc-testing
patch link: https://lore.kernel.org/r/20260701151438.3772375-1-yijiangshan%40kylinos.cn
patch subject: [PATCH] lkdtm/core: fix resource leaks on module init error path
config: i386-allmodconfig (https://download.01.org/0day-ci/archive/20260805/202608050915.CRrKhB4T-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260805/202608050915.CRrKhB4T-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202608050915.CRrKhB4T-lkp@intel.com/
All warnings (new ones prefixed by >>, old ones prefixed by <<):
>> WARNING: modpost: drivers/misc/lkdtm/lkdtm: section mismatch in reference: lkdtm_module_init+0x221 (section: .init.text) -> lkdtm_heap_exit (section: .exit.text)
>> WARNING: modpost: drivers/misc/lkdtm/lkdtm: section mismatch in reference: lkdtm_module_init+0x226 (section: .init.text) -> lkdtm_usercopy_exit (section: .exit.text)
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Re: [PATCH] lkdtm/core: fix resource leaks on module init error path
2026-08-05 1:57 ` kernel test robot
@ 2026-08-05 2:27 ` Jiangshan Yi
0 siblings, 0 replies; 4+ messages in thread
From: Jiangshan Yi @ 2026-08-05 2:27 UTC (permalink / raw)
To: lkp
Cc: 13667453960, arnd, gregkh, kees, linux-kernel, oe-kbuild-all,
yijiangshan
Hi,
Thanks for the build test report and for catching these section mismatch
warnings:
> > > WARNING: modpost: drivers/misc/lkdtm/lkdtm: section mismatch in reference: lkdtm_module_init+0x221 (section: .init.text) -> lkdtm_heap_exit (section: .exit.text)
> > > WARNING: modpost: drivers/misc/lkdtm/lkdtm: section mismatch in reference: lkdtm_module_init+0x226 (section: .init.text) -> lkdtm_usercopy_exit (section: .exit.text)
These warnings have already been addressed in the v2 of this patch,
posted at:
https://lore.kernel.org/all/20260730154911.3164527-1-yijiangshan@kylinos.cn/
In v2, the error-handling path in lkdtm_module_init() no longer
references the .exit.text cleanup helpers (lkdtm_heap_exit,
lkdtm_usercopy_exit), which resolves the section mismatch reported
by modpost.
Since the fix is part of a new version of the same patch rather than a
separate commit, I haven't added the Reported-by / Closes tags to
that version. However, your report was very helpful in confirming the
issue — thank you again for the testing.
Best regards,
Jiangshan Yi
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] lkdtm/core: fix resource leaks on module init error path
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 7:11 ` kernel test robot
1 sibling, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-08-05 7:11 UTC (permalink / raw)
To: Jiangshan Yi, kees, arnd, gregkh
Cc: oe-kbuild-all, linux-kernel, 13667453960, Jiangshan Yi
Hi Jiangshan,
kernel test robot noticed the following build warnings:
[auto build test WARNING on char-misc/char-misc-testing]
[also build test WARNING on char-misc/char-misc-next char-misc/char-misc-linus soc/for-next linus/master v7.2-rc6 next-20260804]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Jiangshan-Yi/lkdtm-core-fix-resource-leaks-on-module-init-error-path/20260804-225548
base: char-misc/char-misc-testing
patch link: https://lore.kernel.org/r/20260701151438.3772375-1-yijiangshan%40kylinos.cn
patch subject: [PATCH] lkdtm/core: fix resource leaks on module init error path
config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20260805/202608051446.cKZTkVXV-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 16.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260805/202608051446.cKZTkVXV-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202608051446.cKZTkVXV-lkp@intel.com/
All warnings (new ones prefixed by >>, old ones prefixed by <<):
WARNING: modpost: "saved_config" [vmlinux] is COMMON symbol
>> WARNING: modpost: vmlinux: section mismatch in reference: lkdtm_module_init+0x1ec (section: .init.text) -> lkdtm_heap_exit (section: .exit.text)
WARNING: modpost: vmlinux: section mismatch in reference: lkdtm_module_init+0x1f0 (section: .init.text) -> lkdtm_heap_exit (section: .exit.text)
>> WARNING: modpost: vmlinux: section mismatch in reference: lkdtm_module_init+0x1fc (section: .init.text) -> lkdtm_usercopy_exit (section: .exit.text)
WARNING: modpost: vmlinux: section mismatch in reference: lkdtm_module_init+0x200 (section: .init.text) -> lkdtm_usercopy_exit (section: .exit.text)
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [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