From: sashiko-bot@kernel.org
To: "Petr Pavlu" <petr.pavlu@suse.com>
Cc: linux-modules@vger.kernel.org
Subject: Re: [PATCH v3 3/6] module/dups: Avoid unnecessary kmod_dup_req allocations
Date: Thu, 06 Aug 2026 09:42:02 +0000 [thread overview]
Message-ID: <20260806094202.A5A981F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260806-module-stats-rcu-v3-3-2b0331106f00@suse.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] A `request_module_nowait()` call can prematurely complete a concurrent `request_module(wait=true)` request, causing synchronous waiters to proceed before the module is actually loaded.
--
--- Patch [3]: [PATCH v3 3/6] module/dups: Avoid unnecessary kmod_dup_req allocations ---
commit c39253dbe61d24363b967a87af56bd7ef5c557ff
Author: Petr Pavlu <petr.pavlu@suse.com>
module/dups: Avoid unnecessary kmod_dup_req allocations
This commit defers the allocation of kmod_dup_req until it is actually
needed, instead of preallocating it before taking the mutex. It introduces
a helper alloc_kmod_req() to simplify the initialization process.
> diff --git a/kernel/module/dups.c b/kernel/module/dups.c
> --- a/kernel/module/dups.c
> +++ b/kernel/module/dups.c
[ ... ]
> @@ -138,7 +141,6 @@ bool kmod_dup_request_exists_wait(char *module_name, bool wait, int *dup_ret)
> * If a prior request to this one came through with
> * request_module() though, then a request_module_nowait()
> * would benefit from duplicate detection.
> */
> if (!wait) {
> - kfree(new_kmod_req);
> pr_debug("New request_module_nowait() for %s -- cannot track duplicates for this request\n", module_name);
> mutex_unlock(&kmod_dup_mutex);
> return false;
[Severity: High]
This is a pre-existing issue, but does a request_module_nowait() call risk
prematurely completing a concurrent request_module() call that is waiting?
If Thread B calls request_module_nowait("foo"), it doesn't create a
tracking entry because wait is false. If Thread A subsequently calls
request_module("foo") with wait=true, it creates the tracking entry and
blocks for processing. If Thread C then calls request_module("foo") with
wait=true, it finds Thread A's entry and blocks waiting for it.
Because Thread B used nowait, its execution finishes quickly (waiting only
for the modprobe binary to exec) and returns 0. It then unconditionally
announces completion:
kernel/module/dups.c:kmod_dup_request_announce() {
...
kmod_req = kmod_dup_request_lookup(module_name);
if (!kmod_req || completion_done(&kmod_req->first_req_done)) {
mutex_unlock(&kmod_dup_mutex);
return;
}
kmod_req->dup_ret = ret;
/* Inform all duplicate waiters to check the return value. */
complete_all(&kmod_req->first_req_done);
...
}
Won't this find Thread A's tracking entry, assign dup_ret = 0, and wake up
Thread C prematurely while the module is still being loaded in the
background by Thread A?
If Thread C receives a success return value before the module is actually
fully loaded and initialized, could this cause drivers or subsystems to
attempt to use uninitialized module symbols or hardware features?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260806-module-stats-rcu-v3-0-2b0331106f00@suse.com?part=3
next prev parent reply other threads:[~2026-08-06 9:42 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 9:10 [PATCH v3 0/6] module/dups: Fix a use-after-free and improve the code Petr Pavlu
2026-08-06 9:10 ` [PATCH v3 1/6] module/dups: Inform duplicate requests about the result directly Petr Pavlu
2026-08-06 9:25 ` sashiko-bot
2026-08-06 11:19 ` Petr Pavlu
2026-08-06 9:10 ` [PATCH v3 2/6] module/dups: Fix use-after-free in kmod_dup_req lifetime handling Petr Pavlu
2026-08-06 9:10 ` [PATCH v3 3/6] module/dups: Avoid unnecessary kmod_dup_req allocations Petr Pavlu
2026-08-06 9:42 ` sashiko-bot [this message]
2026-08-06 11:20 ` Petr Pavlu
2026-08-06 9:10 ` [PATCH v3 4/6] module/dups: Use scope-based cleanup helpers Petr Pavlu
2026-08-06 9:10 ` [PATCH v3 5/6] module/dups: Use strcmp() to compare module names Petr Pavlu
2026-08-06 9:10 ` [PATCH v3 6/6] module/dups: Clean up includes Petr Pavlu
2026-08-06 11:53 ` [PATCH v3 0/6] module/dups: Fix a use-after-free and improve the code Petr Pavlu
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=20260806094202.A5A981F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=petr.pavlu@suse.com \
--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.