All of lore.kernel.org
 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.1.y] mm/damon/tests/core-kunit: catch test failure in test_merge_regions_of()
Date: Wed, 09 Sep 2026 03:52:36 +0000	[thread overview]
Message-ID: <20260909035237.5A1AF1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260909034257.139428-1-sj@kernel.org>

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

Pre-existing issues:
- [High] Missing failure check in `damon_test_split_at()` assumes `damon_split_region_at()` always succeeds, leading to a heap out-of-bounds read if it fails.
- [High] Missing failure check in `damon_test_set_regions()` can lead to a stack out-of-bounds array read if `damon_set_regions()` creates more than 3 regions.
--

commit 734d67a5ef8e651363b657168887a0a497532892
Author: SJ Park <sj@kernel.org>

mm/damon/tests/core-kunit: catch test failure in test_merge_regions_of()

KUNIT_EXPECT_EQ() does not abort the execution of test code when the
expectation is not met. This commit fixes a potential NULL pointer
dereference in damon_test_merge_regions_of() by explicitly checking the
number of regions and skipping the per-region test if it doesn't match
the expected value. The user impact on realistic setups should be negligible
as it is a unit test.

Link: https://lore.kernel.org/20260715031002.108504-3-sj@kernel.org
Link: https://lore.kernel.org/20260710144937.26981-1-sj@kernel.org [1]

> diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h
> index d8fef225930a5..094714172e581 100644
> --- a/mm/damon/core-test.h
> +++ b/mm/damon/core-test.h
> @@ -253,11 +253,14 @@ static void damon_test_merge_regions_of(struct kunit *test)
>  	damon_merge_regions_of(t, 9, 9999);
>  	/* 0-112, 114-130, 130-156, 156-170 */
>  	KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 5u);
> +	if (damon_nr_regions(t) != 5)
> +		goto out;
>  	for (i = 0; i < 5; i++) {
>  		r = __nth_region_of(t, i);
>  		KUNIT_EXPECT_EQ(test, r->ar.start, saddrs[i]);
>  		KUNIT_EXPECT_EQ(test, r->ar.end, eaddrs[i]);
>  	}
> +out:
>  	damon_free_target(t);
>  }

[Severity: High]
This isn't a bug introduced by this patch, but since the patch specifically
aims to fix missing test-failure aborts, there is a similar missing failure
check in damon_test_split_at() that can lead to a heap out-of-bounds read:

mm/damon/core-test.h:damon_test_split_at() {
    ...
    damon_split_region_at(t, r, 25);
    KUNIT_EXPECT_EQ(test, r->ar.start, 0ul);
    KUNIT_EXPECT_EQ(test, r->ar.end, 25ul);

    r = damon_next_region(r);
    KUNIT_EXPECT_EQ(test, r->ar.start, 25ul);
    ...
}

If memory allocation fails internally in damon_split_region_at(), the region
is not split. KUNIT_EXPECT_EQ() records a failure but does not abort
execution.

Will the test unconditionally execute r = damon_next_region(r) in this
scenario?

Because the region was not split and remains the only element,
damon_next_region() evaluates to an invalid list head pointer. Could
dereferencing this to read r->ar.start cause a heap out-of-bounds read?

[Severity: High]
This is a pre-existing issue, but it shares the exact anti-pattern that the
patch fixes nearby. Another identical omission exists in
damon_test_set_regions():

mm/damon/core-test.h:damon_test_set_regions() {
    ...
    damon_set_regions(t, &range, 1);

    KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 3);
    damon_for_each_region(r, t) {
        KUNIT_EXPECT_EQ(test, r->ar.start, expects[expect_idx++]);
        KUNIT_EXPECT_EQ(test, r->ar.end, expects[expect_idx++]);
    }
    ...
}

If a logic bug in damon_set_regions() outputs 4 or more regions, the test
continues without aborting.

Since the test unconditionally loops over all regions via
damon_for_each_region(r, t) and accesses the 6-element static array expects,
can this exceed the array bounds?

Would using expects[expect_idx++] twice per loop lead to a stack out-of-bounds
read if more than 3 regions exist?

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

  reply	other threads:[~2026-09-09  3:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <2026090809-vice-ribbon-cf5a@gregkh>
2026-09-09  3:42 ` [PATCH 6.1.y] mm/damon/tests/core-kunit: catch test failure in test_merge_regions_of() SJ Park
2026-09-09  3:52   ` sashiko-bot [this message]
2026-09-09 20:26   ` Sasha Levin

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=20260909035237.5A1AF1F00A3A@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.