From: sashiko-bot@kernel.org
To: "Petr Pavlu" <petr.pavlu@suse.com>
Cc: linux-modules@vger.kernel.org
Subject: Re: [PATCH v3 1/6] module/dups: Inform duplicate requests about the result directly
Date: Thu, 06 Aug 2026 09:25:33 +0000 [thread overview]
Message-ID: <20260806092534.4B8E41F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260806-module-stats-rcu-v3-1-2b0331106f00@suse.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Re-arming `delete_work` while it is currently executing leads to a Use-After-Free and timer corruption.
- [High] Waiters sleep in `wait_for_completion_state()` without holding a reference to `kmod_req`, allowing `delete_work` to free the structure out from under them.
--
--- Patch [1]: [PATCH v3 1/6] module/dups: Inform duplicate requests about the result directly ---
commit b996b7173ceb4926f129328065b0224c2ccfe2d2
Author: Petr Pavlu <petr.pavlu@suse.com>
module/dups: Inform duplicate requests about the result directly
This patch removes the complete_work workqueue item that was used to delay
the completion signal. It updates kmod_dup_request_announce() to call
complete_all() and then immediately queue delete_work to clean up the entry.
> diff --git a/kernel/module/dups.c b/kernel/module/dups.c
> index 8b6f8f177de4f..45080f451e5c6 100644
> --- a/kernel/module/dups.c
> +++ b/kernel/module/dups.c
[ ... ]
> @@ -230,17 +205,17 @@ void kmod_dup_request_announce(char *module_name, int ret)
>
> kmod_req->dup_ret = ret;
>
> + /* Inform all duplicate waiters to check the return value. */
> + complete_all(&kmod_req->first_req_done);
> +
[Severity: High]
This isn't a bug introduced by this patch, but could this lead to a
use-after-free if a waiter thread is severely delayed after being woken up?
Waiters in kmod_dup_request_exists_wait() wait on this completion without
taking a reference to kmod_req:
kernel/module/dups.c:kmod_dup_request_exists_wait() {
...
wait_for_completion_state(&kmod_req->first_req_done, ...);
...
*dup_ret = kmod_req->dup_ret;
...
}
If a woken waiter is preempted, heavily throttled, or the system is suspended
for more than 60 seconds before it can return and read kmod_req->dup_ret,
delete_work will run and free kmod_req, causing a use-after-free when the
waiter resumes.
> /*
> - * If we complete() here we may allow duplicate threads
> - * to continue before the first one that submitted the
> - * request. We're in no rush also, given that each and
> - * every bounce back to userspace is slow we avoid that
> - * with a slight delay here. So queueue up the completion
> - * and let duplicates suffer, just wait a tad bit longer.
> - * There is no rush. But we also don't want to hold the
> - * caller up forever or introduce any boot delays.
> + * Now that we have allowed prior request_module() calls to go on
> + * with life, let's schedule deleting this entry. We don't have
> + * to do it right away, but we *eventually* want to do it so to not
> + * let this linger forever as this is just a boot optimization for
> + * possible abuses of vmalloc() incurred by finit_module() thrashing.
> */
> - queue_work(system_dfl_wq, &kmod_req->complete_work);
> + queue_delayed_work(system_dfl_wq, &kmod_req->delete_work, 60 * HZ);
[Severity: Critical]
This is a pre-existing issue, but could this queue_delayed_work() call lead
to a use-after-free and timer corruption if it races with an executing
delete_work?
If a previous delete_work worker wakes up, clears the WORK_STRUCT_PENDING bit,
and blocks on kmod_dup_mutex:
Worker Thread:
(clears WORK_STRUCT_PENDING)
mutex_lock(&kmod_dup_mutex); // blocked
Concurrent module load:
kmod_dup_request_announce()
mutex_lock(&kmod_dup_mutex);
...
queue_delayed_work(..., &kmod_req->delete_work, 60 * HZ);
mutex_unlock(&kmod_dup_mutex);
Because the pending bit was cleared by the worker, queue_delayed_work() will
successfully re-arm the timer.
When the worker thread acquires the mutex, it will unlink kmod_req and
unconditionally call kfree(). When the re-armed timer expires 60 seconds
later, the kernel will dereference the timer_list from freed memory, resulting
in a panic.
>
> out:
> mutex_unlock(&kmod_dup_mutex);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260806-module-stats-rcu-v3-0-2b0331106f00@suse.com?part=1
next prev parent reply other threads:[~2026-08-06 9:25 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 [this message]
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
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=20260806092534.4B8E41F000E9@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox