All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Hao Ge" <hao.ge@linux.dev>
Cc: linux-modules@vger.kernel.org
Subject: Re: [PATCH] module: fix lost error code from codetag_load_module()
Date: Mon, 24 Aug 2026 02:03:34 +0000	[thread overview]
Message-ID: <20260824020334.E8E991F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260824014736.35026-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 call to codetag_unload_module() in the error path leaves dangling module pointers in codetag_types IDR.
--

--- Patch [1]: [PATCH] module: fix lost error code from codetag_load_module() ---
commit 5006baafc1e00091b0abb9c8d393876e887ccb31
Author: Hao Ge <hao.ge@linux.dev>

module: fix lost error code from codetag_load_module()

This commit fixes a bug where the error code from codetag_load_module()
was previously lost. It ensures load_module() correctly captures the error
and aborts module loading upon failure.

> --- a/kernel/module/main.c
> +++ b/kernel/module/main.c
> @@ -3581,7 +3581,8 @@ static int load_module(struct load_info *info, const char __user *uargs,
>  			goto sysfs_cleanup;
>  	}
>  
> -	if (codetag_load_module(mod))
> +	err = codetag_load_module(mod);
> +	if (err)
>  		goto sysfs_cleanup;

[Severity: High]
This is a pre-existing issue, but by fixing the error path here, we might
expose a use-after-free bug during module load failures.

If codetag_load_module() fails partway through the list of codetag_types:

lib/codetag.c:codetag_load_module() {
	...
	list_for_each_entry(cttype, &codetag_types, link) {
		ret = codetag_module_init(cttype, mod);
		if (ret)
			break;
	}
	...
}

It returns an error without rolling back the types that were already
successfully initialized. We then jump to sysfs_cleanup, which eventually
calls module_deallocate() in the free_module block to free the module memory.

However, there is no call to codetag_unload_module() anywhere in this cleanup
path to clean up the dangling references from the codetag_types IDR.

Will this leave dangling pointers that result in a use-after-free dereference
of the freed module memory when codetags are later iterated (for example,
when reading from /proc/allocinfo)?

lib/codetag.c:codetag_next_ct() {
	...
			ct = get_first_module_ct(cmod);
	...
}

>  
>  	/* Get rid of temporary copy. */

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260824014736.35026-1-hao.ge@linux.dev?part=1

  reply	other threads:[~2026-08-24  2:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-24  1:47 [PATCH] module: fix lost error code from codetag_load_module() Hao Ge
2026-08-24  2:03 ` sashiko-bot [this message]
2026-08-24 16:26 ` Suren Baghdasaryan
2026-08-25  8:54 ` Aaron Tomlin
2026-08-25 19:36 ` Bradley Morgan
2026-08-26  9:24 ` Petr Pavlu
2026-08-27  0:11   ` Suren Baghdasaryan
2026-08-27  0:23   ` Bradley Morgan
2026-08-27  3:15   ` 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=20260824020334.E8E991F000E9@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.