DAMON development mailing list
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "SJ Park" <sj@kernel.org>
Cc: damon@lists.linux.dev
Subject: Re: [PATCH 6/7] mm/damon/core-kunit: skip wrong quota goal walk in commit_quota_goals()
Date: Fri, 17 Jul 2026 00:44:33 +0000	[thread overview]
Message-ID: <20260717004433.98CBC1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260717003022.119437-7-sj@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [Medium] Missing error check in `damon_test_commit_target_regions_for()` leads to an out-of-bounds read if `damon_commit_target_regions()` fails.
--

--- Patch [6]: [PATCH 6/7] mm/damon/core-kunit: skip wrong quota goal walk in commit_quota_goals() ---
commit 9bf8891739c4d265498b06b272b3083da8b65ed2
Author: SJ Park <sj@kernel.org>

mm/damon/core-kunit: skip wrong quota goal walk in commit_quota_goals()

This commit fixes an out-of-bounds access in
damos_test_commit_quota_goals_for() by verifying the number of quota goals
matches the expected amount before traversing them. This prevents test setups
from crashing if damos_commit_quota_goals() creates an unexpected number of
goals.

Link: https://lore.kernel.org/20260713144757.39740-1-sj@kernel.org

> --- a/mm/damon/tests/core-kunit.h
> +++ b/mm/damon/tests/core-kunit.h
[ ... ]
> @@ -861,6 +862,14 @@ static void damos_test_commit_quota_goals_for(struct kunit *test,
>  
>  	damos_commit_quota_goals(&dst, &src);
>  
> +	damos_for_each_quota_goal(goal, &dst)
> +		nr_dst++;
> +	damos_for_each_quota_goal(goal, &src)
> +		nr_src++;
> +	KUNIT_EXPECT_EQ(test, nr_dst, nr_src);
> +	if (nr_dst != nr_src)
> +		goto out;
> +
>  	i = 0;
>  	damos_for_each_quota_goal(goal, (&dst)) {
>  		KUNIT_EXPECT_EQ(test, goal->metric, src_goals[i].metric);

[Severity: Medium]
This is a pre-existing issue, but since this patch fixes this exact pattern 
for quota goals, does damon_test_commit_target_regions_for() need a similar 
fix for target regions?

If damon_commit_target_regions() fails (for example, due to a memory 
allocation failure), it returns an error code and leaves dst_target's 
regions unmodified. The test code currently ignores the return value and 
blindly iterates over dst_target:

mm/damon/tests/core-kunit.h:damon_test_commit_target_regions_for() {
...
	damon_commit_target_regions(dst_target, src_target, 1);
	i = 0;
	damon_for_each_region(r, dst_target) {
		KUNIT_EXPECT_EQ(test, r->ar.start, expect_start_end[i][0]);
		KUNIT_EXPECT_EQ(test, r->ar.end, expect_start_end[i][1]);
		i++;
	}
...
}

In a case where the original number of destination regions is larger than 
the number of expected regions, could this loop execute more times than the 
size of expect_start_end[] and cause an out-of-bounds read on the stack array?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260717003022.119437-1-sj@kernel.org?part=6

  reply	other threads:[~2026-07-17  0:44 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-17  0:30 [PATCH 0/7] mm/damon: fix uninitialized DAMOS field and kunit exec expectation bugs SJ Park
2026-07-17  0:30 ` [PATCH 1/7] mm/damon/core: initialize damos->last_applied SJ Park
2026-07-17  0:52   ` sashiko-bot
2026-07-17  1:12     ` 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
2026-07-17  0:30 ` [PATCH 3/7] mm/damon/vaddr-kunit: check region count in three_regions test SJ Park
2026-07-17  0:30 ` [PATCH 4/7] mm/damon/core-kunit: handle region split failure in filter_out() SJ Park
2026-07-17  0:46   ` sashiko-bot
2026-07-17  1:22     ` SJ Park
2026-07-17  0:30 ` [PATCH 5/7] mm/damon/core-kunit: skip wrong dest walk in commit_dests_for() SJ Park
2026-07-17  0:30 ` [PATCH 6/7] mm/damon/core-kunit: skip wrong quota goal walk in commit_quota_goals() SJ Park
2026-07-17  0:44   ` sashiko-bot [this message]
2026-07-17  1:23     ` SJ Park
2026-07-17  0:30 ` [PATCH 7/7] mm/damon/core-kunit: skip wrong region walk in commit_target_regions() SJ Park
2026-07-17  1:05 ` [PATCH 0/7] mm/damon: fix uninitialized DAMOS field and kunit exec expectation bugs 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=20260717004433.98CBC1F000E9@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