From: sashiko-bot@kernel.org
To: "SJ Park" <sj@kernel.org>
Cc: damon@lists.linux.dev
Subject: Re: [PATCH 2/7] mm/damon/core-kunit: check region count before testing in split_at()
Date: Sat, 18 Jul 2026 00:30:26 +0000 [thread overview]
Message-ID: <20260718003027.0315D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260718001442.87129-3-sj@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Silent allocation failure inside `damon_split_region_at()` causes an improper pointer traversal into the list head in `damon_apply_min_nr_regions()`, resulting in a potential infinite loop and out-of-bounds memory corruption.
- [Medium] The patch fixes an invalid pointer dereference upon split allocation failure in `damon_test_split_at()`, but misses an identical vulnerability in `damos_test_filter_out()`.
--
--- Patch [2]: [PATCH 2/7] mm/damon/core-kunit: check region count before testing in split_at() ---
commit 97ba538eacadf2d58d517d9d0f86ecaac4b3851f
Author: SJ Park <sj@kernel.org>
Subject: mm/damon/core-kunit: check region count before testing in split_at()
This commit fixes an issue in the KUnit tests where damon_test_split_at()
could dereference invalid pointers if a region split fails to allocate
memory. The fix tests if the number of regions was changed as expected
and exits early upon failure.
Link: https://lore.kernel.org/20260714142352.100478-1-sj@kernel.org
> diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
> index eba643762132f..322a295ac2cec 100644
> --- a/mm/damon/tests/core-kunit.h
> +++ b/mm/damon/tests/core-kunit.h
> @@ -155,6 +155,10 @@ static void damon_test_split_at(struct kunit *test)
> r->age = 10;
> damon_add_region(r, t);
> damon_split_region_at(t, r, 25);
> + KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 2);
> + if (damon_nr_regions(t) != 2)
> + goto out;
> +
> KUNIT_EXPECT_EQ(test, r->ar.start, 0ul);
> KUNIT_EXPECT_EQ(test, r->ar.end, 25ul);
[Severity: Medium]
This isn't a bug introduced by this patch, but this exact same vulnerability
seems to exist later in this file in damos_test_filter_out().
If damos_filter_match() internally fails to allocate memory during a region
split, the test continues and damon_next_region(r) returns the list head.
mm/damon/tests/core-kunit.h:damos_test_filter_out() {
...
/* region started before the range */
r->ar.start = 1;
r->ar.end = 4;
KUNIT_EXPECT_FALSE(test, damos_filter_match(NULL, t, r, f, 1));
/* filter should have split the region */
KUNIT_EXPECT_EQ(test, r->ar.start, 1);
KUNIT_EXPECT_EQ(test, r->ar.end, 2);
KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 2);
r2 = damon_next_region(r);
KUNIT_EXPECT_EQ(test, r2->ar.start, 2);
KUNIT_EXPECT_EQ(test, r2->ar.end, 4);
damon_destroy_region(r2, t);
...
}
Should the test also be checking the region count and returning early here,
before we pass an invalid pointer to damon_destroy_region() and corrupt the
slab?
[Severity: High]
This is a pre-existing issue, but I'm also concerned about silent allocation
failures from damon_split_region_at() in core kernel paths.
Looking at damon_apply_min_nr_regions():
mm/damon/core.c:damon_apply_min_nr_regions() {
...
damon_for_each_target(t, ctx) {
damon_for_each_region_safe(r, next, t) {
while (damon_sz_region(r) > max_region_sz) {
damon_split_region_at(t, r, max_region_sz);
r = damon_next_region(r);
}
}
}
...
}
If damon_split_region_at() silently fails to allocate memory, it returns
without splitting the region. The while loop then incorrectly advances r
to the next region.
If this allocation failure occurs on the last region in the list,
damon_next_region(r) will return the list head.
The loop condition damon_sz_region(r) > max_region_sz will evaluate memory
located before the damon_target struct.
If those garbage values evaluate to true, could this result in an out-of-bounds
access loop or corrupt memory? Should damon_split_region_at() return an
error code that callers can check?
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260718001442.87129-1-sj@kernel.org?part=2
next prev parent reply other threads:[~2026-07-18 0:30 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-18 0:14 [PATCH 0/7] mm/damon: fix uninitialized DAMOS field and kunit exec expectation bugs SJ Park
2026-07-18 0:14 ` [PATCH 1/7] mm/damon/core: initialize damos->last_applied SJ Park
2026-07-18 0:32 ` sashiko-bot
2026-07-18 0:53 ` SJ Park
2026-07-18 0:14 ` [PATCH 2/7] mm/damon/core-kunit: check region count before testing in split_at() SJ Park
2026-07-18 0:30 ` sashiko-bot [this message]
2026-07-18 0:55 ` SJ Park
2026-07-18 0:14 ` [PATCH 3/7] mm/damon/vaddr-kunit: check region count in three_regions test SJ Park
2026-07-18 0:14 ` [PATCH 4/7] mm/damon/core-kunit: handle region split failure in filter_out() SJ Park
2026-07-18 0:29 ` sashiko-bot
2026-07-18 1:00 ` SJ Park
2026-07-18 0:14 ` [PATCH 5/7] mm/damon/core-kunit: skip wrong dest walk in commit_dests_for() SJ Park
2026-07-18 0:25 ` sashiko-bot
2026-07-18 1:01 ` SJ Park
2026-07-18 0:14 ` [PATCH 6/7] mm/damon/core-kunit: skip wrong quota goal walk in commit_quota_goals() SJ Park
2026-07-18 0:22 ` sashiko-bot
2026-07-18 1:02 ` SJ Park
2026-07-18 0:14 ` [PATCH 7/7] mm/damon/core-kunit: skip wrong region walk in commit_target_regions() SJ Park
2026-07-18 1:13 ` [PATCH 0/7] mm/damon: fix uninitialized DAMOS field and kunit exec expectation bugs SJ Park
-- strict thread matches above, loose matches on Subject: below --
2026-07-17 0:30 SJ Park
2026-07-17 0:30 ` [PATCH 2/7] mm/damon/core-kunit: check region count before testing in split_at() SJ Park
2026-07-17 0:44 ` sashiko-bot
2026-07-17 1:18 ` 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=20260718003027.0315D1F000E9@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