From: SJ Park <sj@kernel.org>
To: sashiko-bot@kernel.org
Cc: SJ Park <sj@kernel.org>, damon@lists.linux.dev
Subject: Re: [PATCH 4/6] samples/damon/mtier: handle damon_stop() failure
Date: Sun, 28 Jun 2026 15:35:21 -0700 [thread overview]
Message-ID: <20260628223522.100030-1-sj@kernel.org> (raw)
In-Reply-To: <20260628220957.5C1971F000E9@smtp.kernel.org>
On Sun, 28 Jun 2026 22:09:56 +0000 sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] Concurrent execution of module initialization and sysfs parameter write leads to Use-After-Free and NULL pointer dereferences.
> --
>
> commit f7efff971c5dc6b095a484211734bb0e2a54f858
> Author: SJ Park <sj@kernel.org>
>
> samples/damon/mtier: handle damon_stop() failure
>
> damon_sample_mtier_stop() assumes its damon_stop() call will always
> successfully stops the two DAMON contexts. Hence it deallocates the two
> DAMON contexts after the damon_stop() call.
>
> Link: https://lore.kernel.org/20260609014219.3013-1-sj@kernel.org
>
> > diff --git a/samples/damon/mtier.c b/samples/damon/mtier.c
> > --- a/samples/damon/mtier.c
> > +++ b/samples/damon/mtier.c
> > @@ -199,7 +199,8 @@ static int damon_sample_mtier_start(void)
> >
> > static void damon_sample_mtier_stop(void)
> > {
> > - damon_stop(ctxs, 2);
> > + damon_stop(ctxs, 1);
> > + damon_stop(&ctxs[1], 1);
> > damon_destroy_ctx(ctxs[0]);
>
> [Severity: High]
> This is a pre-existing issue, but does this function have a concurrency race
> with sysfs parameter writes during module initialization?
>
> Sysfs parameter nodes are exposed before module_init executes. If a user
> concurrently writes to the enabled sysfs parameter,
> damon_sample_mtier_enable_store() can call damon_sample_mtier_stop() while
> the module is still initializing:
>
> samples/damon/mtier.c:damon_sample_mtier_init() {
> ...
> err = damon_sample_mtier_start();
> ...
> }
>
> If damon_sample_mtier_stop() runs before ctxs is initialized, couldn't this
> lead to a NULL pointer dereference when we reach damon_destroy_ctx(ctxs[0])?
>
> Alternatively, if it runs concurrently with damon_sample_mtier_start(),
> could this cause a use-after-free since the module init function doesn't
> seem to hold a lock to serialize with the sysfs store callback?
Wrong. mtier is static module. Cannot be loaded on runtime. So I'm ignoring
this.
Thanks,
SJ
[...]
next prev parent reply other threads:[~2026-06-28 22:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-28 21:54 [PATCH 0/6] samples/damon: handle damon_{start,stop}() failures SJ Park
2026-06-28 21:54 ` [PATCH 1/6] samples/damon/wsse: handle damon_start() failure SJ Park
2026-06-28 21:54 ` [PATCH 2/6] samples/damon/prcl: " SJ Park
2026-06-28 21:54 ` [PATCH 3/6] samples/damon/mtier: " SJ Park
2026-06-28 21:54 ` [PATCH 4/6] samples/damon/mtier: handle damon_stop() failure SJ Park
2026-06-28 22:09 ` sashiko-bot
2026-06-28 22:35 ` SJ Park [this message]
2026-06-28 21:54 ` [PATCH 5/6] samples/damon/wsse: stop and free damon ctx when damon_call() fails SJ Park
2026-06-28 21:54 ` [PATCH 6/6] samples/damon/prcl: " SJ 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=20260628223522.100030-1-sj@kernel.org \
--to=sj@kernel.org \
--cc=damon@lists.linux.dev \
--cc=sashiko-bot@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