From: sashiko-bot@kernel.org
To: "SeongJae Park" <sj@kernel.org>
Cc: damon@lists.linux.dev
Subject: Re: [RFC PATCH 2/2] mm/damonn/lru_sort: handle ctx allocation failure
Date: Thu, 28 May 2026 07:29:55 +0000 [thread overview]
Message-ID: <20260528072956.650801F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260528061110.2172-3-sj@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] Module load parameter 'enabled' causes unconditional module load failure.
Pre-existing issues:
- [High] TOCTOU race condition between sysfs store and module initialization leading to data corruption.
--
commit 98350211104d3088f79c58844d29a85c013ac178
Author: SeongJae Park <sj@kernel.org>
mm/damonn/lru_sort: handle ctx allocation failure
This commit attempts to fix a NULL pointer dereference in
damon_lru_sort_enabled_store() by returning -ENOMEM if the damon_ctx object
failed to allocate during initialization.
> diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c
> index eca88ed941b32..8298c6001fd09 100644
> --- a/mm/damon/lru_sort.c
> +++ b/mm/damon/lru_sort.c
> @@ -476,6 +476,10 @@ static int damon_lru_sort_enabled_store(const char *val,
> if (!damon_initialized())
> return 0;
>
> + /* damon_modules_new_paddr_ctx_target() in the init function failed. */
> + if (!ctx)
> + return -ENOMEM;
> +
[Severity: High]
Will this cause an unconditional module load failure when passing the
enabled parameter at load time?
When loading the module with modprobe damon_lru_sort enabled=Y, the kernel
calls parse_args() before the module's init function damon_lru_sort_init()
is executed.
At this point, damon_initialized() returns true because the damon_core
dependency is already initialized, but ctx is still NULL since the module
init function hasn't run yet.
Could this evaluate to true and return -ENOMEM, causing the entire module
loading process to fail and abort?
> return damon_lru_sort_turn(enabled);
> }
[Severity: High]
This isn't a bug introduced by this patch, but is there a TOCTOU race
condition here between the sysfs store and module initialization?
The kernel exposes module parameter sysfs files via mod_sysfs_setup()
before executing the module's initcall do_init_module().
If a userspace process writes to this sysfs file concurrently while
damon_lru_sort_init() is executing, could it trigger the following sequence?
Userspace sysfs write happens right after damon_lru_sort_init() allocates
ctx. This callback sees ctx != NULL and calls damon_lru_sort_turn(true).
Concurrently, damon_lru_sort_init() continues, reads enabled == true
(updated by the sysfs store), and also calls damon_lru_sort_turn(true).
Does this concurrent execution of damon_lru_sort_apply_parameters() and
damon_commit_ctx() on the same ctx without locks lead to list corruption
or double frees?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260528061110.2172-1-sj@kernel.org?part=2
next prev parent reply other threads:[~2026-05-28 7:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-28 6:11 [RFC PATCH 0/2] mm/damon/{reclaim,lru_sort}: handle ctx allocation failures SeongJae Park
2026-05-28 6:11 ` [RFC PATCH 1/2] mm/damon/reclaim: handle ctx allocation failure SeongJae Park
2026-05-28 6:50 ` sashiko-bot
2026-05-28 14:00 ` SeongJae Park
2026-05-28 6:11 ` [RFC PATCH 2/2] mm/damonn/lru_sort: " SeongJae Park
2026-05-28 7:29 ` sashiko-bot [this message]
2026-05-28 14:02 ` SeongJae Park
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=20260528072956.650801F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=damon@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sj@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox