From: sashiko-bot@kernel.org
To: "SeongJae Park" <sj@kernel.org>
Cc: damon@lists.linux.dev
Subject: Re: [PATCH v3 2/3] mm/damon/lru_sort: detect and use fresh enabled and kdamond_pid values
Date: Sun, 19 Apr 2026 17:28:17 +0000 [thread overview]
Message-ID: <20260419172817.E2FA2C2BCAF@smtp.kernel.org> (raw)
In-Reply-To: <20260419161003.79176-3-sj@kernel.org>
Sashiko AI review found 1 potential issue(s):
- [High] Loading the module with the `enabled=Y` parameter causes a NULL pointer dereference.
--
commit e25c111d55f5d7c99165dbc8b59a5261d640ada5
Author: SeongJae Park <sj@kernel.org>
mm/damon/lru_sort: detect and use fresh enabled and kdamond_pid values
This commit updates DAMON_LRU_SORT to dynamically detect and use the
current running status of the kdamond thread for the enabled and
kdamond_pid parameters. This prevents users from seeing stale values or
being unable to restart kdamond if it stops due to unintentional events.
> diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c
> index 554559d729760..8494040b1ee48 100644
> --- a/mm/damon/lru_sort.c
> +++ b/mm/damon/lru_sort.c
[ ... ]
> static int damon_lru_sort_enabled_store(const char *val,
> const struct kernel_param *kp)
> {
> - bool is_enabled = enabled;
> - bool enable;
> int err;
>
> - err = kstrtobool(val, &enable);
> + err = kstrtobool(val, &enabled);
> if (err)
> return err;
>
> - if (is_enabled == enable)
> + if (damon_lru_sort_enabled() == enabled)
> return 0;
>
> /* Called before init function. The function will handle this. */
> if (!damon_initialized())
> - goto set_param_out;
> + return 0;
>
> - err = damon_lru_sort_turn(enable);
> - if (err)
> - return err;
> + return damon_lru_sort_turn(enabled);
> +}
This isn't a bug introduced by this patch, but does this code cause a NULL
pointer dereference if the module is dynamically loaded with enabled=Y?
When the module is loaded as a dynamically loadable module with the
enabled=Y parameter, the kernel's module loader parses the parameters
before damon_lru_sort_init() runs.
This invokes damon_lru_sort_enabled_store(). Because damon_core (a module
dependency) is already loaded, damon_initialized() evaluates to true,
bypassing the safety guard.
The function proceeds to call damon_lru_sort_turn(true), which eventually
calls damon_lru_sort_apply_parameters(). This invokes:
damon_commit_ctx(ctx, param_ctx);
At this point, the global ctx pointer is still NULL because it is only
allocated later in damon_lru_sort_init(). damon_commit_ctx() unconditionally
dereferences the pointer:
dst->maybe_corrupted = true;
causing a direct NULL pointer dereference and a kernel panic.
Should this check use !ctx instead of !damon_initialized() to properly
defer execution to the init function?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260419161003.79176-1-sj@kernel.org?part=2
next prev parent reply other threads:[~2026-04-19 17:28 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-19 16:09 [PATCH v3 0/3] mm/damon/modules: detect and use fresh status SeongJae Park
2026-04-19 16:10 ` [PATCH v3 1/3] mm/damon/reclaim: detect and use fresh enabled and kdamond_pid values SeongJae Park
2026-04-19 16:48 ` sashiko-bot
2026-04-19 16:52 ` SeongJae Park
2026-04-19 16:10 ` [PATCH v3 2/3] mm/damon/lru_sort: " SeongJae Park
2026-04-19 17:28 ` sashiko-bot [this message]
2026-04-19 18:12 ` SeongJae Park
2026-04-19 16:10 ` [PATCH v3 3/3] mm/damon/stat: detect and use fresh enabled value SeongJae Park
2026-04-19 17:51 ` sashiko-bot
2026-04-19 18:19 ` 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=20260419172817.E2FA2C2BCAF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=damon@lists.linux.dev \
--cc=sashiko@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 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.