All of lore.kernel.org
 help / color / mirror / Atom feed
From: SJ Park <sj@kernel.org>
To: sashiko-bot@kernel.org
Cc: SJ Park <sj@kernel.org>, damon@lists.linux.dev
Subject: Re: [RFC PATCH v1.1 3/7] mm/damon/vaddr-kunit: check region count in three_regions test
Date: Fri, 17 Jul 2026 07:55:49 -0700	[thread overview]
Message-ID: <20260717145551.92109-1-sj@kernel.org> (raw)
In-Reply-To: <20260717145050.1D6331F000E9@smtp.kernel.org>

On Fri, 17 Jul 2026 14:50:49 +0000 sashiko-bot@kernel.org wrote:

> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> 
> Pre-existing issues:
> - [High] Out-of-bounds array read in KUnit test helpers due to missing array bounds check and ignored return values
> --
> 
> --- Patch [3]: [RFC PATCH v1.1 3/7] mm/damon/vaddr-kunit: check region count in three_regions test ---
> commit b2d38d564a3004fa6df02a9f1d54af3423302437
> Author: SJ Park <sj@kernel.org>
> 
> mm/damon/vaddr-kunit: check region count in three_regions test
> 
> This commit adds a check in damon_do_test_apply_three_regions() to ensure
> damon_set_regions() succeeded in setting the expected number of regions.
> This prevents a potential NULL pointer dereference during test iteration.
> 
> Link: https://lore.kernel.org/20260713144757.39740-1-sj@kernel.org
> 
> > diff --git a/mm/damon/tests/vaddr-kunit.h b/mm/damon/tests/vaddr-kunit.h
> > index 61f844336ffb5..6a95441d193ae 100644
> > --- a/mm/damon/tests/vaddr-kunit.h
> > +++ b/mm/damon/tests/vaddr-kunit.h
> 
> [ ... ]
> 
> [Severity: High]
> This is a pre-existing issue, but while reviewing this test fix, I noticed
> similar missing bounds checks and unhandled return values in
> mm/damon/tests/core-kunit.h that can cause out-of-bounds array reads.
> 
> In 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++;
> 	}
> 
> If memory allocation fails inside damon_commit_target_regions(), it returns
> an error without modifying dst_target. Because the return value is ignored
> here, could this iterate over the original regions of dst_target and read
> past the end of the expect_start_end stack array?
> 
> A similar pattern appears in damos_test_commit_quota_goals_for():
> 
> 	damos_commit_quota_goals(&dst, &src);
> 
> 	i = 0;
> 	damos_for_each_quota_goal(goal, (&dst)) {
> 		KUNIT_EXPECT_EQ(test, goal->metric, src_goals[i].metric);
> 		KUNIT_EXPECT_EQ(test, goal->target_value,
> 				src_goals[i++].target_value);
> 	}
> 
> Does ignoring the return value of damos_commit_quota_goals() risk an
> out-of-bounds read on src_goals[] if the destination goals are not updated
> and retain more items than expected?
> 
> Finally, in damos_test_commit_dests_for():
> 
> 	KUNIT_EXPECT_EQ(test, dst.nr_dests, src_nr_dests);
> 	for (i = 0; i < dst.nr_dests; i++) {
> 		KUNIT_EXPECT_EQ(test, dst.node_id_arr[i], src_node_id_arr[i]);
> 		KUNIT_EXPECT_EQ(test, dst.weight_arr[i], src_weight_arr[i]);
> 	}
> 
> Since KUNIT_EXPECT_EQ does not abort test execution on failure, could an
> out-of-bounds read occur on src_node_id_arr[] and src_weight_arr[] if
> dst.nr_dests ends up larger than src_nr_dests?

These issues are fixed by other patches in this series.

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


Thanks,
SJ

  reply	other threads:[~2026-07-17 14:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-17 14:34 [RFC PATCH v1.1 0/7] mm/damon: fix uninitialized DAMOS field and kunit exec expectation bugs SJ Park
2026-07-17 14:34 ` [RFC PATCH v1.1 1/7] mm/damon/core: initialize damos->last_applied SJ Park
2026-07-17 14:34 ` [RFC PATCH v1.1 2/7] mm/damon/core-kunit: check region count before testing in split_at() SJ Park
2026-07-17 14:51   ` sashiko-bot
2026-07-17 14:54     ` SJ Park
2026-07-17 14:34 ` [RFC PATCH v1.1 3/7] mm/damon/vaddr-kunit: check region count in three_regions test SJ Park
2026-07-17 14:50   ` sashiko-bot
2026-07-17 14:55     ` SJ Park [this message]
2026-07-17 14:34 ` [RFC PATCH v1.1 4/7] mm/damon/core-kunit: handle region split failure in filter_out() SJ Park
2026-07-17 14:49   ` sashiko-bot
2026-07-17 14:56     ` SJ Park
2026-07-17 14:34 ` [RFC PATCH v1.1 5/7] mm/damon/core-kunit: skip wrong dest walk in commit_dests_for() SJ Park
2026-07-17 14:34 ` [RFC PATCH v1.1 6/7] mm/damon/core-kunit: skip wrong quota goal walk in commit_quota_goals() SJ Park
2026-07-17 14:34 ` [RFC PATCH v1.1 7/7] mm/damon/core-kunit: skip wrong region walk in commit_target_regions() 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=20260717145551.92109-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.