From: SJ Park <sj@kernel.org>
To: sashiko-bot@kernel.org
Cc: SJ Park <sj@kernel.org>, damon@lists.linux.dev
Subject: Re: [PATCH 6.1.y v3 2/2] mm/damon/core: fix unconditionally skip last region
Date: Sat, 10 Oct 2026 00:12:33 -0700 [thread overview]
Message-ID: <20261010071234.9041-1-sj@kernel.org> (raw)
In-Reply-To: <sashiko-outbox-166285@kernel.org>
On Sat, 10 Oct 2026 06:46:00 +0000 sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] mm: damon: use-after-free and permanent scheme disablement on target destroy
> --
>
> commit c97d3ff78284ee81310d99deee85b79f32b561d5
> Author: Liew Rui Yan <aethernet65535@gmail.com>
>
> mm/damon/core: fix unconditionally skip last region
>
> Once quota set, the charge_{target,addr}_from unconditionally skips and
> resets at the last region of the tracked target, so the last region can be
> skipped even when it has not been processed.
>
> Link: https://lore.kernel.org/20260908134739.96919-1-sj@kernel.org
>
> > diff --git a/mm/damon/core.c b/mm/damon/core.c
> > index b5c85e6488596..1b9fb00405cfb 100644
> > --- a/mm/damon/core.c
> > +++ b/mm/damon/core.c
> > @@ -768,14 +769,11 @@ static void damon_do_apply_schemes(struct damon_ctx *c,
> > if (quota->charge_target_from) {
> > if (t != quota->charge_target_from)
> > continue;
>
> [Severity: High]
> Does this code have a use-after-free and permanent scheme disablement issue
> when a target is destroyed?
>
> If the user dynamically removes a target via sysfs, damon_sysfs_set_targets()
> calls damon_destroy_target() which frees the target memory:
>
> mm/damon/sysfs.c:damon_sysfs_set_targets() {
> ...
> } else {
> if (damon_target_has_pid(ctx))
> put_pid(t->pid);
> damon_destroy_target(t);
> }
> ...
> }
>
> mm/damon/core.c:damon_destroy_target() {
> damon_del_target(t);
> damon_free_target(t);
> }
>
> Existing schemes are updated in-place via damon_sysfs_update_scheme(), which
> does not clear the charge_target_from pointer, leaving a dangling pointer in
> the scheme.
>
> Immediately after, when kdamond_apply_schemes() runs in the same thread,
> damon_do_apply_schemes() compares the valid remaining targets against this
> dangling pointer (if (t != quota->charge_target_from)). Since it does not
> match the remaining targets, it unconditionally executes continue, skipping
> the scheme for all regions.
>
> Because a matching target is never reached, the pointer is never reset (the
> code cannot reach the clean_charge_from_skip label). This results in
> permanent disablement of the scheme and persistent use-after-free comparisons
> against the dangling pointer.
This is a pre-existing issue that also exists in the mainline. I will
separately work on this.
>
> > - if (r == damon_last_region(t)) {
> > - quota->charge_target_from = NULL;
> > - quota->charge_addr_from = 0;
> > - continue;
> > - }
> > if (quota->charge_addr_from &&
> > - r->ar.end <= quota->charge_addr_from)
> > - continue;
> > + r->ar.end <= quota->charge_addr_from) {
> > + skip = true;
> > + goto clean_charge_from_skip;
> > + }
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20261010063042.8611-1-sj@kernel.org?part=2
Thanks,
SJ
next prev parent reply other threads:[~2026-10-10 7:12 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <2026092949-surpass-thimble-02a8@gregkh>
2026-09-30 9:48 ` [PATCH 6.1.y] mm/damon/core: fix unconditionally skip last region SJ Park
2026-09-30 10:05 ` sashiko-bot
2026-09-30 10:23 ` SJ Park
2026-10-02 14:19 ` Sasha Levin
2026-10-09 14:48 ` [PATCH 6.1.y v2 0/2] mm/damon/core: fix last region handling of damos_skip_charged_regions() SJ Park
2026-10-09 14:48 ` [PATCH 6.1.y v2 1/2] mm/damon/core: do non-safe region walk on kdamond_apply_schemes() SJ Park
2026-10-09 14:56 ` sashiko-bot
2026-10-09 15:09 ` SJ Park
2026-10-09 14:48 ` [PATCH 6.1.y v2 2/2] mm/damon/core: fix unconditionally skip last region SJ Park
2026-10-09 15:04 ` sashiko-bot
2026-10-09 15:11 ` SJ Park
2026-10-10 6:30 ` [PATCH 6.1.y v3 0/2] mm/damon/core: fix last region handling of damos_skip_charged_regions() SJ Park
2026-10-10 6:30 ` [PATCH 6.1.y v3 1/2] mm/damon/core: do non-safe region walk on kdamond_apply_schemes() SJ Park
2026-10-10 6:41 ` sashiko-bot
2026-10-10 7:11 ` SJ Park
2026-10-10 6:30 ` [PATCH 6.1.y v3 2/2] mm/damon/core: fix unconditionally skip last region SJ Park
2026-10-10 6:46 ` sashiko-bot
2026-10-10 7:12 ` SJ Park [this message]
2026-10-11 16:48 ` [PATCH 6.1.y v3 0/2] mm/damon/core: fix last region handling of damos_skip_charged_regions() Sasha Levin
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=20261010071234.9041-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 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.