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.12.y v2] mm/damon/core: fix unconditionally skip last region
Date: Wed, 30 Sep 2026 03:34:07 -0700 [thread overview]
Message-ID: <20260930103408.59035-1-sj@kernel.org> (raw)
In-Reply-To: <20260930102649.7B2AE1F000FF@smtp.kernel.org>
On Wed, 30 Sep 2026 10:26:49 +0000 sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] mm: OOB dereference in damon_do_apply_schemes() on split failure
> --
>
> commit 61e0ff2e7385bb544355d1f3aa3598f7f8e9e1d0
> Author: Liew Rui Yan <aethernet65535@gmail.com>
>
> mm/damon/core: fix unconditionally skip last region
>
> This commit changes the logic in damos_skip_charged_region() to only reset
> charge_{target,addr}_from when the last region is reached. This is intended to
> ensure the last region is not skipped if it has not been fully 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 32737cc5f877b..cc7250f0936af 100644
> > --- a/mm/damon/core.c
> > +++ b/mm/damon/core.c
> [ ... ]
> > @@ -1322,37 +1322,41 @@ static bool damos_skip_charged_region(struct damon_target *t,
> > struct damon_region *r = *rp;
> > struct damos_quota *quota = &s->quota;
> > unsigned long sz_to_skip;
> > + bool skip = false;
> >
> > /* Skip previously charged regions */
> > if (quota->charge_target_from) {
> > if (t != quota->charge_target_from)
> > return true;
> > - if (r == damon_last_region(t)) {
> > - quota->charge_target_from = NULL;
> > - quota->charge_addr_from = 0;
> > - return true;
> > - }
> > if (quota->charge_addr_from &&
> > - r->ar.end <= quota->charge_addr_from)
> > - return true;
> > + r->ar.end <= quota->charge_addr_from) {
> > + skip = true;
> > + goto out;
> > + }
> >
> > if (quota->charge_addr_from && r->ar.start <
> > quota->charge_addr_from) {
> > sz_to_skip = ALIGN_DOWN(quota->charge_addr_from -
> > r->ar.start, DAMON_MIN_REGION);
> > if (!sz_to_skip) {
> > - if (damon_sz_region(r) <= DAMON_MIN_REGION)
> > - return true;
> > + if (damon_sz_region(r) <= DAMON_MIN_REGION) {
> > + skip = true;
> > + goto out;
> > + }
> > sz_to_skip = DAMON_MIN_REGION;
> > }
> > damon_split_region_at(t, r, sz_to_skip);
> > r = damon_next_region(r);
> > *rp = r;
> > + skip = false;
> > }
> > + }
> > +out:
> > + if (r == damon_last_region(t)) {
>
> [Severity: High]
> If damon_split_region_at() fails to allocate memory, it returns silently and
> the region remains unmodified. If r happens to be the last region in the list,
> could damon_next_region(r) evaluate past the list boundary and return an
> invalid pointer?
>
> Since this invalid pointer is assigned to *rp and the function continues to
> the out label, could it fail this (r == damon_last_region(t)) check, bypass
> the intended quota reset, and return false?
>
> If so, could the caller damon_do_apply_schemes() then receive this invalid
> pointer and pass it to damos_valid_target():
>
> mm/damon/core.c:damon_do_apply_schemes() {
> ...
> if (damos_skip_charged_region(t, &r, s))
> continue;
>
> if (!damos_valid_target(c, t, r, s))
> continue;
> ...
> }
>
> causing it to dereference garbage data (such as r->ar.start and r->ar.end) and
> potentially lead to an out-of-bounds memory access?
I will separately work on this. Refer to my other reply to same issue report
for details.
[1] https://lore.kernel.org/20260930102333.58847-1-sj@kernel.org
>
> > quota->charge_target_from = NULL;
> > quota->charge_addr_from = 0;
> > }
> > - return false;
> > + return skip;
> > }
> >
> > static void damos_update_stat(struct damos *s,
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260930101459.56041-1-sj@kernel.org?part=1
Thanks,
SJ
next prev parent reply other threads:[~2026-09-30 10:34 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <2026092948-agency-overhand-3fd1@gregkh>
2026-09-30 9:28 ` [PATCH 6.12.y] mm/damon/core: fix unconditionally skip last region SJ Park
2026-09-30 9:53 ` sashiko-bot
2026-09-30 10:01 ` SJ Park
2026-09-30 10:03 ` SJ Park
2026-09-30 10:14 ` [PATCH 6.12.y v2] " SJ Park
2026-09-30 10:26 ` sashiko-bot
2026-09-30 10:34 ` SJ Park [this message]
2026-10-02 14:19 ` Sasha Levin
2026-10-09 12:36 ` [PATCH 6.12.y v3 0/2] mm/damon/core: fix last region handling of damos_skip_charged_regions() SJ Park
2026-10-09 12:36 ` [PATCH 6.12.y v3 1/2] mm/damon/core: do non-safe region walk on kdamond_apply_schemes() SJ Park
2026-10-09 12:55 ` sashiko-bot
2026-10-09 13:42 ` SJ Park
2026-10-09 12:36 ` [PATCH 6.12.y v3 2/2] mm/damon/core: fix unconditionally skip last region SJ Park
2026-10-09 13:06 ` sashiko-bot
2026-10-09 13:40 ` SJ Park
2026-10-11 16:48 ` [PATCH 6.12.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=20260930103408.59035-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.