From: sashiko-bot@kernel.org
To: "Cosmin Tanislav" <cosmin-gabriel.tanislav.xa@renesas.com>
Cc: vkoul@kernel.org, dmaengine@vger.kernel.org, Frank.Li@kernel.org
Subject: Re: [PATCH] dmaengine: dmatest: fix race between wait for thread and thread start
Date: Mon, 17 Aug 2026 19:40:34 +0000 [thread overview]
Message-ID: <20260817194034.C27C41F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260817192557.437474-1-cosmin-gabriel.tanislav.xa@renesas.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [Medium] TOCTOU race in pending flag update allows premature wait completion.
Pre-existing issues:
- [High] Lockless list traversal in wait condition causes Use-After-Free kernel crash.
--
--- Patch [1]: [PATCH] dmaengine: dmatest: fix race between wait for thread and thread start ---
commit 6a5e8f24ddb4b9e471d1801d58f2c91b07f83d13
Author: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
dmaengine: dmatest: fix race between wait for thread and thread start
This commit addresses a race condition in the dmatest module where the wait
module parameter could cause an early exit if the worker thread has not yet
started. It attempts to resolve this by clearing the pending flag immediately
after waking up the worker thread.
> When the wait module parameter is set to true, dmatest_init() waits for
> the !is_threaded_test_run() condition to become true.
[Severity: High]
This is a pre-existing issue, but does evaluating this condition repeatedly
in wait_event() without holding a lock lead to a use-after-free?
Looking at is_threaded_test_run(), it iterates over info->channels and
dtc->threads without holding info->lock:
drivers/dma/dmatest.c:is_threaded_test_run() {
...
list_for_each_entry(dtc, &info->channels, node) {
...
}
...
}
If stop_threaded_test() is executed concurrently via sysfs, it can modify
the list nodes. Since the traversal in is_threaded_test_run() happens
without holding the lock, could this hit freed memory and result in a
direct use-after-free?
> diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c
> index 2ae3469397f37..2d2eb43eee7cc 100644
> --- a/drivers/dma/dmatest.c
> +++ b/drivers/dma/dmatest.c
[ ... ]
> @@ -1142,6 +1141,7 @@ static void run_pending_tests(struct dmatest_info *info)
> thread_count = 0;
> list_for_each_entry(thread, &dtc->threads, node) {
> wake_up_process(thread->task);
> + thread->pending = false;
[Severity: Medium]
Could this order of operations introduce a race window?
If wake_up_process() makes the thread runnable immediately, could a
concurrent wait_event() evaluate a stale pending state before it is
cleared here?
Would swapping these operations to clear the pending flag strictly before
the wakeup prevent concurrent wait_event() evaluations from exiting
prematurely?
> thread_count++;
> }
> pr_info("Started %u threads using %s\n",
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260817192557.437474-1-cosmin-gabriel.tanislav.xa@renesas.com?part=1
next prev parent reply other threads:[~2026-08-17 19:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-17 19:25 [PATCH] dmaengine: dmatest: fix race between wait for thread and thread start Cosmin Tanislav
2026-08-17 19:40 ` sashiko-bot [this message]
2026-08-17 20:01 ` Cosmin-Gabriel Tanislav
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=20260817194034.C27C41F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=cosmin-gabriel.tanislav.xa@renesas.com \
--cc=dmaengine@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vkoul@kernel.org \
/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.