From: sashiko-bot@kernel.org
To: "SJ Park" <sj@kernel.org>
Cc: damon@lists.linux.dev
Subject: Re: [RFC PATCH v1.1 8/8] mm/damon/sysfs: remove region size validation
Date: Thu, 02 Jul 2026 21:15:39 +0000 [thread overview]
Message-ID: <20260702211540.07DA01F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260702210551.95167-9-sj@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Removing the `start > end` validation allows negative-sized regions to bypass subsequent validation, resulting in overlapping regions and eventually negative-sized regions in the DAMON core, leading to unbounded memory allocation (OOM).
--
commit d23d0a5af36c320aac75064c21548cc9de76c4f1
Author: SJ Park <sj@kernel.org>
mm/damon/sysfs: remove region size validation
DAMON_SYSFS validates user inputs for monitoring target regions to
disallow negative size regions. DAMON core assumes only positive size
regions, though. The validation is incomplete. Fortunately
damon_set_regions(), which is eventually used by DAMON_SYSFS, does the
complete validation. Remove the incomplete and unnecessary validation.
> diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
> index e666dddf1feba..b65651498e0d1 100644
> --- a/mm/damon/sysfs.c
> +++ b/mm/damon/sysfs.c
> @@ -1987,9 +1987,6 @@ static int damon_sysfs_set_regions(struct damon_target *t,
> struct damon_sysfs_region *sys_region =
> sysfs_regions->regions_arr[i];
>
> - if (sys_region->ar.start > sys_region->ar.end)
> - goto out;
> -
[Severity: High]
Does removing this validation allow negative-sized regions to bypass the
subsequent overlap checks in damon_sysfs_set_regions()?
If we have an inverted region (e.g., start=2000, end=1000) followed by another
region (e.g., start=1500, end=3000), the overlap check in
damon_sysfs_set_regions() evaluates:
if (ranges[i - 1].end > ranges[i].start)
Which results in ranges[0].end (1000) > ranges[1].start (1500).
This is false, meaning the inverted region bypasses the overlap check.
Will this inverted region also bypass the alignment-based bounds check in
mm/damon/core.c:damon_set_regions()?
mm/damon/core.c:damon_set_regions() {
...
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;
}
If the regions fall within the same alignment block (e.g., start=2000 and
end=1000 with min_region_sz=4096 align to 0 and 4096), the check evaluates
0 >= 4096, which is false, passing the invalid input to the core.
When the negative-sized region reaches mm/damon/core.c:damon_apply_min_nr_regions(),
can this cause an out-of-memory loop?
mm/damon/core.c:damon_apply_min_nr_regions() {
...
while (damon_sz_region(r) > max_region_sz) {
damon_split_region_at(t, r, max_region_sz);
r = damon_next_region(r);
}
The inverted region size would underflow to a very large number, which appears
to cause this loop to continuously split the region, allocating region structs
until the system runs out of memory.
> ranges[i].start = sys_region->ar.start;
> ranges[i].end = sys_region->ar.end;
> if (i == 0)
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260702210551.95167-1-sj@kernel.org?part=8
next prev parent reply other threads:[~2026-07-02 21:15 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-02 21:05 [RFC PATCH v1.1 0/8] mm/damon: validate all parameters in the core SJ Park
2026-07-02 21:05 ` [RFC PATCH v1.1 1/8] mm/damon/core: safely validate src on damon_commit_ctx() SJ Park
2026-07-02 21:21 ` sashiko-bot
2026-07-02 21:35 ` SJ Park
2026-07-02 21:05 ` [RFC PATCH v1.1 2/8] mm/damon/core: do parameter testing commit on damon_start() SJ Park
2026-07-02 21:05 ` [RFC PATCH v1.1 3/8] mm/damon/sysfs: remove duplicated commit input validity check SJ Park
2026-07-02 21:05 ` [RFC PATCH v1.1 4/8] mm/damon/reclaim: remove duplicated min_region_sz power of 2 check SJ Park
2026-07-02 21:05 ` [RFC PATCH v1.1 5/8] mm/damon/lru_sort: remove duplicated min_region_sz power_of_2() check SJ Park
2026-07-02 21:20 ` sashiko-bot
2026-07-02 21:44 ` SJ Park
2026-07-02 21:05 ` [RFC PATCH v1.1 6/8] mm/damon: document region size validation in damon_set_regions() SJ Park
2026-07-02 21:19 ` sashiko-bot
2026-07-02 21:48 ` SJ Park
2026-07-02 21:05 ` [RFC PATCH v1.1 7/8] mm/damon/core: remove start, end check in damon_set_region_system_rams() SJ Park
2026-07-02 21:16 ` sashiko-bot
2026-07-02 21:50 ` SJ Park
2026-07-02 21:05 ` [RFC PATCH v1.1 8/8] mm/damon/sysfs: remove region size validation SJ Park
2026-07-02 21:15 ` sashiko-bot [this message]
2026-07-02 21:53 ` 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=20260702211540.07DA01F000E9@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 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.