From: sashiko-bot@kernel.org
To: "Hao Ge" <hao.ge@linux.dev>
Cc: linux-modules@vger.kernel.org
Subject: Re: [PATCH v2] module: fix lost error code from codetag_load_module()
Date: Thu, 27 Aug 2026 03:17:01 +0000 [thread overview]
Message-ID: <20260827031701.9FE7B1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260827030503.49171-1-hao.ge@linux.dev>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing `codetag_unload_module(mod)` on `codetag_load_module()` failure permanently strands partially initialized codetags, causing a Use-After-Free when the freed module is subsequently accessed.
--
commit 46e63afac7b776756489b1e2ad6cec3cf1e11513
Author: Hao Ge <hao.ge@linux.dev>
module: fix lost error code from codetag_load_module()
If codetag_load_module() fails, err is not set to reflect the failure
and load_module() returns 0 after the module has been torn down.
> diff --git a/kernel/module/main.c b/kernel/module/main.c
> index d0e1e0bd2ad06..c1b34dc1e89ac 100644
> --- a/kernel/module/main.c
> +++ b/kernel/module/main.c
> @@ -3581,8 +3581,9 @@ static int load_module(struct load_info *info, const char __user *uargs,
> goto sysfs_cleanup;
> }
>
> - if (codetag_load_module(mod))
> - goto sysfs_cleanup;
> + err = codetag_load_module(mod);
> + if (err)
> + goto livepatch_cleanup;
[Severity: High]
This isn't a bug introduced by this patch, but missing codetag_unload_module()
on codetag_load_module() failure permanently strands partially initialized
codetags, causing a use-after-free when the freed module is subsequently
accessed.
If a module load is initiated, and codetag_load_module() iterates through
registered codetag_types:
lib/codetag.c:codetag_load_module() {
...
ret = codetag_module_init(cttype, mod);
if (ret)
break;
...
}
If an early iteration succeeds but a subsequent one fails (e.g., kmalloc
failure inside codetag_module_init()), codetag_load_module() breaks and
returns the error without unwinding previously allocated cmod entries.
load_module() receives the error, jumps to livepatch_cleanup and eventually
calls module_deallocate(mod, info) to free the module memory. However,
codetag_unload_module(mod) is never invoked on this error path, leaving
cmod entries pointing to freed module memory inside the successfully
initialized cttype->mod_idr structures.
When subsequent codetag operations (like reading /proc/allocinfo) iterate
over cttype->mod_idr, they will access the freed module memory.
Should this error path invoke codetag_unload_module(mod) to clean up the
partially registered state before tearing down and freeing the module
memory?
>
> /* Get rid of temporary copy. */
> free_copy(info, flags);
> @@ -3592,6 +3593,9 @@ static int load_module(struct load_info *info, const char __user *uargs,
>
> return do_init_module(mod);
>
> + livepatch_cleanup:
> + if (is_livepatch_module(mod))
> + free_module_elf(mod);
> sysfs_cleanup:
> mod_sysfs_teardown(mod);
> coming_cleanup:
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260827030503.49171-1-hao.ge@linux.dev?part=1
next prev parent reply other threads:[~2026-08-27 3:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-27 3:05 [PATCH v2] module: fix lost error code from codetag_load_module() Hao Ge
2026-08-27 3:17 ` sashiko-bot [this message]
2026-09-07 19:42 ` Daniel Gomez
2026-09-08 9:50 ` Hao Ge
2026-09-09 22:00 ` Daniel Gomez
2026-09-10 3:17 ` Hao Ge
2026-09-10 3:28 ` Hao Ge
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=20260827031701.9FE7B1F00A3A@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.