From: sashiko-bot@kernel.org
To: "SJ Park" <sj@kernel.org>
Cc: damon@lists.linux.dev
Subject: Re: [PATCH] mm/damon/core: validate ranges in damon_set_regions()
Date: Tue, 30 Jun 2026 04:08:28 +0000 [thread overview]
Message-ID: <20260630040828.9D1F11F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260630035221.146458-1-sj@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The introduced validation logic in `damon_set_regions()` is flawed and fails to prevent the `WARN_ONCE` and divide-by-zero crashes it intends to fix. Distinct valid regions within the same alignment block bypass the check, leading to duplicated overlapping regions, inverted hole regions, and a kernel panic.
--
commit 79a8d61a7b1112d3a6da1cff84b7f4a28c66e465
Author: SJ Park <sj@kernel.org>
mm/damon/core: validate ranges in damon_set_regions()
This commit attempts to fix a zero-length region issue that could lead to
a WARN_ONCE and a divide-by-zero crash in DAMON. It adds a validation
loop in damon_set_regions() to reject empty or invalid target regions
before they are processed.
Fixes: 43b0536cb471 ("mm/damon: introduce DAMON-based Reclamation (DAMON_RECLAIM)")
Cc: <stable@vger.kernel.org> # 5.16.x
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index 027250e43c66f..3dd2750c2ef20 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -356,6 +356,12 @@ int damon_set_regions(struct damon_target *t, struct damon_addr_range *ranges,
> unsigned int i;
> int err;
>
> + for (i = 0; i < nr_ranges; i++) {
> + if (ALIGN_DOWN(ranges[i].start, min_region_sz) >=
> + ALIGN(ranges[i].end, min_region_sz))
> + return -EINVAL;
> + }
> +
[Severity: High]
This is a pre-existing issue, but does this validation fully prevent the
divide-by-zero crash?
If a user provides two unaligned regions that fall within the same
min_region_sz block (for example, [10, 20] and [20, 30]), this check will
evaluate ALIGN_DOWN(10) >= ALIGN(20), which becomes 0 >= 4096. This allows
them to bypass rejection.
Because they pass, damon_set_regions() inflates both regions to [0, 4096],
creating identical overlapping regions in the list.
If a subsequent update covers these regions (like [0, 8192]), the
intersecting boundaries are adjusted but first->ar.end is left at 4096 and
last->ar.start at 0. This leads to damon_fill_regions_holes() creating an
inverted hole region:
mm/damon/core.c:damon_fill_regions_holes() {
...
if (r->ar.end != next->ar.start) {
newr = damon_new_region(r->ar.end, next->ar.start);
...
}
Calling damon_new_region(4096, 0) triggers the WARN_ONCE(start >= end) and
results in a region with a negative size (ULONG_MAX - 4095).
When damon_merge_two_regions() eventually tries to merge [0, 4096] with
[4096, 0], the combined size underflows to exactly 0, causing a panic here:
mm/damon/core.c:damon_merge_two_regions() {
...
l->nr_accesses = (l->nr_accesses * sz_l + r->nr_accesses * sz_r) /
(sz_l + sz_r);
...
}
Should the alignment check be stricter, or does damon_set_regions() need
additional logic to merge or reject identically aligned overlapping blocks?
> /* Remove regions which are not in the new ranges */
> damon_for_each_region_safe(r, next, t) {
> for (i = 0; i < nr_ranges; i++) {
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260630035221.146458-1-sj@kernel.org?part=1
next prev parent reply other threads:[~2026-06-30 4:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-30 3:52 [PATCH] mm/damon/core: validate ranges in damon_set_regions() SJ Park
2026-06-30 4:08 ` sashiko-bot [this message]
2026-06-30 4:18 ` SJ Park
2026-06-30 4:26 ` 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=20260630040828.9D1F11F000E9@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