From: sashiko-bot@kernel.org
To: "Hao Ge" <hao.ge@linux.dev>
Cc: linux-modules@vger.kernel.org
Subject: Re: [RFC PATCH 1/3] alloc_tag: skip percpu counter allocation when profiling is disabled
Date: Thu, 13 Aug 2026 09:49:52 +0000 [thread overview]
Message-ID: <20260813094952.D2FFB1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260813093421.135230-2-hao.ge@linux.dev>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing error code assignment when codetag_load_module() fails in load_module().
- [High] Use-After-Free and memory leak due to missing codetag_unload_module() on the module load error path.
--
--- Patch [1]: [RFC PATCH 1/3] alloc_tag: skip percpu counter allocation when profiling is disabled ---
commit 355b88475bea314f9aab64a9aa73da39a0d2bcf0
Author: Hao Ge <hao.ge@linux.dev>
alloc_tag: skip percpu counter allocation when profiling is disabled
After shutdown_mem_profiling() clears mem_profiling_support,
needs_section_mem() returns false, so later modules have their codetag
section placed as regular data and never enter the alloc_tag maple tree.
This patch returns CODETAG_MODULE_EXCLUDED when profiling is off to skip
percpu counter allocation.
> diff --git a/lib/codetag.c b/lib/codetag.c
> index a9cda4c962a30..8506ecab9ea70 100644
> --- a/lib/codetag.c
> +++ b/lib/codetag.c
[ ... ]
> @@ -238,9 +238,10 @@ static int codetag_module_init(struct codetag_type *cttype, struct module *mod)
> }
> up_write(&cttype->mod_lock);
>
> - if (err < 0) {
> + if (err) {
> + /* Error or excluded: cmod is dropped, free it. */
> kfree(cmod);
> - return err;
> + return err < 0 ? err : 0;
> }
>
> return 0;
[Severity: High]
This is a pre-existing issue, but if codetag_module_init() fails midway through
the codetag types, does it leave the module registered in the previously
initialized types?
lib/codetag.c:codetag_load_module() {
...
list_for_each_entry(cttype, &codetag_types, link) {
ret = codetag_module_init(cttype, mod);
if (ret)
break;
}
...
}
If the loop breaks on an error, the successfully initialized types are not
unwound. When load_module() in kernel/module/main.c handles this error, it
jumps to sysfs_cleanup and eventually frees the module, but misses a call to
codetag_unload_module(mod).
Could this lead to a use-after-free or a memory leak when traversing the IDR
later, since the freed module is still registered?
[Severity: High]
This is another pre-existing issue. Is the error code lost in load_module()
when codetag_load_module() fails?
kernel/module/main.c:load_module() {
...
if (codetag_load_module(mod))
goto sysfs_cleanup;
...
}
Since err is not assigned before jumping to sysfs_cleanup, would the syscall
incorrectly return 0 (success) even though the module failed to load and was
destroyed on the error path?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260813093421.135230-1-hao.ge@linux.dev?part=1
next prev parent reply other threads:[~2026-08-13 9:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-13 9:34 [RFC PATCH 0/3] alloc_tag: fix races and a leak around shutdown_mem_profiling() Hao Ge
2026-08-13 9:34 ` [RFC PATCH 1/3] alloc_tag: skip percpu counter allocation when profiling is disabled Hao Ge
2026-08-13 9:49 ` sashiko-bot [this message]
2026-08-13 9:34 ` [RFC PATCH 2/3] module: move codetag section placement decision to layout_sections() Hao Ge
2026-08-13 9:54 ` sashiko-bot
2026-08-13 9:34 ` [RFC PATCH 3/3] alloc_tag: remove /proc/allocinfo outside of mod_lock Hao Ge
2026-08-13 9:57 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260813094952.D2FFB1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=hao.ge@linux.dev \
--cc=linux-modules@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.